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

Cannot load classifier into "blank" WekaSegmentation instance #35

Closed hanslovsky closed 7 years ago

hanslovsky commented 7 years ago

I would like to apply a trained 2D model to a 2D image but I fail at loading the classifier already. Minimum working failing example:

package de.hanslovsky.zspacing.spark.experiments.mask.weka;

import trainableSegmentation.WekaSegmentation;

public class Dummy
{

    public static void main( final String[] args )
    {
        final WekaSegmentation seg = new WekaSegmentation();
        final String cp = "/data/hanslovskyp/hk-test/ds-8/2017-02-21-7_40.model";
        seg.loadClassifier( cp );
    }

}

Output:

Field of view: max sigma = 16.0, min sigma = 0.0
Membrane thickness: 1, patch size: 19
Read class name: class 1
Read class name: class 2
Error while adjusting data!
java.lang.NullPointerException
    trainableSegmentation.WekaSegmentation.adjustSegmentationStateToData(WekaSegmentation.java:4141)
    trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:712)
    de.hanslovsky.zspacing.spark.experiments.mask.weka.Dummy.main(Dummy.java:12)

    at trainableSegmentation.WekaSegmentation.adjustSegmentationStateToData(WekaSegmentation.java:4141)
    at trainableSegmentation.WekaSegmentation.loadClassifier(WekaSegmentation.java:712)
    at de.hanslovsky.zspacing.spark.experiments.mask.weka.Dummy.main(Dummy.java:12)

featureStackArray is null at that point.

For now I can use this work-around (thanks to @stelfrich ) but I am worried that it would do unnecessary feature computations and it is more confusing to call the constructor with an ImagePlus:

final WekaSegmentation seg = new WekaSegmentation( ImagePlus imp );

See also this conversation on gitter: https://gitter.im/fiji/fiji?at=58ac564bde50490822f78ed8

iarganda commented 7 years ago

Hello @hanslovsky ! If you use the that WekaSegmentation constructor, you need to set the training image with the method setTrainingImage() as described in the [API](http://javadoc.imagej.net/Fiji/trainableSegmentation/WekaSegmentation.html#WekaSegmentation()). I will check if I can implement an alternative...

hanslovsky commented 7 years ago

As @iarganda stated on gitter, no features will be computed before call to applyClassifier. This resolves this issue for me because I can just use the WekaSegmentation( ImagePlus ) constructor without any overhead. Maybe just renaming the argument of WekaSegmentation( ImagePlus ) to just image would be a good idea.

iarganda commented 7 years ago

Thanks @hanslovsky ! I will implement an alternative to work with WekaSegmentation without using a training image as you were trying to do.