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

Segmentation fails in the middle of Running LST segmentation. #12

Closed sj-choi closed 5 months ago

sj-choi commented 5 months ago

While using Anaconda3 on an Ubuntu-based Linux system (20.04 LTS), I attempted LST-AI segmentation. Although it initially appeared to work well, it stopped mid-way through post-processing, leaving some processed files without segmentation results.

Python version=3.10.14 My packages: tensforflow=2.16.1, scikit-image=0.22.0, scipy=1.13.0, numpy=1.24.3, requests=2.31.0, pillow=10.3.0, nibabel=5.2.1. I believe the package versions all meet the requirements.

Any guidance will be appreciated.

I attached a screenshot of where the process stopped.

preprocessing...

image shape after preprocessing: (129, 153, 129)

prediction (CNN id)...

0

1

2

3

4

running postprocessing...

exporting segmentation...

Limiting the number of threads to 4

Limiting the number of threads to 4

Running LST Segmentation.

Running segmentation on /CPU:0.

Running model 0.

Traceback (most recent call last):

File "/home/xubuntu/anaconda3/envs/lst_env/bin/lst", line 7, in

exec(compile(f.read(), __file__, 'exec')) 

File "/home/xubuntu/lst_direcgtory/LST-AI/LST_AI/lst", line 320, in

unet_segmentation(mni_t1=path_mni_stripped_t1w, 

File "/home/xubuntu/lst_direcgtory/LST-AI/LST_AI/segment.py", line 102, in unet_segmentation

mdl = load_custom_model(model, compile=False) 

File "/home/xubuntu/lst_direcgtory/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 "/home/xubuntu/anaconda3/envs/lst_env/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 "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 133, in load_model_from_hdf5

model = saving_utils.model_from_config( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config

return serialization.deserialize_keras_object( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 495, in deserialize_keras_object

deserialized_obj = cls.from_config( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/models/model.py", line 512, in from_config

return functional_from_config( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/models/functional.py", line 510, in functional_from_config

process_layer(layer_data) 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/models/functional.py", line 490, in process_layer

layer = saving_utils.model_from_config( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config

return serialization.deserialize_keras_object( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 473, in deserialize_keras_object

(cls, cls_config) = class_and_config_for_serialized_keras_object( 

File "/home/xubuntu/anaconda3/envs/lst_env/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 354, in class_and_config_for_serialized_keras_object

raise ValueError( 

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.

Some files left:

image
CompImg commented 5 months ago

Hi, thanks for bringing this up! This is a new regression introduced in Tf >= 2.16, where loading models saved in .h5 format fails (with a non-helpful error message). Downgrading Tensorflow to <=2.15 should remedy this (see also the updated "requirements.txt")

sj-choi commented 5 months ago

Thank you for the tip. It worked!