Open mcmaxl opened 1 year ago
This may happen when you change enabled features after you load your classifier. Here is how to reproduce with 3.2.34
diff --git a/src/test/java/trainableSegmentation/BasicTest.java b/src/test/java/trainableSegmentation/BasicTest.java
index 5ad8639..bc0ca82 100644
--- a/src/test/java/trainableSegmentation/BasicTest.java
+++ b/src/test/java/trainableSegmentation/BasicTest.java
@@ -47,6 +47,16 @@ public class BasicTest
{
assertTrue("Misclassified training sample", pix[i] == pixTrue[i]);
}
+
+ // TODO: avoid testing the file system
+ boolean[] ff = segmentator.getEnabledFeatures();
+ segmentator.saveClassifier("test1.classifier");
+ segmentator = new WekaSegmentation();
+ segmentator.loadClassifier("test1.classifier"); // <- load
+ ff[0] = false; // <- turn off gaussian blur
+ segmentator.setEnabledFeatures(ff);
+ result = segmentator.applyClassifier(image);
+ assertTrue("Failed to apply trained classifier", null != result);
}
@Test
mvn test
(after adjusting pom.xml to some recent scijava version say 37.0.0) would produce
Could not apply Classifier!
java.lang.ArrayIndexOutOfBoundsException: Index 74 out of bounds for length 72
weka.core.DenseInstance.value(DenseInstance.java:347)
weka.core.AbstractInstance.isMissing(AbstractInstance.java:319)
hr.irb.fastRandomForest.FastRandomTree.distributionForInstance(FastRandomTree.java:248)
hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:645)
hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
trainableSegmentation.WekaSegmentation$9.call(WekaSegmentation.java:7096)
trainableSegmentation.WekaSegmentation$9.call(WekaSegmentation.java:1)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:829)
at weka.core.DenseInstance.value(DenseInstance.java:347)
at weka.core.AbstractInstance.isMissing(AbstractInstance.java:319)
at hr.irb.fastRandomForest.FastRandomTree.distributionForInstance(FastRandomTree.java:248)
at hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:645)
at hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
at trainableSegmentation.WekaSegmentation$9.call(WekaSegmentation.java:7096)
at trainableSegmentation.WekaSegmentation$9.call(WekaSegmentation.java:1)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Exception in thread "Thread-2" java.lang.NullPointerException
trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6763)
trainableSegmentation.WekaSegmentation$1ApplyClassifierThread.run(WekaSegmentation.java:5508)
at trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6763)
at trainableSegmentation.WekaSegmentation$1ApplyClassifierThread.run(WekaSegmentation.java:5508)
This perfectly matches your output.
This might be related to #74 as I saw the stack trace from this issue while trying to incorrectly fix 74.
Hi everyone,
while trying to apply a previously trained model to a number of files in a folder using the standard script provided here https://imagej.net/plugins/tws/scripting#example-apply-classifier-to-all-images-in-folder I get the follow error in a pop up window: "Could not apply Classifier!"
The script window gives me the following output:
while the Fiji console gives me this:
I am running Fiji/ImageJ2 Version 2.9.0/1.53t Build: a33148d777 and have tried this with both the inbuilt Trainable_Segmentation-3.3.2 as well as Trainable_Segmentation-3.2.34.
I also tried using an older Fiji Version (ImageJ 2.1.0 Build 5f23140693) with inbuilt Trainable_Segmentation-3.2.34. Same error. Script log output shows:
while Fiji console shows:
I am running Mac OS 13.2.1
Any ideas what the problem might be? Thanks very much for any help!