use of sc.fiji.labkit.ui.segmentation.Segmenter 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;
}
}
use of sc.fiji.labkit.ui.segmentation.Segmenter in project labkit-ui by juglab.
the class DefaultSegmentationModel method getPredictions.
public List<RandomAccessibleInterval<FloatType>> getPredictions() {
ImgPlus<?> image = imageLabelingModel().imageForSegmentation().get();
Stream<Segmenter> trainedSegmenters = getTrainedSegmenters();
return trainedSegmenters.map(segmenter -> {
int numberOfClasses = segmenter.classNames().size();
RandomAccessibleInterval<FloatType> prediction = new CellImgFactory<>(new FloatType()).create(DimensionUtils.appendDimensionToInterval(image, 0, numberOfClasses - 1));
segmenter.predict(image, prediction);
return prediction;
}).collect(Collectors.toList());
}
Aggregations