frankkramer-lab / MIScnn

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

Predict fucntion is broken #48

Closed jumutc closed 3 years ago

jumutc commented 3 years ago

I have tried an example notebook CellTracking.ipynb with the latest miscnn==1.1.1 and got this error on predict:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-25142bc8de9f> in <module>
----> 1 model.predict(sample_list[0:1])

~/repos/experiments/bacteria/venv/lib/python3.7/site-packages/miscnn/neural_network/model.py in predict(self, sample_list, return_output, activation_output)
    159             dataGen = DataGenerator([sample], self.preprocessor,
    160                                     training=False, validation=False,
--> 161                                     shuffle=False, iterations=None)
    162             # Run prediction process with Keras predict
    163             pred_list = []

~/repos/experiments/bacteria/venv/lib/python3.7/site-packages/miscnn/neural_network/data_generator.py in __init__(self, sample_list, preprocessor, training, validation, shuffle, iterations)
     49         # If samples with subroutines should be preprocessed -> do it now
     50         if preprocessor.prepare_subfunctions:
---> 51             preprocessor.run_subfunctions(sample_list, training)
     52         # If batches should be prepared before runtime -> do it now
     53         if preprocessor.prepare_batches:

~/repos/experiments/bacteria/venv/lib/python3.7/site-packages/miscnn/processing/preprocessor.py in run_subfunctions(self, indices_list, training)
    223         if not self.use_multiprocessing or not training:
    224             for index in indices_list:
--> 225                 self.prepare_sample_subfunctions(index, training)
    226         # Prepare subfunctions using multiprocessing
    227         else:

~/repos/experiments/bacteria/venv/lib/python3.7/site-packages/miscnn/processing/preprocessor.py in prepare_sample_subfunctions(self, index, training)
    242         # Transform array data types in order to save disk space
    243         sample.img_data = np.array(sample.img_data, dtype=np.float32)
--> 244         sample.seg_data = np.array(sample.seg_data, dtype=np.uint8)
    245         # Backup sample as pickle to disk
    246         self.data_io.backup_sample(sample)

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Looking into source code it is clear that we are missing in preprocessor:prepare_sample_subfunctions something like:

if training:
  sample.seg_data = np.array(sample.seg_data, dtype=np.uint8)

By adding the above all problems are solved!

muellerdo commented 3 years ago

Hey @jumutc,

Thank you for spotting this bug and also for providing already the solution! Sorry that this slipped through the testing. I will fix this issue and add another unittest for catching this scenario in the future.

Cheers, Dominik

Tasks

Related Commits: 6acc91ed1b0e9922d5f6bd2a88849ba3298030e9 6a6533fe069515241324ac243b51d3a16b9a827c

jumutc commented 3 years ago

Thanks @muellerdo, for now I switched to version 1.0