Protocol API¶
Visual Protocol API¶
Interfaces that are common across OND and CONDDA protocol
Visual Protocol Dataclasses¶
Source code: sail_on_client/protocol/visual_dataclasses.py
Common dataclasses for visual protocols.
- class sail_on_client.protocol.visual_dataclasses.FeatureExtractionParams[source]¶
Class for storing feature extraction parameters associated with an algorithm.
- __init__(dataset, data_root, round_id)¶
Visual Round¶
Source code: sail_on_client/protocol/visual_round.py
Round for visual protocol.
- class sail_on_client.protocol.visual_round.VisualRound[source]¶
Class with common elements for visual protocols.
- __init__(algorithm, data_root, features_dict, harness, logit_dict, redlight_instance, session_id, skip_stages, test_id)[source]¶
Construct VisualRound.
- Parameters
algorithm (
Any
) – An instance of algorithmdata_root (
str
) – Root directory of the datafeatures_dict (
Dict
) – Dictionary with features for the entire datasetharness (~TestAndEvaluationHarnessType) – An instance of the harness used for T&E
logit_dict (
Dict
) – Dictionary with logits for the entire datasetredlight_instance (
str
) – The instance when the world changessession_id (
str
) – Session id associated with the algorithmtest_id (
str
) – Test id associated with the round
- Returns
None
- Return type
- _run_feature_extraction(fe_params, instance_ids)[source]¶
Private helper function for running feature extraction.
- _run_world_change_detection(wcd_params, round_id)[source]¶
Private helper function for detecting that the world has changed.
- Parameters
wcd_params (
WorldChangeDetectionParams
) – An instance of dataclass with parameters for world change detectionround_id (
int
) – Identifier for a round
- Return type
- Returns
None
Visual Test¶
Source code: sail_on_client/protocol/visual_test.py
Test for Visual Protocol.
- class sail_on_client.protocol.visual_test.VisualTest[source]¶
Class representing test in visual protocol.
- __init__(algorithm_attributes, data_root, domain, feature_dir, harness, save_dir, session_id, skip_stages, use_consolidated_features, use_saved_features)[source]¶
Construct visual test.
- Parameters
algorithm_attributes (
Union
[AlgorithmAttributes
,AlgorithmAttributes
]) – An instance of algorithm_attributesdata_root (
str
) – Root directory for the datasetdomain (
str
) – Name of the domain for the testfeature_dir (
str
) – Directory to save featuresharness (~TestAndEvaluationHarnessType) – An Instance of harness used for T&E
save_dir (
str
) – The directory where features are savedsession_id (
str
) – Session identifier for the testskip_stages (
List
[str
]) – List of stages that would be skippeduse_consolidated_features (
bool
) – Flag for using consolidated featuresuse_saved_features (
bool
) – Flag for using saved features
- Returns
None
- Return type
Visual Protocol¶
Source code: sail_on_client/protocol/visual_protocol.py
Visual Protocol.
- class sail_on_client.protocol.visual_protocol.VisualProtocol[source]¶
Protocol for visual tasks.
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- get_config()[source]¶
Get json compliant representation of the protocol.
- Return type
- Returns
Dictionary with json compliant representation of the protocol
- classmethod get_default_config()¶
Generate and return a default configuration dictionary for this class. This will be primarily used for generating what the configuration dictionary would look like for this class without instantiating it.
By default, we observe what this class’s constructor takes as arguments, turning those argument names into configuration dictionary keys. If any of those arguments have defaults, we will add those values into the configuration dictionary appropriately. The dictionary returned should only contain JSON compliant value types.
It is not be guaranteed that the configuration dictionary returned from this method is valid for construction of an instance of this class.
- Returns
Default configuration dictionary for the class.
- Return type
>>> # noinspection PyUnresolvedReferences >>> class SimpleConfig(Configurable): ... def __init__(self, a=1, b='foo'): ... self.a = a ... self.b = b ... def get_config(self): ... return {'a': self.a, 'b': self.b} >>> self = SimpleConfig() >>> config = self.get_default_config() >>> assert config == {'a': 1, 'b': 'foo'}
- classmethod get_impls()¶
Discover and return a set of classes that implement the calling class.
See the various
discover_via_*()
functions in this module for more details on the logic of how implementing classes (aka “plugins”) are discovered.The class-level variables
PLUGIN_ENV_VAR
andPLUGIN_NAMESPACE
may be overridden to change what environment and entry-point extension are looked for, respectively.
- classmethod is_usable()¶
Determine if this class will be detected by SMQTK’s plugin utilities.
- Return type
OND API¶
OND Dataclasses¶
Source code: sail_on_client/protocol/ond_dataclasses.py
Dataclasses for the protocols.
- class sail_on_client.protocol.ond_dataclasses.AlgorithmAttributes[source]¶
Class for storing attributes of algorithm present in the protocol.
- __init__(name, detection_threshold, instance, is_baseline, is_reaction_baseline, package_name, parameters, session_id, test_ids)¶
- merge_detector_params(detector_params, exclude_keys=None)[source]¶
Merge common parameters with algorithm specific parameters with exclusions.
- class sail_on_client.protocol.ond_dataclasses.InitializeParams[source]¶
Class for storing parameters that are used to initialize the algorithm.
- __init__(parameters, session_id, test_id, pre_novelty_batches, feedback_instance)¶
- Parameters
parameters (Dict) –
session_id (str) –
test_id (str) –
pre_novelty_batches (int) –
feedback_instance (Optional[Union[sail_on_client.feedback.image_classification_feedback.ImageClassificationFeedback, sail_on_client.feedback.document_transcription_feedback.DocumentTranscriptionFeedback, sail_on_client.feedback.activity_recognition_feedback.ActivityRecognitionFeedback]]) –
- Return type
- class sail_on_client.protocol.ond_dataclasses.NoveltyAdaptationParams[source]¶
Class for storing parameters associated novelty adaptation with an algorithm.
- class sail_on_client.protocol.ond_dataclasses.NoveltyCharacterizationParams[source]¶
Class for storing parameters associated novelty characterization with an algorithm.
OND Round¶
Source code: sail_on_client/protocol/ond_round.py
Round for OND.
- class sail_on_client.protocol.ond_round.ONDRound[source]¶
Class Representing a round in OND.
- __init__(algorithm, data_root, features_dict, harness, logit_dict, redlight_instance, session_id, skip_stages, test_id)[source]¶
Construct round for OND.
- Parameters
algorithm (
Any
) – An instance of algorithmdata_root (
str
) – Root directory of the datafeatures_dict (
Dict
) – Dictionary with features for the entire datasetharness (~TestAndEvaluationHarnessType) – An instance of the harness used for T&E
logit_dict (
Dict
) – Dictionary with logits for the entire datasetredlight_instance (
str
) – The instance when the world changessession_id (
str
) – Session id associated with the algorithmtest_id (
str
) – Test id associated with the round
- Returns
None
- Return type
- _run_novelty_adaptation(na_params)[source]¶
Private helper function for adaptation.
- Parameters
na_params (
NoveltyAdaptationParams
) – An instance of dataclass with parameters for adaptation- Return type
- Returns
None
- _run_novelty_classification(nc_params, round_id)[source]¶
Private helper function for novelty classification.
- Parameters
nc_params (
NoveltyClassificationParams
) – An instance of dataclass with parameters for novelty classificationround_id (
int
) – Identifier for a round
- Return type
- Returns
None
OND Test¶
Source code: sail_on_client/protocol/ond_test.py
Test for OND.
- class sail_on_client.protocol.ond_test.ONDTest[source]¶
Class Representing OND test.
- __init__(algorithm_attributes, data_root, domain, feedback_type, feature_dir, harness, save_dir, session_id, skip_stages, use_consolidated_features, use_saved_features)[source]¶
Construct test for OND.
- Parameters
algorithm_attributes (
AlgorithmAttributes
) – An instance of algorithm_attributesdata_root (
str
) – Root directory for the datasetdomain (
str
) – Name of the domain for the testfeedback_type (
str
) – Type of feedback used in the testharness (~TestAndEvaluationHarnessType) – An Instance of harness used for T&E
save_dir (
str
) – The directory where features are savedsession_id (
str
) – Session identifier for the testskip_stages (
List
[str
]) – List of stages that would be skippeduse_consolidated_features (
bool
) – Flag for using consolidated featuresuse_saved_features (
bool
) – Flag for using saved featuresfeature_dir (str) –
- Returns
None
- Return type
- _create_feedback_instance(test_id, feedback_max_ids)[source]¶
Private function for creating feedback object.
- Parameters
- Return type
Union
[ActivityRecognitionFeedback
,DocumentTranscriptionFeedback
,ImageClassificationFeedback
]- Returns
An instance of feedback for the domain
OND Protocol¶
Source code: sail_on_client/protocol/ond_protocol.py
OND protocol.
- class sail_on_client.protocol.ond_protocol.ONDProtocol[source]¶
OND protocol.
- __init__(algorithms, dataset_root, domain, harness, save_dir, seed, test_ids, baseline_class='', feature_extraction_only=False, has_baseline=False, has_reaction_baseline=False, hints=None, is_eval_enabled=False, is_eval_roundwise_enabled=False, resume_session=False, resume_session_ids=None, save_attributes=False, saved_attributes=None, save_elementwise=False, save_features=False, feature_dir='', skip_stages=None, use_feedback=False, feedback_type='classification', use_consolidated_features=False, use_saved_attributes=False, use_saved_features=False)[source]¶
Construct OND protocol.
- Parameters
algorithms (
Dict
[str
,ONDAgent
]) – Dictionary of algorithms that are used run based on the protocolbaseline_class (
str
) – Name of the baseline classdataset_root (
str
) – Root directory of the datasetdomain (
str
) – Domain of the problemsave_dir (
str
) – Directory where results are savedseed (
str
) – Seed for the experimentsfeedback_type (
str
) – Type of feedbackfeature_extraction_only (
bool
) – Flag to only run feature extractionhas_baseline (
bool
) – Flag to check if the session has baselinehas_reaction_baseline (
bool
) – Flag to check if the session has reaction baselinehints (
Optional
[List
]) – List of hint provided in the sessionharness (~TestAndEvaluationHarnessType) – A harness for test and evaluation
is_eval_enabled (
bool
) – Flag to check if evaluation is enabled in sessionis_eval_roundwise_enabled (
bool
) – Flag to check if evaluation is enabled for roundsresume_session (
bool
) – Flag to resume sessionresume_session_ids (
Optional
[Dict
]) – Dictionary for resuming sessionssave_attributes (
bool
) – Flag to save attributessaved_attributes (
Optional
[Dict
]) – Dictionary for attributessave_elementwise (
bool
) – Flag to save features elementwisesave_features (
bool
) – Flag to save featuresfeature_dir (
str
) – Directory to save featuresskip_stages (
Optional
[List
]) – List of stages that are skippeduse_feedback (
bool
) – Flag to use feedbackuse_saved_attributes (
bool
) – Flag to use saved attributesuse_saved_features (
bool
) – Flag to use saved featuresuse_consolidated_features (bool) –
- Returns
None
- Return type
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- _evaluate_algorithms(algorithms_attributes, algorithm_scores, save_dir)[source]¶
Evaluate algorithms after all tests have been submitted.
- Parameters
algorithms_attributes (
List
[AlgorithmAttributes
]) – All algorithms present in the configalgorithm_scores (
Dict
) – Scores for round wise evaluationsave_dir (
str
) – Directory where the scores are stored
- Return type
- Returns
None
- create_algorithm_attributes(algorithm_name, algorithm_param, baseline_algorithm_name, has_baseline, has_reaction_baseline, test_ids)[source]¶
Create an instance of algorithm attributes.
- Parameters
algorithm_name (
str
) – Name of the algorithmalgorithm_param (
Dict
) – Parameters for the algorithmbaseline_algorithm_name (
str
) – Name of the baseline algorithmhas_baseline (
bool
) – Flag to check if a baseline is present in the confighas_reaction_baseline (
bool
) – Flag to check if a reaction baseline is present in the config
- Return type
- Returns
An instance of AlgorithmAttributes
- create_algorithm_session(algorithm_attributes, domain, hints, has_a_session, protocol_name)[source]¶
Create/resume session for an algorithm.
- Parameters
- Return type
- Returns
An AlgorithmAttributes object with updated session id or test id
- classmethod from_config(config_dict, merge_default=True)¶
Construct protocol from config.
- classmethod get_default_config()¶
Generate and return a default configuration dictionary for this class. This will be primarily used for generating what the configuration dictionary would look like for this class without instantiating it.
By default, we observe what this class’s constructor takes as arguments, turning those argument names into configuration dictionary keys. If any of those arguments have defaults, we will add those values into the configuration dictionary appropriately. The dictionary returned should only contain JSON compliant value types.
It is not be guaranteed that the configuration dictionary returned from this method is valid for construction of an instance of this class.
- Returns
Default configuration dictionary for the class.
- Return type
>>> # noinspection PyUnresolvedReferences >>> class SimpleConfig(Configurable): ... def __init__(self, a=1, b='foo'): ... self.a = a ... self.b = b ... def get_config(self): ... return {'a': self.a, 'b': self.b} >>> self = SimpleConfig() >>> config = self.get_default_config() >>> assert config == {'a': 1, 'b': 'foo'}
- classmethod get_impls()¶
Discover and return a set of classes that implement the calling class.
See the various
discover_via_*()
functions in this module for more details on the logic of how implementing classes (aka “plugins”) are discovered.The class-level variables
PLUGIN_ENV_VAR
andPLUGIN_NAMESPACE
may be overridden to change what environment and entry-point extension are looked for, respectively.
- classmethod is_usable()¶
Determine if this class will be detected by SMQTK’s plugin utilities.
- Return type
- update_skip_stages(skip_stages, is_eval_enabled, is_eval_roundwise_enabled, use_feedback, save_features, feature_extraction_only)[source]¶
Update skip stages based on the boolean values in config.
- Parameters
skip_stages (
List
[str
]) – List of skip stages specified in the configis_eval_enabled (
bool
) – Flag to enable evaluationis_eval_roundwise_enabled (
bool
) – Flag to enable evaluation in every rounduse_feedback (
bool
) – Flag to enable using feedbacksave_features (
bool
) – Flag to enable saving featuresfeature_extraction_only (
bool
) – Flag to only run feature extraction
- Return type
- Returns
Update list of skip stages
CONDDA API¶
CONDDA Dataclasses¶
Source code: sail_on_client/protocol/condda_dataclasses.py
Dataclasses for CONDDA.
- class sail_on_client.protocol.condda_dataclasses.AlgorithmAttributes[source]¶
Class for storing attributes of algorithm present in the protocol.
- __init__(name, detection_threshold, instance, package_name, parameters, session_id, test_ids)¶
- merge_detector_params(detector_params, exclude_keys=None)[source]¶
Merge common parameters with algorithm specific parameters with exclusions.
- class sail_on_client.protocol.condda_dataclasses.InitializeParams[source]¶
Class for storing parameters that are used to initialize the algorithm.
- __init__(parameters, session_id, test_id)¶
CONDDA Round¶
Source code: sail_on_client/protocol/condda_round.py
Round for CONDDA.
- class sail_on_client.protocol.condda_round.CONDDARound[source]¶
Class Representing a round for CONDDA.
- __init__(algorithm, data_root, features_dict, harness, logit_dict, redlight_instance, session_id, skip_stages, test_id)[source]¶
Construct CONDDARound.
- Parameters
algorithm (
Any
) – An instance of algorithmdata_root (
str
) – Root directory of the datafeatures_dict (
Dict
) – Dictionary with features for the entire datasetharness (~TestAndEvaluationHarnessType) – An instance of the harness used for T&E
logit_dict (
Dict
) – Dictionary with logits for the entire datasetredlight_instance (
str
) – The instance when the world changessession_id (
str
) – Session id associated with the algorithmtest_id (
str
) – Test id associated with the round
- Returns
None
- Return type
CONDDA Test¶
Source code: sail_on_client/protocol/condda_test.py
Test for CONDDA.
- class sail_on_client.protocol.condda_test.CONDDATest[source]¶
Class representing CONDDA Test.
- __init__(algorithm_attributes, data_root, domain, feature_dir, harness, save_dir, session_id, skip_stages, use_consolidated_features, use_saved_features)[source]¶
Construct test for CONDDA.
- Parameters
algorithm_attributes (
AlgorithmAttributes
) – An instance of algorithm_attributesdata_root (
str
) – Root directory for the datasetdomain (
str
) – Name of the domain for the testfeature_dir (
str
) – Directory where features are storedharness (~TestAndEvaluationHarnessType) – An Instance of harness used for T&E
save_dir (
str
) – The directory where features are savedsession_id (
str
) – Session identifier for the testskip_stages (
List
[str
]) – List of stages that would be skippeduse_consolidated_features (
bool
) – Flag for using consolidated featuresuse_saved_features (
bool
) – Flag for using saved features
- Returns
None
- Return type
CONDDA Protocol¶
Source code: sail_on_client/protocol/condda_protocol.py
CONDDA protocol.
- class sail_on_client.protocol.condda_protocol.Condda[source]¶
CONDDA protocol.
- __init__(algorithms, dataset_root, domain, harness, save_dir, seed, test_ids, feature_extraction_only=False, hints=None, is_eval_enabled=False, is_eval_roundwise_enabled=False, resume_session=False, resume_session_ids=None, save_attributes=False, saved_attributes=None, save_elementwise=False, save_features=False, feature_dir='', skip_stages=None, use_consolidated_features=False, use_saved_attributes=False, use_saved_features=False)[source]¶
Initialize CONDDA protocol object.
- Parameters
algorithms (
Dict
[str
,CONDDAAgent
]) – Dictionary of algorithms that are used run based on the protocoldataset_root (
str
) – Root directory of the datasetdomain (
str
) – Domain of the problemsave_dir (
str
) – Directory where results are savedseed (
str
) – Seed for the experimentsfeature_extraction_only (
bool
) – Flag to only run feature extractionhints (
Optional
[List
]) – List of hint provided in the sessionharness (~TestAndEvaluationHarnessType) – A harness for test and evaluation
is_eval_enabled (
bool
) – Flag to check if evaluation is enabled in sessionis_eval_roundwise_enabled (
bool
) – Flag to check if evaluation is enabled for roundsresume_session (
bool
) – Flag to resume sessionresume_session_ids (
Optional
[Dict
]) – Dictionary for resuming sessionssave_attributes (
bool
) – Flag to save attributessaved_attributes (
Optional
[Dict
]) – Dictionary for attributessave_elementwise (
bool
) – Flag to save features elementwisesave_features (
bool
) – Flag to save featuresfeature_dir (
str
) – Directory to save featuresskip_stages (
Optional
[List
]) – List of stages that are skippeduse_consolidated_features (
bool
) – Flag to use consolidated featuresuse_saved_attributes (
bool
) – Flag to use saved attributesuse_saved_features (
bool
) – Flag to use saved features
- Returns
None
- Return type
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- create_algorithm_attributes(algorithm_name, algorithm_param, test_ids)[source]¶
Create an instance of algorithm attributes.
- Parameters
algorithm_name (
str
) – Name of the algorithmalgorithm_param (
Dict
) – Parameters for the algorithmbaseline_algorithm_name – Name of the baseline algorithm
has_baseline – Flag to check if a baseline is present in the config
has_reaction_baseline – Flag to check if a reaction baseline is present in the config
- Return type
- Returns
An instance of AlgorithmAttributes
- create_algorithm_session(algorithm_attributes, domain, hints, has_a_session, protocol_name)[source]¶
Create/resume session for an algorithm.
- Parameters
- Return type
- Returns
An AlgorithmAttributes object with updated session id or test id
- classmethod from_config(config_dict, merge_default=True)¶
Construct protocol from config.
- get_config()¶
Get json compliant representation of the protocol.
- Return type
- Returns
Dictionary with json compliant representation of the protocol
- classmethod get_default_config()¶
Generate and return a default configuration dictionary for this class. This will be primarily used for generating what the configuration dictionary would look like for this class without instantiating it.
By default, we observe what this class’s constructor takes as arguments, turning those argument names into configuration dictionary keys. If any of those arguments have defaults, we will add those values into the configuration dictionary appropriately. The dictionary returned should only contain JSON compliant value types.
It is not be guaranteed that the configuration dictionary returned from this method is valid for construction of an instance of this class.
- Returns
Default configuration dictionary for the class.
- Return type
>>> # noinspection PyUnresolvedReferences >>> class SimpleConfig(Configurable): ... def __init__(self, a=1, b='foo'): ... self.a = a ... self.b = b ... def get_config(self): ... return {'a': self.a, 'b': self.b} >>> self = SimpleConfig() >>> config = self.get_default_config() >>> assert config == {'a': 1, 'b': 'foo'}
- classmethod get_impls()¶
Discover and return a set of classes that implement the calling class.
See the various
discover_via_*()
functions in this module for more details on the logic of how implementing classes (aka “plugins”) are discovered.The class-level variables
PLUGIN_ENV_VAR
andPLUGIN_NAMESPACE
may be overridden to change what environment and entry-point extension are looked for, respectively.
- classmethod is_usable()¶
Determine if this class will be detected by SMQTK’s plugin utilities.
- Return type
- update_skip_stages(skip_stages, save_features, feature_extraction_only)[source]¶
Update skip stages based on the boolean values in config.
- Parameters
skip_stages (
List
[str
]) – List of skip stages specified in the configis_eval_enabled – Flag to enable evaluation
is_eval_roundwise_enabled – Flag to enable evaluation in every round
use_feedback – Flag to enable using feedback
save_features (
bool
) – Flag to enable saving featuresfeature_extraction_only (
bool
) – Flag to only run feature extraction
- Return type
- Returns
Update list of skip stages