titu1994 / Neural-Style-Transfer

Keras Implementation of Neural Style Transfer from the paper "A Neural Algorithm of Artistic Style" (http://arxiv.org/abs/1508.06576) in Keras 2.0+
Apache License 2.0
2.26k stars 481 forks source link

Bug using preserve color option #70

Open borderlineinteractive opened 4 years ago

borderlineinteractive commented 4 years ago

Hi,

Thank you very much for this nice implementation.

I am using your code successfully on Windows 10 on an iMac and AMD GPU via Plaidml. However, using the preserve color option I get a noise-like Image output with a diagonal stripe pattern. This also happens with the example images that you provide and show on your GitHub page (the Buddhist temple with water lillies style. Without the preserve color option everything works fine.

Any suggestion what might be going wrong?

Many thanks in advance!

titu1994 commented 4 years ago

There's been some issue to get color preservation working once scipy stopped supporting imread and imsave. I'd suggest going down to a version which uses older scipy and perform colorization post training

sipie800 commented 3 years ago

I encounter this too.Win10 tensorflow 2.3 and Keras 2.4.3 and all latest version required libraries. Finally figured out that this is due to some glitch on conversion between rgb and ycbcr and also between uint8 and float64, and al the same for working around among PIL,skimage,imageio. It's not a wise choose to fix all the glitches one by one because those libraries are not designed to work together in a decent way. Get it solved by removing all implementation using PIL,imageio and skimage.All of these will be done by cv2 only. And also conversion between RGB and BGR is done by cv2 rather than x=x[:,:,::-1], which just in some case, can cause unexpected result where you never imagine to be.

HitLuca commented 2 years ago

I know I'm late to the party, but to fix it you can update the fromimage function in utils.py from

def fromimage(img, mode="RGB"):
    if mode == "RGB":
        img = color.lab2rgb(img)
    else:
        img = color.rgb2lab(img)
    return img

to

def fromimage(img, mode="RGB"):
    return np.array(img.convert(mode))

as a bonus you don't need the scikit-image library anymore since it's used only for that from what I could see