This repository contains code for stylizing arbitrary image datasets using AdaIN. The code is a generalization of Robert Geirhos' Stylized-ImageNet code, which is tailored to stylizing ImageNet. Everything in this repository is based on naoto0804's pytorch-AdaIN implementation.
Given an image dataset, the script creates the specified number of stylized versions of every image while keeping the directory structure and naming scheme intact (usefull for existing data loaders or if directory names include class annotations).
Feel free to open an issue in case there is any question.
models/
directoryTo stylize a dataset, run python stylize.py
.
Arguments:
--content-dir <CONTENT>
the top-level directory of the content image dataset (mandatory)--style-dir <STLYE>
the top-level directory of the style images (mandatory)--output-dir <OUTPUT>
the directory where the stylized dataset will be stored (optional, default: output/
)--num-styles <N>
number of stylizations to create for each content image (optional, default: 1
)--alpha <A>
Weight that controls the strength of stylization, should be between 0 and 1 (optional, default: 1
)--extensions <EX0> <EX1> ...
list of image extensions to scan style and content directory for (optional, default: png, jpeg, jpg
). Note: this is case sensitive, --extensions jpg
will not scan for files ending on .JPG
. Image types must be compatible with PIL's Image.open()
(Documentation)--content-size <N>
Minimum size for content images, resulting in scaling of the shorter side of the content image to N
(optional, default: 0
). Set this to 0 to keep the original image dimensions.--style-size <N>
Minimum size for style images, resulting in scaling of the shorter side of the style image to N
(optional, default: 512
). Set this to 0 to keep the original image dimensions (for large style images, this will result in high (GPU) memory consumption).--crop <N>
Size for the center crop applied to the content image in order to create a squared image (optional, default 0). Setting this to 0 will disable the cropping.Here is an example call:
python3 stylize.py --content-dir '/home/username/stylize-datasets/images/' --style-dir '/home/username/stylize-datasets/train/' --num-styles 10 --content_size 0 --style_size 256
If you use this code, please consider citing:
@article{michaelis2019dragon,
title={Benchmarking Robustness in Object Detection:
Autonomous Driving when Winter is Coming},
author={Michaelis, Claudio and Mitzkus, Benjamin and
Geirhos, Robert and Rusak, Evgenia and
Bringmann, Oliver and Ecker, Alexander S. and
Bethge, Matthias and Brendel, Wieland},
journal={arXiv preprint arXiv:1907.07484},
year={2019}
}