GAN-MRI icon indicating copy to clipboard operation
GAN-MRI copied to clipboard

cyclicGAN issues and solutions

Open idhamari opened this issue 5 years ago • 4 comments

Some issues I faced and some suggested solutions:

  1. 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
    
  2. ImportError: cannot import name 'Container'

      #from keras.engine.topology import Container
       from keras.engine.network import Network
    
  3. 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)
    
  4. 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))
    
  5. AttributeError: module 'tensorflow' has no attribute 'ConfigProto',

    #config = tf.ConfigProto()
     config = tf.compat.v1.ConfigProto()
    
  6. AttributeError: module 'tensorflow' has no attribute 'Session'

     #K.tensorflow_backend.set_session(tf.Session(config=config))
      tf.compat.v1.keras.backend.get_session(config)
    

idhamari avatar May 31 '20 18:05 idhamari

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

idhamari avatar May 31 '20 19:05 idhamari

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

idhamari avatar Jun 01 '20 09:06 idhamari

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.

idhamari avatar Jun 01 '20 13:06 idhamari

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

charlesmoatti avatar Jun 28 '22 09:06 charlesmoatti