Skip to content

Inofficial implementation of the paper "SinGAN: Learning a Generative Model from a Single Natural Image"

Notifications You must be signed in to change notification settings

jonasgrebe/pt-singan-single-image-gan

Repository files navigation

pt-singan-single-image-gan

Inofficial implementation of the paper "SinGAN: Learning a Generative Model from a Single Natural Image" as a project for the Deep Generative Models lecture at TU Darmstadt SS2020.

The web application

Setup

In order to execute the web application on your local computer, you need to do the following.

  1. Install all packages from the requirements.txt.
  2. Install the RabbitMQ message broker from their website.
  3. Run the RabbitMQ Service, then open a terminal and configure RabbitMQ by entering the following four commands:
    • rabbitmqctl.bat add_user singan singan
    • rabbitmqctl.bat add_vhost singan_host
    • rabbitmqctl.bat set_user_tags singan singan_tag
    • rabbitmqctl.bat set_permissions -p singan_host singan ".*" ".*" ".*"
  4. In the project's root directory, go into the folder web, open a terminal here and run python manage.py runserver to run the Django server.
  5. In the same folder (web) open another terminal and execute the Celery worker process by entering celery -A web worker --pool=solo -l info
  6. Finally, in your browser, open http://127.0.0.1:8000/.

How to use without the UI

For each of the SinGAN applications, we created an easy-to-use python script that can be run directly from the console by specifying the necessary parameters. All of these scripts have in common that they require either just the run_name of a pretrained SinGAN model or the --not_pretrained flag together with the training image path, the number of scales N and the number of steps per scale. For instance, the following additional command line arguments would train a SinGAN model on the green fern plant image with 8 scales and 2000 steps per scale:

python application.py [...] --not_pretrained --img 5026-green-fern-plant-during-daytime.jpg --N 8 --steps_per_scale 2000

If the --not_pretrained flag is not given but a trained model with the identifier run_name exists, this is used instead.

Random Sampling

python sample.py --run_name <String> -- height <int> --width <int>

Scale Injection

python scale_injections.py --run_name <String>

Super Resolution

python scale_injections.py --run_name <String> --super_scales <int>

Paint2Image

Note: You have to additionally provide a training image via --img if you want to train a new model. The paint images are expected to be found in the data/paint subdirectory.

python paint2image.py --run_name <String> --paint 5026_1.jpg

Single Image Animation

python animate.py --run_name <String> --frames <int> --fps <int> --alpha 0.1 --beta 0.9 --start_at_scale <int>

Current example results

Random Sampling

training (512x512) 512x512 512x512 512x512 512x1024
train img1 img2 img3 img4
train img1 img2 img3 img4
train img1 img2 img3 img4

Scale Injections

training (512x512) Scale 0/10 Scale 1/10 Scale 2/10 Scale 3/10 Scale 4/10
train img1 img2 img3 img4 img5
Scale 5/10 Scale 6/10 Scale 7/10 Scale 8/10 Scale 9/10 Scale 10/10
train img6 img7 img8 img9 img10
training (512x512) Scale 0/10 Scale 1/10 Scale 2/10 Scale 3/10 Scale 4
train img1 img2 img3 img4 img5
Scale 5/10 Scale 6/10 Scale 7/10 Scale 8/10 Scale 9/10 Scale 10/10
train img6 img7 img8 img9 img10

Super Resolution

training (512x512) SinGAN (1616x1616) bilinear (1616x1616)
train img1 img2
train img1 img2
train img1 img2

Paint2Image

training paint Scale 7/9 Scale 9/9
train img1 img2 img3
training paint Scale 6/9 Scale 9/9
train img1 img2 img3
training paint Scale 6/9 Scale 9/9
train img1 img2 img3

Single Image Animation

training animation
train img1