def test_from_config_with_content(self, m_get_impls): # Mocking implementation getter to only return the dummy # implementation. m_get_impls.side_effect = lambda: {DummyClassifier} "tests.algorithms.classifier.test_ClassifierAbstract.DummyClassifier" ccol = ClassifierCollection.from_config({ 'a': { 'tests.algorithms.classifier.test_ClassifierAbstract' '.DummyClassifier': {}, 'type': 'tests.algorithms.classifier' '.test_ClassifierAbstract.DummyClassifier' }, 'b': { 'tests.algorithms.classifier.test_ClassifierAbstract' '.DummyClassifier': {}, 'type': 'tests.algorithms.classifier' '.test_ClassifierAbstract.DummyClassifier' }, }) self.assertEqual( # Using sort because return from ``keys()`` has no guarantee on # order. sorted(ccol._label_to_classifier.keys()), ['a', 'b']) self.assertIsInstance(ccol._label_to_classifier['a'], DummyClassifier) self.assertIsInstance(ccol._label_to_classifier['b'], DummyClassifier)
def test_from_config_skip_example_key(self): # If the default example is left in the config, it should be skipped. # The string chosen for the example key should be unlikely to be used # in reality. ccol = ClassifierCollection.from_config({ '__example_label__': 'this should be skipped regardless of content' }) self.assertEqual(ccol._label_to_classifier, {})
def __init__(self, json_config): super(SmqtkClassifierService, self).__init__(json_config) self.enable_classifier_removal = \ bool(json_config[self.CONFIG_ENABLE_CLASSIFIER_REMOVAL]) self.immutable_labels = set(json_config[self.CONFIG_IMMUTABLE_LABELS]) # Convert configuration into SMQTK plugin instances. # - Static classifier configurations. # - Skip the example config key # - Classification element factory # - Descriptor generator # - Descriptor element factory # - from-IQR-state classifier configuration # - There must at least be the default key defined for when no # specific classifier type is specified at state POST. # Classifier collection + factor self.classification_factory = \ ClassificationElementFactory.from_config( json_config[self.CONFIG_CLASSIFICATION_FACTORY] ) #: :type: ClassifierCollection self.classifier_collection = ClassifierCollection.from_config( json_config[self.CONFIG_CLASSIFIER_COLLECTION] ) # Descriptor generator + factory self.descriptor_factory = DescriptorElementFactory.from_config( json_config[self.CONFIG_DESCRIPTOR_FACTORY] ) #: :type: smqtk.algorithms.DescriptorGenerator self.descriptor_gen = from_config_dict( json_config[self.CONFIG_DESCRIPTOR_GENERATOR], smqtk.algorithms.DescriptorGenerator.get_impls() ) # Descriptor set bundled for classification-by-UID. try: self.descriptor_set = from_config_dict( json_config.get(self.CONFIG_DESCRIPTOR_SET, {}), DescriptorSet.get_impls() ) except ValueError: # Default empty set. self.descriptor_set = MemoryDescriptorSet() # Classifier config for uploaded IQR states. self.iqr_state_classifier_config = \ json_config[self.CONFIG_IQR_CLASSIFIER] self.add_routes()
def __init__(self, json_config): super(SmqtkClassifierService, self).__init__(json_config) self.enable_classifier_removal = \ bool(json_config[self.CONFIG_ENABLE_CLASSIFIER_REMOVAL]) self.immutable_labels = set(json_config[self.CONFIG_IMMUTABLE_LABELS]) # Convert configuration into SMQTK plugin instances. # - Static classifier configurations. # - Skip the example config key # - Classification element factory # - Descriptor generator # - Descriptor element factory # - from-IQR-state classifier configuration # - There must at least be the default key defined for when no # specific classifier type is specified at state POST. # Classifier collection + factor self.classification_factory = \ ClassificationElementFactory.from_config( json_config[self.CONFIG_CLASSIFICATION_FACTORY] ) self.classifier_collection = ClassifierCollection.from_config( json_config[self.CONFIG_CLASSIFIER_COLLECTION] ) # Descriptor generator + factory self.descriptor_factory = DescriptorElementFactory.from_config( json_config[self.CONFIG_DESCRIPTOR_FACTORY] ) #: :type: smqtk.algorithms.DescriptorGenerator self.descriptor_gen = smqtk.utils.plugin.from_plugin_config( json_config[self.CONFIG_DESCRIPTOR_GENERATOR], smqtk.algorithms.get_descriptor_generator_impls() ) # Classifier config for uploaded IQR states. self.iqr_state_classifier_config = \ json_config[self.CONFIG_IQR_CLASSIFIER] self.add_routes()
def test_from_config_empty(self): ccol = ClassifierCollection.from_config({}) self.assertEqual(ccol._label_to_classifier, {})