CompImg / LST-AI

LST-AI - Deep Learning Ensemble for Accurate MS Lesion Segmentation
https://doi.org/10.1016/j.nicl.2024.103611
MIT License
18 stars 4 forks source link

Unknown layer: 'Addons>InstanceNormalization' #11

Closed joseabernal closed 5 months ago

joseabernal commented 5 months ago

Hi,

I am getting the following error:

ValueError: Unknown layer: 'Addons>InstanceNormalization'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

Do you know how I could fix this issue? Thanks.

Jose

judajake commented 5 months ago

I am having the same issue. I am using python 3.10. Running LST Segmentation. Running segmentation on /CPU:0. Running model 0. Traceback (most recent call last): File "....bin/lst", line 7, in exec(compile(f.read(), file, 'exec')) File "programing/LST-AI/LST_AI/lst", line 320, in unet_segmentation(mni_t1=path_mni_stripped_t1w, File "programing/LST-AI/LST_AI/segment.py", line 102, in unet_segmentation mdl = load_custom_model(model, compile=False) File programing/LST-AI/LST_AI/custom_tf.py", line 28, in load_custom_model return tf.keras.models.load_model(model_path, custom_objects=custom_objects, compile=compile) File "python/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 183, in load_model return legacy_h5_format.load_model_from_hdf5(filepath) File "python/lib/python3.10/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 133, in load_model_from_hdf5 ....

judajake commented 5 months ago

I dug a bit more into this and figured out that the loading model was the problem. I was using TensorFlow 2.16.1. This seems too new for this model. Reverting to TensorFlow 2.13.0, the model will load the model. I picked 2.13 because it was the minimum version listed. I am not sure what is the newest TensorFlow that supports this model file. The model in question is: LST_AI/model/UNet3D_MS_final_mdlA.h5

joseabernal commented 5 months ago

Indeed, TensorFlow 2.13.0 does the job. This should be somewhat reflected in the ReadMe and requirements file (tensorflow==2.13.0 instead of tensorflow<=2.12.0).

CompImg commented 5 months ago

Thank you very much for reporting this. It seems indeed that tensorflow 2.16 dropped support for the .h5 model files. I will update the Readme to reflect this.