yusuketomoto / chainer-fast-neuralstyle

Chainer implementation of "Perceptual Losses for Real-Time Style Transfer and Super-Resolution".
MIT License
803 stars 229 forks source link

Keep original colors? #78

Open artnose opened 7 years ago

artnose commented 7 years ago

Is it possible to add a flag to keep original color of the image and only transfer the style?

// from jcjohnson's neural style -- Combine the Y channel of the generated image and the UV channels of the -- content image to perform color-independent style transfer.

yusuketomoto commented 7 years ago

Pass --keep_colors option.

artnose commented 7 years ago

That would be awesome, but I'm getting an error..
Traceback (most recent call last): File "generate.py", line 55, in <module> med = original_colors(original, med) File "generate.py", line 27, in original_colors return Image.merge('HSV', (h, s, vs)).convert('RGB') File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2404, in merge raise ValueError("size mismatch") ValueError: size mismatch

artnose commented 7 years ago

Hmm, so, input image was 800x531 and output image is 800x528 with out --keep_colors
so, it's cropping it and then the color merge doesn't work

HappyCoderMan commented 7 years ago

I'm getting very similar error, and only when I use the --keep_colors option.

I'm using the "resize-conv" branch. I have this working on Windows 10 with GPU.

Here the my console dump for a --keep_colors option: Traceback (most recent call last): File "generate.py", line 55, in med = original_colors(original, med) File "generate.py", line 27, in original_colors return Image.merge('HSV', (h, s, vs)).convert('RGB') File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 2444, in merge raise ValueError("size mismatch") ValueError: size mismatch

6o6o commented 7 years ago

Both image dimensions have to be divisible by 4, otherwise the output resolution won't match the input and original_colors function needs them to be identical.

For arbitrary dimensions to work, just resize one of the images to match the resolution before calling the function. Replace the condition with the following code:

if args.keep_colors:
    med = original_colors(original.resize((med.size), 3), med)