CycleGAN-TensorFlow
CycleGAN-TensorFlow copied to clipboard
utils.convert2float incorrect
Hi I think that the utility function convert2float called in preprocess function of reader is incorrect. I believe the desired functionality is to convert the image from [0,255] int format to [-1,1] float format.
The code is
def convert2float(image): """ Transfrom from int image ([0,255]) to float tensor ([-1.,1.]) """ image = tf.image.convert_image_dtype(image, dtype=tf.float32) return (image/127.5) - 1.0
The issue is in dividing the image by 127.5 after scaling. The tf.image.convert_image_dtype function scales images to [0,1] floats already, so you actually need to multiply by 2 and then subtract 1, not divide by 127.5.
The behavior of tf.image.convert_image_dtype
is quite confusing. When I called this, it returned [0.0, 255.0] instead of [0.0, 1.0].
There is an issue related to it: https://github.com/tensorflow/tensorflow/issues/1763
As you point out in #38, I may misuse this function.
#37 and #38 should be fixed together.
Thank you for your feedback!
Yea in my opinion its sort of a dangerous function that tries to be too smart. They should probably break it into 2 functions and raise an error if your input isnt in some specific format
@lucasgreene @vanhuyz
great work! So the current wrong code should be the same with the right code, and I don't need to fix them?
update: I found that tensorflow process images in a different way from scipy I performed same operation with scipy on images : (as in the code )
- resize (bilinear)
- / 127.5 - 1
The images processed by tensorflow show more noise, while the images processed by scipy are much better. It may be the cause for the obvious noise and artifact on those sample appleoranges. I don't know how to solve it, do you have any idea?