Skip to content

Commit 4acae68

Browse files
committed
Changes to deploy
1 parent e8e3f66 commit 4acae68

File tree

8 files changed

+96
-2
lines changed

8 files changed

+96
-2
lines changed

README.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,94 @@
11
# Doodle-to-Image-Generator
2-
This is an automatic realistic image generation from doodles using GauGan which has been deployed on streamlit.
2+
This is an automatic realistic image generator from doodles using GauGan which has been deployed on streamlit. You can check it out [here](https://shreyz-max-doodle-to-image-generator-streamlitapp-miq4ua.streamlitapp.com/).
3+
This uses GauGAN to generate the images given the semantic maps or doodles here.
4+
The model is based on Conditional GAN where given a particular image and a condition the realistic image gets generated.
5+
6+
The model has been taken from nvidia labs SPADE released in 2019.
7+
## Table of contents
8+
* <a href="#Idea">Idea</a>
9+
* <a href="#SampleResults">Sample Results</a>
10+
* <a href="#Dataset">Dataset</a>
11+
* <a href="#Setup">Setup</a>
12+
* <a href="#Components">Different Components</a>
13+
* <a href="#FineTuning">Fine Tuning the model</a>
14+
* <a href="#ModelLoss">Model and Loss</a>
15+
* <a href="#OtherExamples">Other Examples</a>
16+
* <a href="#References">References</a>
17+
18+
<h2 id="Idea">Idea</h2>
19+
A lot of interest was captured when GauGAN2 was released by Nvidia recently.
20+
I wanted to check it out but turns out GauGAN2 has not yet been open-sourced to the public.
21+
So, I started looking into GauGAN in general and found this implementation.
22+
I wanted to fully understand the functioning of the model and understand how even though it was adopted from pix2pix model,
23+
it still had way better results. Another factor was I wanted to make the front end easily accessible by the data science community
24+
since not everyone is well versed with html and css. Hence, I deployed it on streamlit.
25+
26+
<h2 id="SampleResults">Sample Results</h2>
27+
Here is the working of GauGAN in real life deployed on a website.
28+
29+
<p align = "center"><img align = "center" src = "images/gaugan.gif" /></p>
30+
31+
<h2 id="Dataset">Dataset</h2>
32+
Originally in the SPADE paper, the model was trained on 3 different datasets namely COCO, cityscapes and ADE20K. Although, Flcikr dataset was also used however I am not so sure about the segmentation
33+
of that dataset. The model has been trained on 8 V100 GPUs that equals 128 GB of memory. So, to avoid any of such memory problems
34+
I used a pretrained dataset. However, I tried training on custom dataset as well. You can find the details to that here.
35+
36+
<h2 id="Setup">Setup</h2>
37+
38+
You can easily setup this application. Here are the steps to replicate my outcome in your system.
39+
40+
Clone the repository. <code>git clone https://github.com/Shreyz-max/Doodle-to-Image-Generator.git</code>
41+
42+
Create a conda environment. <code>conda create -n doodle_image python=3.10</code>
43+
44+
Activate environment. <code>conda activate doodle_image</code>
45+
46+
Install requirements file. <code>pip install -r requirements.txt</code>
47+
48+
Run app.py <code>streamlit run streamlit/app.py</code>
49+
50+
<h2 id="Components">Different Components</h2>
51+
<code>app.py</code> has all of the streamlit code to run the frontend.
52+
53+
<code>label_colors.py</code> contains a list of dictionaries for each label as well as it's corresponding color that I have assigned
54+
and its corresponding id in the coco dataset.
55+
56+
<h2 id="FineTuning">Fine Tuning the model</h2>
57+
Here are a few things that I did.
58+
So basically, GauGAN is trained to take a black and white semantic map and convert it into a realisitc image.
59+
So, once we have a painted image, it is converted into black and white using its labels. I have selected a few labels from COCO
60+
dataset. You have 182 labels. So, you can choose any of the labels. Just select a few labels from your choice from COCO dataset.
61+
Change the color based on what you like in `label_colors.py`. Make sure that the ids of those labels match those of the COCO dataset.
62+
Also make the changes in the select-box of `app.py`.
63+
In case you want to use a different model with different datasets. Download the model from here. Use `latest_net_G.pth` for this.
64+
65+
<h2 id="ModelLoss">Model and Loss</h2>
66+
To understand the model and the different types of losses, I would suggest reading the paper here.
67+
To train on your dataset, you can follow my repository here. This follows you through how to train in google colab. You can then download the model and load it in this project.
68+
Make a few changes as mentioned above, and you will have a working frontend as well.
69+
70+
<h2 id="OtherExamples">Other Examples</h2>
71+
Some other results to enjoy:
72+
<h3 id="Performance">Performance of both algorithms on testing data</h3>
73+
<table>
74+
<tr>
75+
<th>Doodle Input</th>
76+
<th>Realistic Image</th>
77+
</tr>
78+
<tr>
79+
<td><img src="images/try1.png" width="420px"/></td>
80+
<td><img src="images/try1.jpeg" width="420px"/></td>
81+
</tr>
82+
<tr>
83+
<td><img src="images/try2.png" width="420px"/></td>
84+
<td><img src="images/try2.jpeg" width="420px"/></td>
85+
</tr>
86+
</table>
87+
88+
<h2 id="References">References</h2>
89+
90+
[Spade Paper](https://arxiv.org/pdf/1903.07291.pdf)
91+
92+
[Spade Implementation](https://github.com/NVlabs/SPADE/tree/master)
93+
94+
[Flask implementation](https://github.com/mcheng89/gaugan)

images/gaugan.gif

1.76 MB
Loading

images/try1.jpeg

165 KB
Loading

images/try1.png

10.1 KB
Loading

images/try2.jpeg

209 KB
Loading

images/try2.png

19.2 KB
Loading

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Pillow==9.2.0
2-
streamlit==1.11.1
2+
streamlit>=1.10.0
33
streamlit-drawable-canvas==0.9.1
44
torch==1.12.0
55
torchvision==0.13.0

streamlit/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
st.set_page_config(layout="wide")
11+
1112
# Specify canvas parameters in application
1213
drawing_object = st.sidebar.selectbox(
1314
"Object:", ("sea", "cloud", "bush", "grass", "mountain", "sky", "snow",
@@ -24,6 +25,7 @@
2425

2526
stroke_color = drawing_object_dict[drawing_object]
2627

28+
2729
col1, col2 = st.columns(2)
2830
with col1:
2931
# Create a canvas component with different parameters

0 commit comments

Comments
 (0)