Git Product home page Git Product logo

stylize-datasets's Introduction

stylize-datasets

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.

Usage

  • Dependencies:

    • python >= 3.6
    • Pillow
    • torch
    • torchvision
    • tqdm
  • Download the models:

  • To 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

Citation

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}
}

stylize-datasets's People

Contributors

dkadish avatar evgeniaar avatar hvitgar avatar mmathislab avatar rgeirhos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylize-datasets's Issues

Any idea for data parrel?

Hello, thanks for your great work.

I'm making stylized-coco.
But due to CUDA out of memory, Some images (Actually 2 out of 3) are skipped.

I use Gtx 1080 ti x 5.

Do you know how to handle this code parallel?

Thanks.

RuntimeError in style_f = vgg(style)

Traceback (most recent call last):
File "stylize.py", line 155, in
main()
File "stylize.py", line 134, in main
args.alpha)
File "stylize.py", line 53, in style_transfer
style_f = vgg(style)
File "/root/anaconda3/envs/CornerNet/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/root/anaconda3/envs/CornerNet/lib/python3.6/site-packages/torch/nn/modules/container.py", line 91, in forward
input = module(input)
File "/root/anaconda3/envs/CornerNet/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/root/anaconda3/envs/CornerNet/lib/python3.6/site-packages/torch/nn/modules/padding.py", line 163, in forward
return F.pad(input, self.padding, 'reflect')
File "/root/anaconda3/envs/CornerNet/lib/python3.6/site-packages/torch/nn/functional.py", line 2171, in pad
return torch._C._nn.reflection_pad2d(input, pad)
RuntimeError: invalid argument 4: Padding size should be less than the corresponding input dimension, but got: padding (1, 1) at dimension 3 of input [1 x 3 x 1 x 1] at /opt/conda/conda-bld/pytorch_1532581333611/work/aten/src/THCUNN/generic/SpatialReflectionPadding.cu:36

local variable 'photoshop' referenced before assignment

Getting the following traceback

Traceback (most recent call last):
File "stylize.py", line 150, in
main()
File "stylize.py", line 117, in main
style_img = Image.open(style_path).convert('RGB')
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/Image.py", line 2690, in open
im = _open_core(fp, filename, prefix)
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/Image.py", line 2676, in _open_core
im = factory(fp, filename)
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 783, in jpeg_factory
im = JpegImageFile(fp, filename)
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/ImageFile.py", line 103, in init
self._open()
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 373, in _open
handler(self, i)
File "/home/moritz/anaconda3/envs/adain/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 139, in APP
self.info["photoshop"] = photoshop
UnboundLocalError: local variable 'photoshop' referenced before assignment

after around 300 images have been processed.

Any thoughts?

Misleading tqdm progress with num_styles greater than 1

I have dataset of 3999 images and I want to stylize it with num-styles=5. When stylize.py script will successfully finish it's work the progress would be at 20% mark. Here is example of the output:

20%|███████████▊                                               | 3999/19995

The problem is in line 116 in stylize.py: with tqdm(total=len(content_paths) * args.num_styles) as pbar. The pbar is created with len of number of images multiplied by number of styles. However pbar is updated only num_images times (line 156). The pbar object should be either of length of content_paths either should be updated after every style is applied.

Stylised images have problems

Thank you for your excellent work.

It doesn't work well in my environment, although it seems to work for others.
The attached image was obtained and the other images obtained are similar.
n01440764_18-stylized-66649

Could you please help me if you know the cause of the problem?

The target image is ImageNet (ILSVR2012) and the style image is the specified one (Kaggle's painter-by-numbers dataset).
The torch version (0.4.1) is correct and the model is downloaded from the specified location.
The code works all the way through without error. (The following warning was displayed, but is probably not a problem).

UserWarning: nn.Upsampling is deprecated. Use nn.functional.interpolate instead.
  warnings.warn("nn.Upsampling is deprecated. Use nn.functional.interpolate instead.")

stylizing the datasets

what format should the datasets be when applied into the content directory? and in what format are they transformed to?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.