cyclicGAN issues and solutions
Some issues I faced and some suggested solutions:
-
ImportError: cannot import name 'InstanceNormalization'
#from keras_contrib.layers.normalization import InstanceNormalization, InputSpec from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization from keras_contrib.layers.normalization import InputSpec -
ImportError: cannot import name 'Container'
#from keras.engine.topology import Container from keras.engine.network import Network -
ImportError: cannot import name 'imsave'
pip install pillow from PIL import Image #toimage(image, cmin=-1, cmax=1).save(path_name) Image.fromarray(image.astype(np.uint8)).save(path_name) -
AttributeError: module 'tensorflow' has no attribute 'squared_difference'
#loss = tf.reduce_mean(tf.squared_difference(y_pred, y_true)) loss = tf.reduce_mean(tf.math.squared_difference(y_pred, y_true)) -
AttributeError: module 'tensorflow' has no attribute 'ConfigProto',
#config = tf.ConfigProto() config = tf.compat.v1.ConfigProto() -
AttributeError: module 'tensorflow' has no attribute 'Session'
#K.tensorflow_backend.set_session(tf.Session(config=config)) tf.compat.v1.keras.backend.get_session(config)
A simpler solution is to use the correct versions:
pip uninstall -y tensorflow
pip install tensorflow-gpu==1.14.0
pip uninstall keras
pip install keras==2.1.2
Issues related to image size: resize the images to one channel (256,304) e.g.
import os
from PIL import Image
newSize = (256, 304)
dirNms=["trainA","trainB","testA","testB"]
for d in dirNms:
fnms = os.listdir(os.path.join(datasetPath,d))
for fnm in fnms:
im = Image.open(os.path.join(dPath,fnm)).convert('L')
im = im.resize(newSize)
im.save(imgPath)
#endfor
#endfor
Issues related to black output image:
the output of the model has a range [-1,1]. It needs to be rescaled before saving it e.g.
synt_A = synthetic_images_A[i]
synt_A = ( (synt_A - np.amin(synt_A) ) * (255 / (np.amax(synt_A)- np.amin(synt_A)) ) )
Not sure about this but it seems most of the image is black even after rescaling. Maybe the model fails to produce a valid results.
A simpler solution is to use the correct versions:
pip uninstall -y tensorflow pip install tensorflow-gpu==1.14.0 pip uninstall keras pip install keras==2.1.2
Alright but what version of keras_contrib do we need?
I am having a lot of troubles using this repo in 2022, why did the authors not make a requirements.txt with a list of all the required packages...