axondeepseg / axondeepseg

Axon/Myelin segmentation using Deep Learning
https://axondeepseg.rtfd.io/
MIT License
114 stars 32 forks source link

model_seg_human-axon-myelin_bf doesn't work since the new changes #658

Closed hermancollin closed 2 years ago

hermancollin commented 2 years ago

Description While doing some refactoring for the latest features, we missed something for model native resolution.

To Reproduce For a model without a Resample transformation:

2022-06-27 11:29:47.520 | INFO     | AxonDeepSeg.segment:main:323 - AxonDeepSeg v.4.0.0
2022-06-27 11:29:47.521 | ERROR    | AxonDeepSeg.segment:main:478 - An error has been caught in function 'main', process 'MainProcess' (611309), thread 'MainThread' (140331803146048):
Traceback (most recent call last):

  File "/home/herman/.conda/envs/ads_venv/bin/axondeepseg", line 33, in <module>
    sys.exit(load_entry_point('AxonDeepSeg', 'console_scripts', 'axondeepseg')())
    │   │    └ <function importlib_load_entry_point at 0x7fa18aec0280>
    │   └ <built-in function exit>
    └ <module 'sys' (built-in)>

> File "/home/herman/Documents/NEUROPOLY_21/axondeepseg/AxonDeepSeg/segment.py", line 478, in main
    segment_image(
    └ <function segment_image at 0x7fa128824f70>

  File "/home/herman/Documents/NEUROPOLY_21/axondeepseg/AxonDeepSeg/segment.py", line 165, in segment_image
    model_resolution, patch_size = get_model_native_resolution_and_patch(path_model)
                                   │                                     └ PosixPath('/home/herman/Documents/NEUROPOLY_21/crypte/20220316_upload_wakehealth_model_on_gh/model_seg_human_axon-myelin_bf')
                                   └ <function get_model_native_resolution_and_patch at 0x7fa128824e50>

  File "/home/herman/Documents/NEUROPOLY_21/axondeepseg/AxonDeepSeg/segment.py", line 92, in get_model_native_resolution_and_patch
    model_resolution = [model['transformation']['Resample']['wspace'], model['transformation']['Resample']['hspace']]
                        │                                              └ {'command': 'train', 'gpu_ids': [1], 'path_output': 'output/', 'model_name': 'model_seg_human_axon-myelin_bf', 'debugging': T...
                        └ {'command': 'train', 'gpu_ids': [1], 'path_output': 'output/', 'model_name': 'model_seg_human_axon-myelin_bf', 'debugging': T...

KeyError: 'Resample'
2022-06-27 11:29:47.523 | INFO     | AxonDeepSeg.segment:main:487 - Segmentation finished.

The model_seg_human_axon-myelin_bf dataset I trained (https://github.com/axondeepseg/model_seg_human_axon-myelin_bf) doesn't use resampling (not sure why, but I think I got better results with it) and since the introduction of get_model_native_resolution_and_patch, I hadn't tested it.

I will issue a quick fix for this as I need to use it to test something asap, either by fixing the get_model_native_resolution_and_patch or by adding resampling to the model so that it resamples to the exact pixel size of the training data.

mathieuboudreau commented 2 years ago

Feel free to assign me to review

hermancollin commented 2 years ago

Actually get_model_native_resolution_and_patch isn't the only problem. I need to completely remove the ONNX model from this repo because it simply doesn't work. I was kinda pissed that the model produced trash segmentations after so much time optimizing its training... then I remembered what is documented in this issue: https://github.com/ivadomed/ivadomed/issues/882 I deleted the ONNX model so that ADS takes the pytorch one instead, and the segmentation was immediately visually perfect.

hermancollin commented 2 years ago

Ok so I fixed it. There's no way to correct this on the ADS side because the Resample transformation is the only way we have to get the model's native resolution. Also, this field is mentioned in the microscopy tutorial @mariehbourget wrote so any user that is comfortable enough to train a model should already have it in his config.

The solution was to add a resampling operation to the wakehealth model so that it resamples the image to the 0.226 um/px resolution (training image px size). Now it is usable.

Oh and I also entirely removed the highly frustrating ONNX model from the repo because it's useless and repeatedly caused me problems.