OrsTrainer

Manages the segmentation trainer

author:

Dragonfly Team

contact:

https://dragonfly.comet.tech

email:

support.dragonfly@comet.tech

organization:

Comet Technologies Canada Inc.

address:

460 Ste-Catherine Ouest, suite 600, Montréal, Québec, Canada, H3B 1A7

copyright:

Comet Technologies Canada Inc. All rights reserved 2023.

date:

Jul 31 2017 12:45

dragonflyVersion:

3.1.0.286 (D)

UUID:

68f8d3f6761d11e7b495448a5b5d70c0

Class Code

class OrsPythonPlugins.OrsTrainer.OrsTrainer.OrsTrainer(*args, **kwargs)
interfacemethod classification(classifier: AIModelAbstract, classifierManager: ClassifiersManager, channels: List[Channel], mask: ROI, classificationResults: PreviewClassifierResults, computeConfidenceMap: bool = False, confidenceRange: tuple = (0, 100), regionGenerator: RegionAlgorithmsAbstract = None, progress: Progress = None) bool

Classify a dataset with a machine learning classifier that has previously been trained (see Train interface method). It can classify a dataset on an area defined by a mask. The classification can be done per pixel or per regions, defined by the region generator. The features can be extracted from filter presets (known by the classifier) or automatically from a keras autoencoder. The classification can be done on a preview or on the complete dataset.

Parameters:
  • classifier (transient AIModelAbstract) – segmentation classifier

  • classifierManager (transient ClassifiersManager) – the classifier manager. Knows all the classifiers available and their location.

  • channels (ORSModel.ors.Channel) [count=[1, None]] – channel inputs of the classifier to generate features

  • mask (ORSModel.ors.ROI) – mask regions where the classifier works

  • classificationResults (transient PreviewClassifierResults) – classificationPreviewResults result struct

  • computeConfidenceMap (bool) – indicate if we wan’t the confidence map to be computed

  • confidenceRange (tuple) – confidence min and max range. If this parameter is given the output confidence map is not computed

  • regionGenerator (transient RegionAlgorithmsAbstract) – if the working area is Pixel, there is no regionGenerator. if the working area is Region, the regionGenerator is an instance of a class specifying the algorithm to use to generate regions and its inputs and parameters

  • progress (ORSModel.ors.Progress) – a progress bar

Returns:

succes (bool) – return succes

interfacemethod classificationOnPreview(classifier: AIModelAbstract, classifierManager: ClassifiersManager, channels: List[Channel], previewHelper: ModelPreviewHelper, classificationPreviewParams: dict, regionGenerator: RegionAlgorithmsAbstract = None) None

Classify a dataset with a machine learning classifier that has previously been trained (see Train interface method). It can classify a dataset on an area defined by a mask. The classification can be done per pixel or per regions, defined by the region generator. The features can be extracted from filter presets (known by the classifier) or automatically from a keras autoencoder. The classification is done on preview (A slice channel on each view is classified).

Parameters:
  • classifier (transient AIModelAbstract) – segmentation classifier

  • classifierManager (transient ClassifiersManager) – the classifier manager. Knows all the classifiers available and their location.

  • channels (ORSModel.ors.Channel) [count=[1, None]] – channel inputs of the classifier to generate features

  • previewHelper (transient ModelPreviewHelper) – preview helper

  • classificationPreviewParams (dict) – parameters for results preview

  • regionGenerator (transient RegionAlgorithmsAbstract) – if the working area is Pixel, there is no regionGenerator. if the working area is Region, the regionGenerator is an instance of a class specifying the algorithm to use to generate regions and its inputs and parameters

cleanup()

Deletes the variables managed by the plugin. It is the place to remove callbacks and other references to Python objects that would prevent them to be garbage collected. This method is called during the process of deletion of the plugin. It calls for the cleanup and deletion of the forms.

creationOfRegions(landscapeDataset, regionGenerator, onPreview=True)

Compute the Regions Preview, storing the result in the classificationResult instance :param landscapeDataset: (Channel) :param regionGenerator: RegionAlgorithmsAbstract :param onPreview: (bool) True if we extract a previewLandscapePreview from the view, False if we produce regions for the whole landscapeDataset

exportPreview(bClassification=False, bRegions=False, bConfidenceMap=False)

Publish the currently displayed in views classification and regions, with the associated confidenceMap :param bClassification: (bool) :param bRegions: (bool) :param bConfidenceMap: (bool)

classmethod getMainFormClass()

Gets the class of the main form

Returns:

output

handleChanged(oldState, newState)

This method is called when the state of the application is changed.

Parameters:
  • oldState (str) – name of the old (previous) state

  • newState (str) – name of the new (current) state

handleTriggered(eventdata)

This method is called on every user input (mouse move, mouse click, key press, …) when the current state of the application is one of those declared by the plugin. This method can be used to perform specific tasks even if no action is currently in progress.

Parameters:

eventData (OrsEvent.eventdata.InputEventData) – the event data

classmethod startupDefault(openMainForm=True)

Creates an instance of the plugin class and opens the main form (if required) at the default position.

Returns:

output (AbstractPlugin) – plugin instance

interfacemethod training(classifier: AIModelAbstract, classifierManager: ClassifiersManager, trainingDatasets: List[AIDataset], regionGenerator: RegionAlgorithmsAbstract = None, save_classifier: bool = True) bool

Train a machine learning classifier based on features extracted from channels and from classes defined by rois. After it is trained, the classifier could be used to classify any similar dataset. The training area can be defined by a mask and it can be done per pixel or per regions, defined by the region generator. The features can be extracted from filter presets (known by the classifier) or automatically from a keras autoencoder.

Parameters:
  • classifier (transient AIModelAbstract) – segmentation classifier

  • classifierManager (transient ClassifiersManager) – the classifier manager. Knows all the classifiers available and their location.

  • trainingDatasets (transient AIDataset) [count=[1, None]] – (list) of input AIDataset

  • regionGenerator (transient RegionAlgorithmsAbstract) – if the working area is Pixel, there is no regionGenerator. if the working area is Region, the regionGenerator is an instance of a class specifying the algorithm to use to generate regions and its inputs and parameters

  • save_classifier (bool) – Indicate that the model should be saved on file

Returns:

success (bool) – True if successful, False otherwise