Native TensorFlow API implementation of SinGAN paper (https://arxiv.org/pdf/1905.01164.pdf).
The goal of this implementation is instructional. I hope it is useful for people who do not have deep background in Pytorch or Keras. This implementation defines model graph using native TensorFlow (version lte 2.0), thus this may be easier to understand the method for beginners.
Image | Random Sample 1 | Random Sample 2 | Random Sample 3 |
---|---|---|---|
In the paper, to ensure the original image exists in the solution space of generator, noise map is kept as (z*N, 0, 0, 0, ...) from coarsest scale to finest scale. Here z*N is kept fixed while training. Further random samples are generated from noise map (zN, zN-1, zN-2, ...) etc.
We instead trained the network by generating random samples using the following map (z*N + zN, zN-1, zN-2, ...). This way, the noise at the coarsest scale is centered around z*N. Thus, the random sample at coarsest scale can be made to preserve global pattern in images by tuning the magnitude of zN. The resultant images at finest scale preserve global structure much better.
Figure below show comparisons for modified strategy (top) and original strategy (bottom)
Random Sample 1 | Random Sample 2 | Random Sample 3 | Random Sample 4 |
---|---|---|---|
Installation steps tested for Windows 10 64-bit and Python 3.5
Open Git Bash terminal, navigate to desired location and clone repository using git clone https://github.com/shiveshc/SinGAN_easy_tensorflow.git
.
Or click on Code
button on top right corner and Download ZIP
.
Open command line terminal as administrator and navigate to cloned repository path using cd .\SinGAN_easy_tensorflow
.
Next run following commands -
Windows 10 | MacOS |
---|---|
1. python -m venv env |
1. python -m venv env |
2. env\Scripts\activate.bat |
2. source env/bin/activate |
3. python -m pip install --upgrade "pip < 21.0" |
3. python -m pip install --upgrade "pip < 21.0" |
4. pip install -r requirements.txt |
4. pip install -r requirements.txt |
Installation should take 10-15 minutes.
Common installation errors -
- pip version is not upgraded
solution : upgrade pip usingpython -m pip install --upgrade pip
- pip version is not compatible with python version
solution : install suitable pip version e.g. pip version < 21.0 is compatible with Python 3.5.
To train on balloons.png
in data folder
run - \
env\Scripts\activate.bat
\python train.py /data/balloons.png output_path -scales 6 -iters 75 1