def test_classify_invalid_descriptor_dimensions(self):
        c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
        d = DescriptorMemoryElement('test', 0)

        # One less
        d.set_vector([1, 2, 3, 4, 5])
        self.assertRaises(RuntimeError, c._classify, d)

        # One more
        d.set_vector([1, 2, 3, 4, 5, 6, 7])
        self.assertRaises(RuntimeError, c._classify, d)
    def test_classify_arrays_invalid_descriptor_dimensions(self):
        c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)

        # One less
        a = numpy.array([1, 2, 3, 4, 5])
        with pytest.raises(RuntimeError):
            list(c._classify_arrays([a]))

        # One more
        a = numpy.array([1, 2, 3, 4, 5, 6, 7])
        with pytest.raises(RuntimeError):
            list(c._classify_arrays([a]))
Beispiel #3
0
    def test_classify_arrays(self):
        c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
        c_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,
        }

        a = numpy.array([1, 2, 3, 4, 5, 6])
        c = list(c._classify_arrays([a]))[0]
        self.assertEqual(c, c_expected)
    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)
Beispiel #5
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_new(self):
     c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS)
     self.assertEqual(c.label_vector, self.EXPECTED_LABEL_VEC)
Beispiel #8
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