use of sc.fiji.labkit.pixel_classification.classification.Training 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;
}
}
Aggregations