fiji / Trainable_Segmentation

Fiji library to perform image segmentation based on the Weka learning schemes
https://imagej.net/Trainable_Weka_Segmentation
GNU General Public License v3.0
106 stars 60 forks source link

Question about training classifier #49

Open CarmenSC opened 5 years ago

CarmenSC commented 5 years ago

Hi,

Some context: I am new using Fiji and WEKA. I am trying to spot some structures in my plants to count them automatically. It worked really well with the first photograph, so I save the model.

I load the model and apply it to a second picture, and it worked but less efficiently. That's why I decided to keep training the model. I tried to do it and I got an error message in WEKA.

The traning did not finish.
Training input:
# of pixels selected as Sporophytes: 2856
# of pixels selected as Background: 18911
# of pixels selected as Sporophytes_Closed: 5517
Creating training data took: 10334ms
Training classifier...
FastRandomForest of 200 trees, each constructed while considering 2 random features.
Out of bag error: 0.48%

Finished training in 240647ms
Classifying whole image using 4 thread(s)...
Error while classifying whole image! 
Finished segmentation of whole image.

My question is:

Can I train the model using different images?

I also added a third category (label) when I did the training the second time. Dunno if that's part of the problem too.

The warning message is below:

WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@764c12b6)
java.lang.ArrayIndexOutOfBoundsException: 2
    hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    java.util.concurrent.FutureTask.run(FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:745)

    at hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    at hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 2
    hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    java.util.concurrent.FutureTask.run(FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:745)

    at hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    at hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 2
    hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    java.util.concurrent.FutureTask.run(FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:745)

    at hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    at hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 2
    hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    java.util.concurrent.FutureTask.run(FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:745)

    at hr.irb.fastRandomForest.FastRfBagging.distributionForInstance(FastRfBagging.java:647)
    at hr.irb.fastRandomForest.FastRandomForest.distributionForInstance(FastRandomForest.java:646)
    at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:173)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:7025)
    at trainableSegmentation.WekaSegmentation$8.call(WekaSegmentation.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
    trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6921)
    trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6361)
    trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6288)
    trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1470)

    at trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6921)
    at trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6361)
    at trainableSegmentation.WekaSegmentation.applyClassifier(WekaSegmentation.java:6288)
    at trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1470)
iarganda commented 5 years ago

Hello @CarmenSC ,

This is strange. Can you describe the steps you followed after your trained a first time?

To train on different images you have two options:

  1. Load a stack of images and call the plugin. The training will be done using all images with annotations.
  2. Load and image, call the plugin and perform the training, click on "save data" to store the feature vectors used for training, load another image, call the plugin and click on "load data" to use the previous feature vectors as well.

I hope this helps!

PS: please consider posting your questions in the ImageJ forum so everybody can contribute to and benefit from the answers :)