Search in sources :

Example 1 with FastRandomForest

use of hr.irb.fastRandomForest.FastRandomForest in project labkit-ui by juglab.

the class TrainableSegmentationSegmenter method train.

@Override
public void train(List<Pair<ImgPlus<?>, Labeling>> trainingData) {
    try {
        initFeatureSettings(trainingData);
        List<String> classes = collectLabels(trainingData.stream().map(Pair::getB).collect(Collectors.toList()));
        sc.fiji.labkit.pixel_classification.classification.Segmenter segmenter = new sc.fiji.labkit.pixel_classification.classification.Segmenter(context, classes, featureSettings, new FastRandomForest());
        segmenter.setUseGpu(useGpu);
        Training training = segmenter.training();
        for (Pair<ImgPlus<?>, Labeling> pair : trainingData) trainStack(training, classes, pair.getB(), pair.getA(), segmenter.features());
        training.train();
        this.segmenter = segmenter;
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        if (cause instanceof WekaException && cause.getMessage().contains("Not enough training instances"))
            throw new CancellationException("The training requires some labeled regions.");
        throw e;
    }
}
Also used : WekaException(weka.core.WekaException) ImgPlus(net.imagej.ImgPlus) Segmenter(sc.fiji.labkit.ui.segmentation.Segmenter) Training(sc.fiji.labkit.pixel_classification.classification.Training) FastRandomForest(hr.irb.fastRandomForest.FastRandomForest) CancellationException(java.util.concurrent.CancellationException) Labeling(sc.fiji.labkit.ui.labeling.Labeling) Pair(net.imglib2.util.Pair)

Aggregations

FastRandomForest (hr.irb.fastRandomForest.FastRandomForest)1 CancellationException (java.util.concurrent.CancellationException)1 ImgPlus (net.imagej.ImgPlus)1 Pair (net.imglib2.util.Pair)1 Training (sc.fiji.labkit.pixel_classification.classification.Training)1 Labeling (sc.fiji.labkit.ui.labeling.Labeling)1 Segmenter (sc.fiji.labkit.ui.segmentation.Segmenter)1 WekaException (weka.core.WekaException)1