SinGAN

August 24, 2021 · View on GitHub

English | 简体中文

1 Introduction

This project is based on the Paddlepaddle framework to reproduce SinGAN, a new unconditional generation model that can be learned from a single natural image. This model contains a fully convolution pyramid structure of GANs, and each GANs is responsible for learning different patch distributions on images of different proportions. This allows for the generation of new samples of arbitrary size and aspect ratio, with significant variability, while maintaining the global structure and fine texture of the training image. Compared with previous single image generation schemes, this method is not limited to texture images and has no conditions (that is, to generate samples from noise).

Paper:

  • [1] Shaham T R, Dekel T, Michaeli T. Singan: Learning a generative model from a single natural image[C]//Proceedings of the IEEE/CVF International Conference on Computer Vision. 2019: 4570-4580.

Reference project:

The link of aistudio:

2 Result

Generated Results

Model Weight Download Address:(Baiduyun code:ipbt)

3 Dataset

Any image can be used as a training set, and this project provides some images to train with. Images

4 Environment

  • Hardware: GPU, CPU

  • Framework:

    • PaddlePaddle >= 2.0.0

5 Quick start

step1: clone

# clone this repo
git clone https://github.com/icey-zhang/paddle_SinGAN.git
cd paddle_SinGAN-main

Installation dependency

sh init.sh

step2: train

  • single machine training
python train.py --input_name colusseum.png 
  • train distributed and use multi machine training:
python3 -m paddle.distributed.launch --log_dir=./debug/ --gpus '0,1,2,3' train.py --input_name colusseum.png

step3: test

  • random_samples
python eval.py --input_name colusseum.png --mode random_samples --gen_start_scale 0

Note: To use the full model, specify that the pyramid structure generation starts at level 0 (gen_start_scale), starts at level 2, specifies that it is 1, and so on.

  • random samples in arbitrary sizes
python eval.py --input_name colusseum.png --mode random_samples_arbitrary_sizes --scale_h 2 --scale_v 1
  • test with pre-training weight

Download the pre-training weights in the main directory, then run the above command, notice where the weights are placed, detailed information can be seen in code structure and [Pre training model](#63-Pre training model)

6 Code structure

6.1 structure

./paddle_SinGAN-main
├─TrainedModels             
├─config                        
├─dataset                     
├─models    
├─Input
├─Output
│  run.sh                  
│  eval.py                    
│  init.sh                     
|  README_cn.md                 
|  README.md                  
│  requirement.txt               
│  train.py                      

6.2 Parameter description

Parameters related to training can be set in train.py, as follows:

Parametersdefaultdescription
input_dirInput/Images, MandatoryThe path to the image
input_nameNone, MandatoryThe name of the image
modetrain, MandatoryMode

Parameters related to test can be set in test.py , as follows:

Parametersdefaultdescription
input_dirInput/Images, MandatoryThe path to the image
input_nameNone, MandatoryThe name of the image
modeNone, MandatoryRandom samples or random samples with arbitrary sizes
gen_start_scaleNone, MandatoryThe beginning of the pyramid
scale_hNone, OptionalAdjust the scale of the image
scale_vNone, OptionalAdjust the scale of the image

6.3 Model Weight

  • Model Weight Download: Baiduyun:Pre training model 提取码:ipbt

  • Model Weight Information

./paddle_SinGAN-main
├─TrainedModels                      #Model storage location
  ├─colusseum                        #Image name
    ├─scale_factor=0.750000,alpha=10 #Reflect the scale of pyramid size change
      ├─0                            #Pyramid structure layer (layer 0))
        ├─netD.pdparams              #The weight of the discriminator
        ├─netG.pdparams              #The weight of the generator
        ├─z_opt.paparams             #-   Random noise for training
        ├─real_scale.png             #Original picture downsampling
        ├─G(z_opt).png               #Image generated with z opt noise
        ├─fake_samples.png           #Image generated from another arbitrary random noise

7 Model information

For other information about the model, please refer to the following table:

informationdescription
AuthorJiaqing Zhang、Kai jiang
Date2021.08
Framework versionPaddle 2.1.2
Application scenariosImage Generation
Support hardwareGPU、CPU
Download linkPre training model code:ipbt
Online operationbotebookScript