funkelab / gunpowder

A library to facilitate machine learning on multi-dimensional images.
https://funkelab.github.io/gunpowder/
MIT License
78 stars 56 forks source link

Check empty should not use sum != 0 #157

Closed Steffen-Wolf closed 1 year ago

Steffen-Wolf commented 3 years ago

In the tensorflow prediction node if skip_empty==True the check statement seems incorrect:

I am referring to https://github.com/funkey/gunpowder/blob/bb204c84293b637137b23195b8de18caf5ca1197/gunpowder/tensorflow/nodes/predict.py#L118 where the prediction is not skipped if all batch[array_key].data.sum() are not equal to zero.

However, the sum of all values can be zero even if there are non zero values in the input image. I suggest we replace it by if batch[array_key].data.any(): as proposed here: https://stackoverflow.com/questions/18395725/test-if-numpy-array-contains-only-zeros

pattonw commented 1 year ago

looks like you solved this, thanks :+1: