Isolated error observed with cell detection, using StarDist

Hi,

Three out of my 300 images fails to detect cells using StarDist. Here is the error I see when it fails.

INFO: Image data set to ImageData: Fluorescence, 2943.ome.tif
INFO: Loading script file D:\Projects\Opal-6plex\MyeloidPanel\scripts\Detect-Cells.groovy
INFO: Starting script at Fri Mar 05 15:56:17 EST 2021
INFO: TensorFlow version 1.15.0
INFO: Found SignatureDef: serving_default (method=tensorflow/serving/predict)
INFO: Loaded TensorFlow bundle: C:\QuPath Scripts\Stardist Models\dsb2018_heavy_augment, (input=input:0 (-1, -1, -1, 1), output=concatenate_4/concat:0 (-1, -1, -1, 33))
INFO: Detecting nuclei for 1230 tiles
WARN: Skipped 3 nucleus detection(s) due to error in resolving overlaps (0.4% of all skipped)
ERROR: IllegalArgumentException: Points of LinearRing do not form a closed linestring

ERROR: org.locationtech.jts.geom.LinearRing.validateConstruction(LinearRing.java:90)
    org.locationtech.jts.geom.LinearRing.<init>(LinearRing.java:85)
    org.locationtech.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:382)
    org.locationtech.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:369)
    org.locationtech.jts.geom.GeometryFactory.createPolygon(GeometryFactory.java:495)
    qupath.tensorflow.stardist.StarDist2D.createNuclei(StarDist2D.java:824)
    qupath.tensorflow.stardist.StarDist2D.detectObjectsForTile(StarDist2D.java:762)
    qupath.tensorflow.stardist.StarDist2D.lambda$detectObjects$5(StarDist2D.java:635)
    java.base/java.util.stream.ReferencePipeline$7$1.accept(Unknown Source)
    java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
    java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(Unknown Source)
    java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(Unknown Source)
    java.base/java.util.stream.AbstractTask.compute(Unknown Source)
    java.base/java.util.concurrent.CountedCompleter.exec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

INFO: Script run time: 35.57 seconds
WARN: Skipped 1 nucleus detection(s) due to error in resolving overlaps (0.1% of all skipped)
WARN: Skipped 1 nucleus detection(s) due to error in resolving overlaps (0.1% of all skipped)

I am running QuPath-0.3.0-SnapShot from the dev-0.3.0 branch, with tensorflow-cpu on windows. I have not yet tested the same with 0.2.3.

Thanks, it sounds like that will be hard to replicate but it should be possible to wrap the key bit of code so that the faulty polygon is simply ignored rather than causing an error.

Just to be sure: does the error cause a total failure in the cell detection, or is the error logged but the rest of the detection works?

Yes, it will be almost impossible to replicate.

When I had this error in the past I remember changing the .pixelSize(micron) in the StarDist2D.builder(model), it did help. This time with this particular image nothing seem to help. It fails with error and no cell are detected. The annotation gets locked once the cell detection crashes.

@petebankhead, surprisingly it didn’t fail on version 0.2.2 with the same parameters. It does fail on the most recent version compiled today.

Does it work in v0.2.3?

@petebankhead , with tensorflow-cpu, cell detection in both the version 0.2.2 and 0.2.3 works okay. It does not fail on the image in question.

I also noticed this in the logs for 0.2.2 and 0.2.3, which I do not see in the logs for 0.3.0-SNAPSHOT It probably crashed before it reached this point. Please disregard this.

WARN: Unable to create cell ROI for Cell - I'll use the nucleus ROI instead
WARN: Unable to create cell ROI for Cell - I'll use the nucleus ROI instead
WARN: Unable to create cell ROI for Cell - I'll use the nucleus ROI instead

I also verified again this morning with 0.3.0-SNAPSHOT, and it fails. I can successfully reproduce with the same image.

ERROR: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR: org.locationtech.jts.geom.LinearRing.validateConstruction(LinearRing.java:93)
    org.locationtech.jts.geom.LinearRing.<init>(LinearRing.java:88)
    org.locationtech.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:382)
    org.locationtech.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:369)
    org.locationtech.jts.geom.GeometryFactory.createPolygon(GeometryFactory.java:495)
    qupath.tensorflow.stardist.StarDist2D.createNuclei(StarDist2D.java:824)
    qupath.tensorflow.stardist.StarDist2D.detectObjectsForTile(StarDist2D.java:762)
    qupath.tensorflow.stardist.StarDist2D.lambda$detectObjects$5(StarDist2D.java:635)
    java.base/java.util.stream.ReferencePipeline$7$1.accept(Unknown Source)
    java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
    java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(Unknown Source)
    java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(Unknown Source)
    java.base/java.util.stream.AbstractTask.compute(Unknown Source)
    java.base/java.util.concurrent.CountedCompleter.exec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)