Giter Site home page Giter Site logo

crypto-code / latent-space-visualization Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 1.94 MB

Visualize the Latent Space of an Autoencoder using matplotlib

License: MIT License

Python 100.00%
2d-space autoencoder bottleneck decoder matplotlib bottleneck-layer data-visualization latent-space dimensionality-reduction dimension-reduction

latent-space-visualization's Introduction

Latent Space Visualization

Visualize the Latent Space of an Autoencoder using matplotlib

What’s the Latent Space ?

An Autoencoder is made of two components: an Encoder & a Decoder. The Encoder brings the input data from a high dimensional representation to a bottleneck layer, where the number of neurons is the smallest. Then, the decoder takes this Encoded Input and converts it back to the original Input shape. The latent space is the space in which the data lies in the bottleneck layer.

The Latent Space contains a compressed representation of the image, which is the only information the decoder is allowed to use to try to reconstruct the input as fully as possible. To perform well, the network has to learn to extract the most relevant features in the bottleneck.

Once the Latent Space is plotted on a 2D space images can be generated by sampling from any point in that space.

Requirements:

Usage:

  • Firstly, collect the required dataset of images to visualize (A datset of pokemon sprites is already provided). Once collected, the images need to be converted to RGB and then resized to 64x64 to fit the Autoencoder using RGBA2RGB.py & resize.py.
python RGBA2RGB.py --help

usage: RGBA2RGB.py [-h] --input INPUT --output OUTPUT

Convert RGBA to RGB

optional arguments:
  -h, --help       show this help message and exit
  --input INPUT    Directory containing images to resize. eg: ./resized
  --output OUTPUT  Directory to save resized images. eg: ./RGB_data
python resize.py --help

usage: resize.py [-h] --input INPUT --output OUTPUT

Resize Input Images

optional arguments:
  -h, --help       show this help message and exit
  --input INPUT    Directory containing images to resize. eg: ./data
  --output OUTPUT  Directory to save resized images. eg: ./resized
  • Once the dataset is prepared, run LS_visualize in training mode to train the autoencoder.
python LS_visualize.py --help
usage: LS_visualize.py [-h] --input INPUT --name NAME [--epoch EPOCH] --mode MODE

Autoencoder Latent Space Visualization

optional arguments:
  -h, --help     show this help message and exit
  --input INPUT  Directory containing images eg: data/
  --name NAME    Model Name
  --epoch EPOCH  No of training iterations
  --mode MODE    Mode: train or plot

Once trained the latent space can be plotted by setting the mode to plot.

Example:

Hovering over any region in the 2D space gives a reconstructed image. Images at points give perfect reconstruction, while in the white space a mix of different images is visible.

G00D LUCK

For doubts email me at: [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.