stardist / stardist

StarDist - Object Detection with Star-convex Shapes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

relabel_image_stardist for empty image errors out

maweigert opened this issue · comments

relabel_image_stardist currently throws an error for an empty image (but should not)

import numpy as np
from stardist import relabel_image_stardist

y = np.zeros((100,100), np.uint16)
relabel_image_stardist(y,32)

AssertionError

Hi! I encountered the same issue because I am trying to run the model on a private dataset. I fixed the bug locally by making the polygons_to_label function return an empty label image when the dimension of the centroids is 1 (empty array) right before the assert instruction that throws the error:

if points.ndim==1:
   return np.zeros(shape,dtype='int32')

assert dist.ndim==2 and points.ndim==2 and len(dist)==len(points)

I wonder if this bug has not been fixed for subtle additional reasons. For example, should training be avoided on empty images? I can tell more about this after I run the model on my images.

Thanks for the reminder that this hasn't been fixed, @Vadori!

I just added commit 4765951 to fix this.

I wonder if this bug has not been fixed for subtle additional reasons.

I don't think so, it probably just didn't pop up in practice to annoy us enough to fix it.

For example, should training be avoided on empty images?

Having empty images in the training set is not a bad thing, especially if those are necessary to prevent nuclei predictions on regions with imaging artifacts. But keep in mind that the loss for the object distances/shape is only active for pixels that belong to a labeled object.