def test_configuration(self):
        cfg = IndexLabelClassifier.get_default_config()
        self.assertEqual(cfg, {'index_to_label_uri': None})

        cfg['index_to_label_uri'] = self.FILEPATH_TEST_LABELS
        c = IndexLabelClassifier.from_config(cfg)
        self.assertEqual(c.get_config(), cfg)
    def test_classify(self):
        c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
        m_expected = {
            six.b('label_1'): 1,
            six.b('label_2'): 2,
            six.b('negative'): 3,
            six.b('label_3'): 4,
            six.b('Kitware'): 5,
            six.b('label_4'): 6,
        }

        d = DescriptorMemoryElement('test', 0)
        d.set_vector([1, 2, 3, 4, 5, 6])

        m = c._classify(d)
        self.assertEqual(m, m_expected)
示例#3
0
 def test_configurable(self):
     c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
     for inst in configuration_test_helper(c):
         assert inst.index_to_label_uri == self.FILEPATH_TEST_LABELS
示例#4
0
 def test_is_usable(self):
     # Should always be available
     self.assertTrue(IndexLabelClassifier.is_usable())
 def test_get_labels(self):
     c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
     self.assertEqual(c.get_labels(), self.EXPECTED_LABEL_VEC)
 def test_new(self):
     c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
     self.assertEqual(c.label_vector, self.EXPECTED_LABEL_VEC)
示例#7
0
initialize_logging(logging.getLogger('smqtk'), logging.DEBUG)

eval_data_set = DataMemorySet(EVAL_DATASET)
img_prob_descr_index = MemoryDescriptorIndex(OUTPUT_DESCR_PROB_INDEX)

img_prob_gen = CaffeDescriptorGenerator(CAFFE_DEPLOY,
                                        CAFFE_MODEL,
                                        CAFFE_IMG_MEAN,
                                        'prob',
                                        batch_size=1000,
                                        use_gpu=True,
                                        load_truncated_images=True)

img_c_mem_factory = ClassificationElementFactory(MemoryClassificationElement,
                                                 {})
img_prob_classifier = IndexLabelClassifier(CAFFE_LABELS)

eval_data2descr = {}
d_to_proc = set()
for data in eval_data_set:
    if not img_prob_descr_index.has_descriptor(data.uuid()):
        d_to_proc.add(data)
    else:
        eval_data2descr[data] = img_prob_descr_index[data.uuid()]
if d_to_proc:
    eval_data2descr.update(img_prob_gen.compute_descriptor_async(d_to_proc))
    d_to_proc.clear()
assert len(eval_data2descr) == eval_data_set.count()

index_additions = []
for data in d_to_proc:
 def test_get_labels(self):
     c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
     self.assertEqual(c.get_labels(), self.EXPECTED_LABEL_VEC)
 def test_is_usable(self):
     # Should always be available
     self.assertTrue(IndexLabelClassifier.is_usable())
示例#10
0
 def test_is_usable(self):
     # Should always be available
     nose.tools.assert_true(IndexLabelClassifier.is_usable())
示例#11
0
eval_data_set = DataMemorySet(DataFileElement(EVAL_DATASET))
img_prob_descr_set = MemoryDescriptorSet(
    DataFileElement(OUTPUT_DESCR_PROB_SET))

img_prob_gen = CaffeDescriptorGenerator(DataFileElement(CAFFE_DEPLOY),
                                        DataFileElement(CAFFE_MODEL),
                                        DataFileElement(CAFFE_IMG_MEAN),
                                        'prob',
                                        batch_size=1000,
                                        use_gpu=True,
                                        load_truncated_images=True)

img_c_mem_factory = ClassificationElementFactory(MemoryClassificationElement,
                                                 {})
img_prob_classifier = IndexLabelClassifier(CAFFE_LABELS)

eval_data2descr = {}
d_to_proc = set()
for data in eval_data_set:
    if not img_prob_descr_set.has_descriptor(data.uuid()):
        d_to_proc.add(data)
    else:
        eval_data2descr[data] = img_prob_descr_set[data.uuid()]
if d_to_proc:
    eval_data2descr.update(
        zip(d_to_proc, img_prob_gen.generate_elements(d_to_proc)))
    d_to_proc.clear()
assert len(eval_data2descr) == eval_data_set.count()

index_additions = []