High-Resolution Multi-Scale Neural Texture Synthesis (Mert Toka Presentation)

Xavier Snelgrove paper: (paper)


Texture synthesis:

"Texture synthesis is the process of algorithmically constructing a large digital image from a small digital sample image by taking advantage of its structural content." (source)


Images:

(If you need to zoom in the image, you can do so by downloading it)

Arguments



Long ArgShort ArgUsageDefaultShort Desc.
--source-s-s SOURCE [SOURCE ... ]NoneList of file to use as source textures
--output-width --output-height-ow, -oh-ow NUMBER, -oh NUMBER512, 512Output width and height
--octaves-o-o NUMBER4Number of octaves
--layers-l-l LAYERS [LAYERS ... ][2,7]Which layers to match gram matrices on
--join-mode-j-j {average, max}averageHow to combine gram matrices when multiple sources given
--mul--mul NUMBER1.0Multiply target grams by this amount
--seed--seed {random, symmetric}randomHow to seed the optimization
--source-scale-ss-ss NUMBERNoneHow much to scale the source image by
--source-width-sw-sw NUMBERNoneScale source to this width. Mutually exclusive with source-scale
--padding-mode-p-p {valid, same}validWhat boundary condition to use for convolutions
--tol--tol NUMBER1e-09Gradient scale at which to terminate optimization
--data-dir-d-d DIRECTORY"model_data"Where to find the VGG weight files
--output-dir--output-dir DIRECTORY"outputs"Where to save the generated outputs
--max-iter-m-m NUMBER500Maximum iterations for the L-BFGS-B optimizer
--output-prefix-op-op PREFIX"out"Prefix to append to output directory
--save-every-n-n NUMBER10Save an in-progress optimization image every SAVE_EVERY iterations
--count-c-c NUMBER1How many images to generate simultaneously
--if-weight--if-weight NUMBER1.0Inter-frame loss weight
--if-shift--if-shift NUMBER5.0How many pixel-shift should inter-frame loss approximate?
--if-order--if-order NUMBER2.0How many frames should we 'tie' together?

Details:

Figure from the paper that illustrates the network architecture

Tensorflow: Library that abstracts the details of common operations performed in machine learning

Keras: Python interface for Tensorflow

Gram matrices: Given a set of V\textbf{V} of m\textbf{m} vectors, the Gram matrix G\mathbf{G} is the matrix of all possible inner products of V\mathbf{V}. [ gij=viTvjg_{ij} = \mathbf{v_i}^T \mathbf{v_j} ]

ImageNet: Image database that has an average of 500 images per label

VGG architectures: Pre-trained CNNs on ImageNet dataset. Keras now includes VGG-16 and VGG-19. VGG-19 network is 19 layers deep (16 convolutional + 3 fully connected) and can classify images into 1000 object categories.

Network architecture of VGG-19 model

Gaussian Pyramid: An image processing technique that iteratively blurs and down-samples the image.

Illustration of gaussian pyramid

Download & Install:

https://github.com/wxs/subjective-functions

Tested on Ubuntu 18.04 with Python 3.6.12.

  • possibly will run the same on MacOS
git clone https://github.com/wxs/subjective-functions.git
cd subjective-functions

pip3 install Pillow
pip3 install scipy==1.5.2
pip3 install numpy==1.19.2
pip3 install --user --upgrade tensorflow-gpu
pip3 install --user --upgrade tensorboard
pip3 install keras==2.3.1
pip3 install --user --upgrade tensorflow-gpu==1.14.0
pip3 install h5py==2.10.0

KERAS_BACKEND=tensorflow python3 synthesize.py -s bark.jpg


# If you would like to use different arguments, simply append them at 
# the end of the above line. e.g.:
KERAS_BACKEND=tensorflow python3 synthesize.py -s bark.jpg -o 1 -l 3 5 -mul 1.5

# Sequencing multiple runs back to back (put a semi column (;) in between different lines). e.g.:
KERAS_BACKEND=tensorflow python3 synthesize.py -s bark.jpg -l 3 8 -mul 1.5 ; KERAS_BACKEND=tensorflow python3 synthesize.py -s bark.jpg -o 2 -l 2 5 ; 

Possible roadblock:

  • Modify h5py library in /home/<USERNAME>/.local/lib/python3.6/site-packages/keras/engine/saving.py

Line 273:

model_config = json.loads(model_config.decode('utf-8'))

to

model_config = json.loads(model_config)#.decode('utf-8'))

Line 278:

original_keras_version = model_weights_group['keras_version'].decode('utf8')

to

original_keras_version = model_weights_group['keras_version']#.decode('utf8')

Line 282:

original_backend = model_weights_group['backend'].decode('utf8')

to

original_backend = model_weights_group['backend']#.decode('utf8')