Skip to content

A simple image generation based on next image prediction with LSTM - MNIST

Notifications You must be signed in to change notification settings

fawern/Sequential-Image-Generator-LSTM-MNIST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Next-Img-Prediction-ImgGeneration-LSTM

A deep learning project that generates images based on next image prediction using LSTM networks. This project specifically works with the MNIST dataset to predict the next image in a sequence.

Project Overview

This project implements an LSTM-based neural network model to predict and generate sequential images from the MNIST dataset. The code has been organized into modular components for improved maintainability and reusability.

How It Works

The system works by:

  1. Data Preparation: MNIST images are arranged into sequences of 4 consecutive digits.
  2. Input Processing: Each image is flattened from 28x28 pixels to a 784-dimensional vector.
  3. Sequence Learning: The LSTM network learns patterns from these sequences.
  4. Prediction: Given a sequence of images, the model predicts what the next image should be.
  5. Generation: By feeding predictions back into the model, we can generate new images in a chain.

For example, if the model is shown images of digits [5,6,7,8], it should predict an image of digit 9. By iteratively using its own outputs as inputs, the model can generate sequences of related digits.

Input

  • The input data is a list of images, each image is a 2D array of shape (28, 28).
  • The output data is a image.
  • All images are in a mathematical format.
  • Each image is one larger than the previous one and one smaller than the next.
Inputs Output
0 - 1 - 2 - 3 4
1 - 2 - 3 - 4 5
2 - 3 - 4 - 5 6
3 - 4 - 5 - 6 7
4 - 5 - 6 - 7 8
5 - 6 - 7 - 8 9

Examples: formula_sample1 formula_sample2

Project Structure

The project has been refactored into modular components:

  • data.py: Data loading and preparation
  • preprocessing.py: Data preprocessing and sequence generation
  • model.py: LSTM model implementation
  • main.ipynb: Main training and evaluation workflow

Model Architecture

The NextImagePredictor class extends Keras' Sequential model to create a specialized LSTM network for image sequence prediction

Results with Different Optimizers

The model was trained with different optimizers to compare performance. Below are the results obtained with each optimizer.

SGD (Stochastic Gradient Descent) Optimizer Results

The following images were generated using the SGD optimizer:

sgd_output0 sgd_output1 sgd_output2 sgd_output3 sgd_output4 sgd_output5

RMSprop Optimizer Results

The following images were generated using the RMSprop optimizer:

rmsprop_output0 rmsprop_output1 rmsprop_output2 rmsprop_output3 rmsprop_output4 rmsprop_output5

Adam Optimizer Results

The following images were generated using the Adam optimizer:

adam_output0 adam_output1 adam_output2 adam_output3 adam_output4 adam_output5

About

A simple image generation based on next image prediction with LSTM - MNIST

Resources

Stars

Watchers

Forks

Packages

No packages published