Harness API¶
Test And Evaluation Harness¶
Source code: sail_on_client/harness/test_and_evaluation_harness.py
Abstract harness for T&E.
- class sail_on_client.harness.test_and_evaluation_harness.TestAndEvaluationHarness[source]¶
Abstract interface for test and evaluation harness.
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- abstract dataset_request(test_id, round_id, session_id)[source]¶
Request data for evaluation.
- Parameters
- Return type
- Returns
Filename of a file containing a list of image files (including full path for each)
- abstract evaluate(test_id, round_id, session_id, baseline_session_id=None)[source]¶
Get results for test(s).
- Parameters
- Return type
- Returns
Path to a file with the results
- classmethod from_config(config_dict, merge_default=True)¶
Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
This base method is adequate without modification when a class’s constructor argument types are JSON-compliant. If one or more are not, however, this method then needs to be overridden in order to convert from a JSON-compliant stand-in into the more complex object the constructor requires. It is recommended that when complex types are used they also inherit from the
Configurable
in order to hopefully make easier the conversion to and from JSON-compliant stand-ins.When this method does need to be overridden, this usually looks like the following pattern:
D = TypeVar("D", bound="MyClass") class MyClass (Configurable): @classmethod def from_config( cls: Type[D], config_dict: Dict, merge_default: bool = True ) -> D: # Perform a shallow copy of the input ``config_dict`` which # is important to maintain idempotency. config_dict = dict(config_dict) # Optionally guarantee default values are present in the # configuration dictionary. This is useful when the # configuration dictionary input is partial and the logic # contained here wants to use config parameters that may # have defaults defined in the constructor. if merge_default: config_dict = merge_dict(cls.get_default_config(), config_dict) # # Perform any overriding of `config_dict` values here. # # Create and return an instance using the super method. return super().from_config(config_dict, merge_default=merge_default)
Note on type annotations: When defining a sub-class of configurable and override this class method, we will need to defined a new TypeVar that is bound at the new class type. This is because super requires a type to be given that descends from the implementing type. If C is used as defined in this interface module, which is upper-bounded on the base
Configurable
class, the type analysis will see that we are attempting to invoke super with a type that may not strictly descend from the implementing type (MyClass
in the example above), and cause an error during type analysis.
- 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'}
- abstract get_feedback_request(feedback_ids, feedback_type, test_id, round_id, session_id)[source]¶
Get Labels from the server based provided one or more example ids.
- Parameters
feedback_ids (
list
) – List of media ids for which feedback is requiredfeedback_type (
str
) – Protocols constants with the values: label, detection, characterizationtest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
Path to a file containing containing requested feedback
- 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.
- abstract get_test_metadata(session_id, test_id)[source]¶
Retrieve the metadata json for the specified test.
- classmethod is_usable()[source]¶
Determine if this class with be detected by SMQTK’s plugin.
- Return type
- abstract post_results(result_files, test_id, round_id, session_id)[source]¶
Post client detector predictions for the dataset.
- Parameters
result_files (
Dict
[str
,str
]) – A dictionary of results with protocol constant as key and file path as valuetest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
None
- abstract session_request(test_ids, protocol, domain, novelty_detector_version, hints, detection_threshold)[source]¶
Create a new session to evaluate the detector using an empirical protocol.
- Parameters
test_ids (
list
) – List of tests being evaluated in this sessionprotocol (
str
) – String indicating which protocol is being evaluateddomain (
str
) – String indicating which domain is being evaluatednovelty_detector_version (
str
) – The novelty detector being evaluatedhints (
list
) – Hints used for the sessiondetection_threshold (
float
) – Detection threshold for the session
- Return type
- Returns
A session identifier provided by the server
- abstract terminate_session(session_id)[source]¶
Terminate the session after the evaluation for the protocol is complete.
Returns: None
Local Harness¶
Source code: sail_on_client/harness/local_harness.py
Implementation of T&E Harness for running experiments locally.
- class sail_on_client.harness.local_harness.LocalHarness[source]¶
Harness without any server communication.
- __init__(data_dir, result_dir, gt_dir='', gt_config='')[source]¶
Initialize an object of local harness.
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- dataset_request(test_id, round_id, session_id)[source]¶
Request data for evaluation.
- Parameters
- Return type
- Returns
Filename of a file containing a list of image files (including full path for each)
- evaluate(test_id, round_id, session_id, baseline_session_id=None)[source]¶
Get results for test(s).
- Parameters
- Return type
- Returns
Path to a file with the results
- classmethod from_config(config_dict, merge_default=True)¶
Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
This base method is adequate without modification when a class’s constructor argument types are JSON-compliant. If one or more are not, however, this method then needs to be overridden in order to convert from a JSON-compliant stand-in into the more complex object the constructor requires. It is recommended that when complex types are used they also inherit from the
Configurable
in order to hopefully make easier the conversion to and from JSON-compliant stand-ins.When this method does need to be overridden, this usually looks like the following pattern:
D = TypeVar("D", bound="MyClass") class MyClass (Configurable): @classmethod def from_config( cls: Type[D], config_dict: Dict, merge_default: bool = True ) -> D: # Perform a shallow copy of the input ``config_dict`` which # is important to maintain idempotency. config_dict = dict(config_dict) # Optionally guarantee default values are present in the # configuration dictionary. This is useful when the # configuration dictionary input is partial and the logic # contained here wants to use config parameters that may # have defaults defined in the constructor. if merge_default: config_dict = merge_dict(cls.get_default_config(), config_dict) # # Perform any overriding of `config_dict` values here. # # Create and return an instance using the super method. return super().from_config(config_dict, merge_default=merge_default)
Note on type annotations: When defining a sub-class of configurable and override this class method, we will need to defined a new TypeVar that is bound at the new class type. This is because super requires a type to be given that descends from the implementing type. If C is used as defined in this interface module, which is upper-bounded on the base
Configurable
class, the type analysis will see that we are attempting to invoke super with a type that may not strictly descend from the implementing type (MyClass
in the example above), and cause an error during type analysis.
- 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'}
- get_feedback_request(feedback_ids, feedback_type, test_id, round_id, session_id)[source]¶
Get Labels from the server based provided one or more example ids.
- Parameters
feedback_ids (
list
) – List of media ids for which feedback is requiredfeedback_type (
str
) – Protocols constants with the values: label, detection, characterizationtest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
Path to a file containing containing requested feedback
- 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 with be detected by SMQTK’s plugin.
- Return type
- post_results(result_files, test_id, round_id, session_id)[source]¶
Post client detector predictions for the dataset.
- Parameters
result_files (
Dict
[str
,str
]) – A dictionary of results with protocol constant as key and file path as valuetest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
None
- session_request(test_ids, protocol, domain, novelty_detector_version, hints, detection_threshold)[source]¶
Create a new session to evaluate the detector using an empirical protocol.
- Parameters
test_ids (
list
) – List of tests being evaluated in this sessionprotocol (
str
) – String indicating which protocol is being evaluateddomain (
str
) – String indicating which domain is being evaluatednovelty_detector_version (
str
) – The novelty detector being evaluatedhints (
list
) – Hints used for the sessiondetection_threshold (
float
) – Detection threshold for the session
- Return type
- Returns
A session identifier provided by the server
- terminate_session(session_id)[source]¶
Terminate the session after the evaluation for the protocol is complete.
Returns: None
PAR Harness¶
Source code: sail_on_client/harness/par_harness.py
Implementation of T&E Harness for PAR Server.
- class sail_on_client.harness.par_harness.ParHarness[source]¶
Harness for PAR server.
- static __new__(cls, *args, **kwargs)¶
- Return type
~P
- Parameters
cls (Type[smqtk_core.plugin.P]) –
args (Any) –
kwargs (Any) –
- dataset_request(test_id, round_id, session_id)[source]¶
Request data for evaluation.
- Parameters
- Return type
- Returns
Filename of a file containing a list of image files (including full path for each)
- classmethod from_config(config_dict, merge_default=True)¶
Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
This base method is adequate without modification when a class’s constructor argument types are JSON-compliant. If one or more are not, however, this method then needs to be overridden in order to convert from a JSON-compliant stand-in into the more complex object the constructor requires. It is recommended that when complex types are used they also inherit from the
Configurable
in order to hopefully make easier the conversion to and from JSON-compliant stand-ins.When this method does need to be overridden, this usually looks like the following pattern:
D = TypeVar("D", bound="MyClass") class MyClass (Configurable): @classmethod def from_config( cls: Type[D], config_dict: Dict, merge_default: bool = True ) -> D: # Perform a shallow copy of the input ``config_dict`` which # is important to maintain idempotency. config_dict = dict(config_dict) # Optionally guarantee default values are present in the # configuration dictionary. This is useful when the # configuration dictionary input is partial and the logic # contained here wants to use config parameters that may # have defaults defined in the constructor. if merge_default: config_dict = merge_dict(cls.get_default_config(), config_dict) # # Perform any overriding of `config_dict` values here. # # Create and return an instance using the super method. return super().from_config(config_dict, merge_default=merge_default)
Note on type annotations: When defining a sub-class of configurable and override this class method, we will need to defined a new TypeVar that is bound at the new class type. This is because super requires a type to be given that descends from the implementing type. If C is used as defined in this interface module, which is upper-bounded on the base
Configurable
class, the type analysis will see that we are attempting to invoke super with a type that may not strictly descend from the implementing type (MyClass
in the example above), and cause an error during type analysis.
- 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'}
- get_feedback_request(feedback_ids, feedback_type, test_id, round_id, session_id)[source]¶
Get Labels from the server based provided one or more example ids.
- Parameters
feedback_ids (
list
) – List of media ids for which feedback is requiredfeedback_type (
str
) – Protocols constants with the values: label, detection, characterizationtest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
Path to a file containing containing requested feedback
- 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 with be detected by SMQTK’s plugin.
- Return type
- post_results(result_files, test_id, round_id, session_id)[source]¶
Post client detector predictions for the dataset.
- Parameters
result_files (
Dict
[str
,str
]) – A dictionary of results with protocol constant as key and file path as valuetest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
None
- session_request(test_ids, protocol, domain, novelty_detector_version, hints, detection_threshold)[source]¶
Create a new session to evaluate the detector using an empirical protocol.
- Parameters
test_ids (
list
) – List of tests being evaluated in this sessionprotocol (
str
) – String indicating which protocol is being evaluateddomain (
str
) – String indicating which domain is being evaluatednovelty_detector_version (
str
) – The novelty detector being evaluatedhints (
list
) – Hints used for the sessiondetection_threshold (
float
) – Detection threshold for the session
- Return type
- Returns
A session identifier provided by the server
- terminate_session(session_id)[source]¶
Terminate the session after the evaluation for the protocol is complete.
Returns: None
File Provider¶
Source code: sail_on_client/harness/file_provider.py
A provider class for evaluating with files.
- class sail_on_client.harness.file_provider.FileProvider[source]¶
File-based service provider.
- get_feedback(feedback_ids, feedback_type, session_id, test_id)[source]¶
Get feedback of the specified type.
- Parameters
- Return type
BytesIO
- Returns
An instance of BytesIO with feedback
- get_test_metadata(session_id, test_id, api_call=True, in_process_only=True)[source]¶
Get test metadata.
- Parameters
- Return type
- Returns
Metadata associated with the test as a dictionary
- new_session(test_ids, protocol, domain, novelty_detector_version, hints, detection_threshold)[source]¶
Create a session.
- post_results(session_id, test_id, round_id, result_files)[source]¶
Post results.
- Parameters
result_files (
Dict
[str
,str
]) – A dictionary of results with protocol constant as key and file path as valuetest_id (
str
) – The id of the test currently being evaluatedround_id (
int
) – The sequential number of the round being evaluatedsession_id (
str
) – The id provided by a server denoting a session
- Return type
- Returns
None
File Provider Utility Methods¶
Source code: sail_on_client/harness/file_provider_fn.py
Set of functions used by file provider.
- sail_on_client.harness.file_provider_fn.get_characterization_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Calculate the proper feedback for characterization type feedback.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_classification_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Calculate the proper feedback for classification type feedback.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_classificaton_score_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Calculate feedback on the accuracy of classification.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_cluster_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Calculate the proper feedback for cluster type feedback.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_encoding(domain)[source]¶
Get encoding based on the domain.
- sail_on_client.harness.file_provider_fn.get_kinetics_labels_var_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Get feedback for video activity recognition.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_levenshtein_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Calculate the proper feedback for levenshtein type feedback.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.get_session_info(folder, session_id, in_process_only=True)[source]¶
Retrieve session info.
- sail_on_client.harness.file_provider_fn.get_session_test_info(folder, session_id, test_id)[source]¶
Retrieve session info for a test.
- sail_on_client.harness.file_provider_fn.get_single_gt_feedback(gt_file, result_files, feedback_ids, metadata)[source]¶
Get feedback that specifies if a sample if correct or incorrect.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.log_session(folder, session_id, activity, test_id=None, round_id=None, content=None, content_loc='round', return_structure=False)[source]¶
Create a log files of all session activity.
- Parameters
- Return type
Optional[Dict]
- Returns
Updated log if return_structure is set to True
- sail_on_client.harness.file_provider_fn.psuedo_label_feedback(gt_file, feedback_ids, feedback_type, metadata, folder, session_id)[source]¶
Get psuedo label feedback for requested ids.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.read_feedback_file(csv_reader, feedback_ids, metadata, check_constrained=True)[source]¶
Get feedback from feedback file for the specified ids in the last submitted round.
- Parameters
- Return type
- Returns
Dictionary containing feedback with feedback_ids as keys
- sail_on_client.harness.file_provider_fn.read_gt_csv_file(file_location)[source]¶
Read the ground truth csv file.