frankkramer-lab / MIScnn

A framework for Medical Image Segmentation with Convolutional Neural Networks and Deep Learning
GNU General Public License v3.0
398 stars 116 forks source link

AssertionError on predict with activation_output=True #121

Closed jumutc closed 2 years ago

jumutc commented 2 years ago

Hello,

I'm using a bit older version of MIScnn==1.1.9 but I have checked that code in master is basically the same around this stacktrace. Number of classes is 12 here and we are dealing with multi-class segmentation problem.

AssertionError                            Traceback (most recent call last)
<ipython-input-7-ed91e9d14dc7> in <module>
     58                   'tversky_crossentropy': tversky_crossentropy
     59               })
---> 60         model.predict(test_samples, activation_output=True)
     61 
     62         for sample_test in test_samples:

c:\users\students\desktop\bacteria_cfu\code\miscnn-master\miscnn\neural_network\model.py in predict(self, sample_list, return_output, activation_output)
    171             # Postprocess prediction
    172             sampleObj = self.preprocessor.cache.pop(sample)
--> 173             pred_seg = self.preprocessor.postprocessing(sampleObj, pred_seg,
    174                                                         activation_output)
    175             # Backup predicted segmentation

c:\users\students\desktop\bacteria_cfu\code\miscnn-master\miscnn\processing\preprocessor.py in postprocessing(self, sample, prediction, activation_output)
    219         # Run Subfunction postprocessing on the prediction
    220         for sf in reversed(self.subfunctions):
--> 221             prediction = sf.postprocessing(sample, prediction)
    222         # Return postprocessed prediction
    223         return prediction

c:\users\students\desktop\bacteria_cfu\code\miscnn-master\miscnn\processing\subfunctions\resize.py in postprocessing(self, sample, prediction)
     77         prediction = np.moveaxis(prediction, -1, 0)
     78         # Resize imaging data
---> 79         prediction = resize_segmentation(prediction, original_shape, order=1,
     80                                          cval=0)
     81         # Transform data from channel-first back to channel-last structure

~\anaconda3\envs\cfu_segmentation\lib\site-packages\batchgenerators\augmentations\utils.py in resize_segmentation(segmentation, new_shape, order, cval)
    596     tpe = segmentation.dtype
    597     unique_labels = np.unique(segmentation)
--> 598     assert len(segmentation.shape) == len(new_shape), "new shape must have same dimensionality as segmentation"
    599     if order == 0:
    600         return resize(segmentation.astype(float), new_shape, order, mode="constant", cval=cval, clip=True, anti_aliasing=False).astype(tpe)

AssertionError: new shape must have same dimensionality as segmentation
muellerdo commented 2 years ago

Hello @jumutc,

sorry for the late reply.

The issues with non-functional activation_output if using subfunctions like Resize is known for version <=1.3.0 and was fixed in these commits here: a37fb858f6c667566d214dfdf7ea0faf6dc77d57 and fd9046a88a5df1afc21b92ec0645c17c28481b38.

The issue was in the subfunctions of Resize/Resampling due to the postprocessing resize expected a mask with sparse encoding and not a continuous format like activation outputs. We solved this issue in 1.4.0 as well as added unittesting for it.

If possible, please update to the current version 1.4.0.

If not due to e.g. older cluster requirements, check out these commits:

Cheers, Dominik

jumutc commented 2 years ago

OK, thanks @muellerdo