Skip to content

kynk94/TF2-Image-Generation

Repository files navigation

License: CC BY-NC-SA 4.0

Tensorflow 2 Reimplementation (Image Generation)

Tensorflow 2 reimplementation of image generation model.

Results

GAN - mnist

GAN mnist GAN mnist plot


CGAN - mnist

All random latent Same latent per class
CGAN mnist random CGAN mnist same

CGAN mnist plot


DCGAN - LSUN

DCGAN LSUN DCGAN LSUN plot


DCGAN - CIFAR-10

DCGAN CIFAR-10 DCGAN CIFAR-10 plot


DCGAN - mnist

DCGAN mnist DCGAN mnist plot


LSGAN - CIFAR-10

LSGAN CIFAR-10 LSGAN CIFAR-10 plot


WGAN-GP - LSUN

WGAN-GP LSUN WGAN-GP LSUN plot


Neural Style Transfer

5000 Step From Content Neural Style Transfer content - 구르미 그린 달빛
Neural Style Transfer style - Voronoi diagram Neural Style Transfer result - Voronoi diagram
Neural Style Transfer style - Vassily Kandinsky Composition 7 Neural Style Transfer result - Vassily Kandinsky Composition 7
Neural Style Transfer style - 게르니카 Neural Style Transfer result - 게르니카
Neural Style Transfer style - 론강의 별이 빛나는 밤 Neural Style Transfer result - 론강의 별이 빛나는 밤
Neural Style Transfer style - La Promenade Neural Style Transfer result - La Promenade

Neural Style Transfer plot


Fast Style Transfer

Fast Style Transfer contents - wave Fast Style Transfer outputs - wave Fast Style Transfer styles - wave
Fast Style Transfer contents - the scream Fast Style Transfer outputs - the scream Fast Style Transfer styles - the scream
Fast Style Transfer contents - udnie Fast Style Transfer outputs - udnie Fast Style Transfer styles - udnie

Differences from the official implementation

  • In Residual Block, follow the steps below.
    input -> (normalization -> activation -> conv) -> (normalization -> activation -> conv) -> add
  • Use FIR Filter in Transposed Convolution
  • Use Reflection Padding
  • Use Leaky ReLU

AdaIN

AdaIN contents 0.1 AdaIN outputs 0.1 AdaIN styles 0.1
AdaIN contents 0.01 AdaIN outputs 0.01 AdaIN styles 0.01

AdaIN plot


Model List

GAN

Style Transfer & Image to Image Translation

  • Neural Style Transfer: Paper
  • Fast Style Transfer: Paper
  • AdaIN: Paper
  • CycleGAN
  • StarGAN
  • UNIT

TF2 Custom Layer

  • Resample Layers (Downsample, Upsample)
  • Padding Layers
  • Noise Layers
  • Linear Block (support noise, weight scaling)
  • Convolution Layers (support int pad, noise, weight scaling, fir filter)
  • Convolution Blocks (support normalization, activation, etc)
  • Residual Blocks (support shortcut, Resample, Transpose, etc)
  • Subpixel Convolution
  • ICNR Initializer
  • Decomposed Transposed Convolution
  • FIR Filter Layer (Need to set learning rate low or resolution high to use filter, according to experiment.)
  • Haar Transform Layers
  • Denormalization Layers (AdaIN, SPADE, ...)

Utilities

Docker

Build

~$ docker pull tensorflow/tensorflow:nightly-gpu
~$ docker build -f Dockerfile \
  -t tf/image-generation:nightly \
  --build-arg user_name=$USER \
  --build-arg user_uid=$UID \
  .

Docker Compose

interactive container
~$ docker-compose up -d
~$ docker exec -it tf_nightly /bin/bash
~$ cd TF2-Image-Generation
~$ {something to do}

otherwise, run command below after modifying docker-compose.yaml
~$ docker-compose up

Dataset Extractor

GIF Maker

Make gif file from image files.

usage: make_gif.py [-h] -i INPUT [-o OUTPUT] [-f FPS] [-r RESOLUTION]
                   [-fc FRAMES_CONSECUTIVE | -fsr FRAMES_SPACE_RATE | -fi FRAMES_INTERVAL]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input images directory
  -o OUTPUT, --output OUTPUT
                        Output file name
  -f FPS, --fps FPS     Frames per Second
  -r RESOLUTION, --resolution RESOLUTION
                        Output file resolution
  -fc FRAMES_CONSECUTIVE, --frames_consecutive FRAMES_CONSECUTIVE
                        Total consecutive frames of gif counting from scratch
  -fsr FRAMES_SPACE_RATE, --frames_space_rate FRAMES_SPACE_RATE
                        Rate of total frames from start to end (if 0.5, use half of frames)
  -fi FRAMES_INTERVAL, --frames_interval FRAMES_INTERVAL
                        Interval index between adjacent frames (if 10, images=[0, 10, 20, ...])

GIF maker uses following options.
If you run it for the first time, you need to run imageio.plugins.freeimage.download() first.
(or automatically download in the runtime)

  • library: imageio
  • plugin: FreeImage
  • format: GIF-FI
  • quantizer: nq (neuqant) - Dekker A. H., Kohonen neural networks for optimal color quantization

Patch Selector

Interactive patch selector.
Select exact patches with numpy indexing from images separated by (ROW x COL) sections.

usage: select_patch.py [-h] -i INPUT -r ROW -c COL [-o OUTPUT] [-n N_TARGET] [-as AUTO_SQUARE]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input images directory
  -r ROW, --row ROW     Number of rows in input images
  -c COL, --col COL     Number of columns in input images
  -o OUTPUT, --output OUTPUT
                        Output directory name (default=./output/patches)
  -n N_TARGET, --n_target N_TARGET
                        Target number of patches in output
  -as AUTO_SQUARE, --auto_square AUTO_SQUARE
                        Flag. Make Selected Patches to almost square

Tensorflow Log Extractor

Extract scalars(to csv) and images(to png) from tensorflow log file.
The extractor is 20~30 times slower than downloading from the Tensorboard GUI.
Don't use this extractor if saved the images at training time.
If need only csv file of scalars log, just download in Tensorboard GUI.

usage: extract_tf_log.py [-h] [-l LOG_DIR] [-o OUTPUT] [-ei EXTRACT_IMAGE]

optional arguments:
  -h, --help            show this help message and exit
  -l LOG_DIR, --log_dir LOG_DIR
                        Event log files directory, Select exact log in runtime (default=./**/checkpoints)
  -o OUTPUT, --output OUTPUT
                        Output directory (default=./log_output)
  -ei EXTRACT_IMAGE, --extract_image EXTRACT_IMAGE
                        Extract Image Flag (default=True)

Requirements

  • tensorflow 2.x
  • pip install -r requirements.txt

About

Tensorflow2 reimplementation of image generation model (GAN, Style Transfer, Image to Image Translation, etc)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published