This repository contains an implementation of the Stable Diffusion model for image generation. It is trained on the Flowers102 dataset. Everything is implemented from scratch using PyTorch.
Here are some samples generated by the model after training for 860 epochs. It can be seen that the model is able to generate realistic looking flowers (and some that look like organic waste).
To get started with this project, follow these steps:
-
Clone this repository:
git clone https://github.com/ProfessorNova/Stable-Diffusion-Flowers.git cd Stable-Diffusion-Flowers
-
Set up Python Environment: Make sure you have Python installed (tested with Python 3.10.11).
-
Install PyTorch: Visit the PyTorch website for proper PyTorch installation based on your system configuration.
-
Install Additional Dependencies: There are two additional dependencies required for this project.
tqdm
is used for progress bars andmatplotlib
is used for plotting the results during inference.pip install tqdm matplotlib
-
Run the Pretrained Model: To generate images using the pretrained model, run the following command:
python sd_inference.py
This will generate 8 images and plot them using matplotlib.
To train the model from scratch, run the following command:
python sd_train.py
This will start the training process. The model will generate samples after every epoch and save them in the images
folder by default.
Here are some images generated during training:
-
Epoch 1:
It is just pure noise at this point.
-
Epoch 10:
The model is starting to generate some larger blobs.
-
Epoch 50:
You can see some flower-like structures starting to form.
-
Epoch 100:
Colors are getting more vibrant and the shapes are more defined.
-
Epoch 300:
Now you can really spot the flowers. But some still look very weird.
-
Epoch 860:
Now almost all images look like flowers. Some are very realistic, some are not.
This project was highly inspired by the keras example Denoising Diffusion Implicit Models by András Béres.