Docker images with set-up style transfer environments
This repository contains two images:
-
neural-fast-style-transfer
containing:- neural-style
- fast-style-transfer
- pre-trained VGG 19 network required by both repos
- example models for fast-style-transfer
-
chainer-style-transfer
containing:- chainer-fast-neuralstyle
- pre-trained VGG 16 network required for training
- the following files are not included:
- coco2014 dataset needed for training new models for fast-style-transfer and chainer-fast-neuralstyle
- linux box with a Nvidia GPU and recent drivers
- docker and nvidia-docker installed
-
Entering into interactive bash
$ docker run -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer bash
$ docker run -ti --rm --runtime=nvidia jtomori/chainer-style-transfer bash
-
Command structure: append your style transfer command at the end:
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer [your command here]
This will mount host system working directory into
/app/work
in container. File structure in the container looks like this inneural-fast-style-transfer
|--- app/ |--- work/ (working directory) |--- neural-style/ |--- fast-style-transfer/ |--- imagenet-vgg-verydeep-19.mat
and like this in
chainer-style-transfer
|--- app/ |--- work/ (working directory) |--- chainer-fast-neuralstyle/
- Run style transfer on included example images
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer python ../neural-style/neural_style.py --network ../imagenet-vgg-verydeep-19.mat --content ../neural-style/examples/1-content.jpg --styles ../neural-style/examples/1-style.jpg --output test.jpg --iterations 10 ``` This should produce `test.jpg` image in current working directory
- Run style transfer on your own images
This will transfer style of
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer python ../neural-style/neural_style.py --network ../imagenet-vgg-verydeep-19.mat --content content.jpg --styles style.jpg --output test.jpg --iterations 10
style.jpg
ontocontent.jpg
resulting intest.jpg
in current host working directory.
-
Run style transfer on included example image with model
la_muse.ckpt
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer python ../fast-style-transfer/evaluate.py --checkpoint ../fast-style-transfer/examples/models/la_muse.ckpt --in-path ../fast-style-transfer/examples/content/chicago.jpg --out-path test.jpg
This will transfer style of example model
la_muse.ckpt
on example image provided with the repository resulting intest.jpg
. You can replace../fast-style-transfer/examples/content/chicago.jpg
withcontent.jpg
to apply style oncontent.jpg
in your current host directory.Included example models:
la_muse.ckpt
rain_princess.ckpt
scream.ckpt
udnie.ckpt
wave.ckpt
wreck.ckpt
-
Train a new model based on
style.jpg
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/neural-fast-style-transfer python ../fast-style-transfer/style.py --vgg-path ../imagenet-vgg-verydeep-19.mat --style style.jpg --checkpoint-dir model --train-path dataset
Note that you need to pass path to coco2014 dataset, which is not included in the Docker image. In this case it is
dataset
folder in host working directory.model
directory also needs to be created there.
-
Run style transfer on included example image and model, which will result in
test.jpg
in your curent host working directory$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/chainer-style-transfer python3 ../chainer-fast-neuralstyle/generate.py ../chainer-fast-neuralstyle/sample_images/tubingen.jpg -m ../chainer-fast-neuralstyle/models/composition.model -o test.jpg -g 0
Included example models:
composition.model
seurat.model
Note: You can use
--memory 7000m
optional argument, which limits containers memory usage. Set it accordingly to your free memory if you encounter system crashes. -
Train a new model
$ docker run -v "$(pwd)":/app/work -ti --rm --runtime=nvidia jtomori/chainer-style-transfer python3 ../chainer-fast-neuralstyle/train.py --vggmodel ../chainer-fast-neuralstyle/vgg16.model --dataset dataset/ --style_image style.jpg --output model/style -g 0
This will generate a new model
model/style.model
based onstyle.jpg
in a current host working directory.dataset
folder also needs to be present there.
This step is required only if you want to make modifications to the image and to do a local build.
- Clone this repo and enter it
$ git clone https://github.com/jtomori/style_transfer_docker.git $ cd style_transfer_docker
- Build images
neural-fast-style-transfer
$ docker build -t neural-fast-style-transfer neural-fast-style-transfer
chainer-style-transfer
$ docker build -t chainer-style-transfer chainer-style-transfer