當前位置: 首頁>>代碼示例>>Python>>正文


Python DescriptorMemoryElement.set_vector方法代碼示例

本文整理匯總了Python中smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement.set_vector方法的典型用法代碼示例。如果您正苦於以下問題:Python DescriptorMemoryElement.set_vector方法的具體用法?Python DescriptorMemoryElement.set_vector怎麽用?Python DescriptorMemoryElement.set_vector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement的用法示例。


在下文中一共展示了DescriptorMemoryElement.set_vector方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_normal_conditions

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_normal_conditions(self, mock_dsi_count):
        index = DummySI()
        mock_dsi_count.return_value = 1

        q = DescriptorMemoryElement('q', 0)
        q.set_vector(numpy.random.rand(4))
        index.nn(q)
開發者ID:dhandeo,項目名稱:SMQTK,代碼行數:9,代碼來源:test_NNI_abstract.py

示例2: test_pickle_dump_load

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_pickle_dump_load(self):
        # Wipe current cache
        DescriptorMemoryElement.MEMORY_CACHE = {}

        # Make a couple descriptors
        v1 = numpy.array([1, 2, 3])
        d1 = DescriptorMemoryElement('test', 0)
        d1.set_vector(v1)

        v2 = numpy.array([4, 5, 6])
        d2 = DescriptorMemoryElement('test', 1)
        d2.set_vector(v2)

        ntools.assert_in(('test', 0), DescriptorMemoryElement.MEMORY_CACHE)
        ntools.assert_in(('test', 1), DescriptorMemoryElement.MEMORY_CACHE)

        d1_s = cPickle.dumps(d1)
        d2_s = cPickle.dumps(d2)

        # Wipe cache again
        DescriptorMemoryElement.MEMORY_CACHE = {}
        ntools.assert_not_in(('test', 0), DescriptorMemoryElement.MEMORY_CACHE)
        ntools.assert_not_in(('test', 1), DescriptorMemoryElement.MEMORY_CACHE)

        # Attempt reconstitution
        d1_r = cPickle.loads(d1_s)
        d2_r = cPickle.loads(d2_s)

        numpy.testing.assert_array_equal(v1, d1_r.vector())
        numpy.testing.assert_array_equal(v2, d2_r.vector())

        # Cache should now have those entries back in it
        ntools.assert_in(('test', 0), DescriptorMemoryElement.MEMORY_CACHE)
        ntools.assert_in(('test', 1), DescriptorMemoryElement.MEMORY_CACHE)
開發者ID:dhandeo,項目名稱:SMQTK,代碼行數:36,代碼來源:test_DescriptorMemoryElement.py

示例3: test_known_descriptors_euclidean_ordered

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_known_descriptors_euclidean_ordered(self):
        index = self._make_inst('euclidean')

        # make vectors to return in a known euclidean distance order
        i = 1000
        test_descriptors = []
        for j in xrange(i):
            d = DescriptorMemoryElement('ordered', j)
            d.set_vector(numpy.array([j, j*2], float))
            test_descriptors.append(d)
        random.shuffle(test_descriptors)
        index.build_index(test_descriptors)

        # Since descriptors were build in increasing distance from (0,0),
        # returned descriptors for a query of [0,0] should be in index order.
        q = DescriptorMemoryElement('query', i)
        q.set_vector(numpy.array([0, 0], float))
        # top result should have UUID == 0 (nearest to query)
        r, dists = index.nn(q, 5)
        ntools.assert_equal(r[0].uuid(), 0)
        ntools.assert_equal(r[1].uuid(), 1)
        ntools.assert_equal(r[2].uuid(), 2)
        ntools.assert_equal(r[3].uuid(), 3)
        ntools.assert_equal(r[4].uuid(), 4)
        # global search should be in complete order
        r, dists = index.nn(q, i)
        for j, d, dist in zip(range(i), r, dists):
            ntools.assert_equal(d.uuid(), j)
開發者ID:msarahan,項目名稱:SMQTK,代碼行數:30,代碼來源:test_NNI_itq.py

示例4: test_get_hash

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_get_hash(self):
        fit_descriptors = []
        for i in range(5):
            d = DescriptorMemoryElement(six.b('test'), i)
            d.set_vector([-2. + i, -2. + i])
            fit_descriptors.append(d)

        # The following "rotation" matrix should cause any 2-feature descriptor
        # to the right of the line ``y = -x`` to be True, and to the left as
        # False. If on the line, should be True.
        itq = ItqFunctor(bit_length=1, random_seed=0)
        itq.mean_vec = numpy.array([0., 0.])
        itq.rotation = numpy.array([[1. / sqrt(2)],
                                    [1. / sqrt(2)]])

        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([1, 1])), [True])
        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([-1, -1])), [False])

        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([-1, 1])), [True])
        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([-1.001, 1])), [False])
        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([-1, 1.001])), [True])

        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([1, -1])), [True])
        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([1, -1.001])), [False])
        numpy.testing.assert_array_equal(
            itq.get_hash(numpy.array([1.001, -1])), [True])
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:35,代碼來源:test_itq.py

示例5: test_build_index

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
        def test_build_index(self):
            # Empty memory data elements for storage
            empty_data = 'base64://'
            f = FlannNearestNeighborsIndex(empty_data, empty_data, empty_data)
            # Internal elements should initialize have zero-length byte values
            self.assertEqual(len(f._index_elem.get_bytes()), 0)
            self.assertEqual(len(f._index_param_elem.get_bytes()), 0)
            self.assertEqual(len(f._descr_cache_elem.get_bytes()), 0)

            # Make unit vectors, one for each feature
            dim = 8
            test_descriptors = []
            for i in range(dim):
                v = numpy.zeros(dim, float)
                v[i] = 1.
                d = DescriptorMemoryElement('unit', i)
                d.set_vector(v)
                test_descriptors.append(d)

            f.build_index(test_descriptors)

            # Internal elements should not have non-zero byte values.
            self.assertGreater(len(f._index_elem.get_bytes()), 0)
            self.assertGreater(len(f._index_param_elem.get_bytes()), 0)
            self.assertGreater(len(f._descr_cache_elem.get_bytes()), 0)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:27,代碼來源:test_NNI_FLANN.py

示例6: _known_ordered_euclidean

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def _known_ordered_euclidean(self, hash_ftor, hash_idx,
                                 ftor_train_hook=lambda d: None):
        # make vectors to return in a known euclidean distance order
        i = 1000
        test_descriptors = []
        for j in range(i):
            d = DescriptorMemoryElement('ordered', j)
            d.set_vector(np.array([j, j*2], float))
            test_descriptors.append(d)
        random.shuffle(test_descriptors)

        ftor_train_hook(test_descriptors)

        di = MemoryDescriptorIndex()
        kvstore = MemoryKeyValueStore()
        index = LSHNearestNeighborIndex(hash_ftor, di, kvstore,
                                        hash_index=hash_idx,
                                        distance_method='euclidean')
        index.build_index(test_descriptors)

        # Since descriptors were built in increasing distance from (0,0),
        # returned descriptors for a query of [0,0] should be in index order.
        q = DescriptorMemoryElement('query', i)
        q.set_vector(np.array([0, 0], float))
        # top result should have UUID == 0 (nearest to query)
        r, dists = index.nn(q, 5)
        self.assertEqual(r[0].uuid(), 0)
        self.assertEqual(r[1].uuid(), 1)
        self.assertEqual(r[2].uuid(), 2)
        self.assertEqual(r[3].uuid(), 3)
        self.assertEqual(r[4].uuid(), 4)
        # global search should be in complete order
        r, dists = index.nn(q, i)
        for j, d, dist in zip(range(i), r, dists):
            self.assertEqual(d.uuid(), j)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:37,代碼來源:test_NNI_lsh.py

示例7: test_nn_known_descriptors_euclidean_unit

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
        def test_nn_known_descriptors_euclidean_unit(self):
            dim = 5

            ###
            # Unit vectors -- Equal distance
            #
            index = self._make_inst()
            test_descriptors = []
            for i in range(dim):
                v = np.zeros(dim, float)
                v[i] = 1.
                d = DescriptorMemoryElement('unit', i)
                d.set_vector(v)
                test_descriptors.append(d)
            index.build_index(test_descriptors)
            # query descriptor -- zero vector
            # -> all modeled descriptors should be equally distant (unit
            # corners)
            q = DescriptorMemoryElement('query', 0)
            q.set_vector(np.zeros(dim, float))
            r, dists = index.nn(q, n=dim)
            self.assertEqual(len(dists), dim)
            # All dists should be 1.0, r order doesn't matter
            for d in dists:
                self.assertEqual(d, 1.)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:27,代碼來源:test_NNI_FAISS.py

示例8: test_known_descriptors_hik_unit

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
        def test_known_descriptors_hik_unit(self):
            dim = 5

            ###
            # Unit vectors - Equal distance
            #
            index = self._make_inst('hik')
            test_descriptors = []
            for i in xrange(dim):
                v = numpy.zeros(dim, float)
                v[i] = 1.
                d = DescriptorMemoryElement('unit', i)
                d.set_vector(v)
                test_descriptors.append(d)
            index.build_index(test_descriptors)
            # query with zero vector
            # -> all modeled descriptors have no intersection, dists should be 1.0,
            #    or maximum distance by histogram intersection
            q = DescriptorMemoryElement('query', 0)
            q.set_vector(numpy.zeros(dim, float))
            r, dists = index.nn(q, dim)
            # All dists should be 1.0, r order doesn't matter
            for d in dists:
                ntools.assert_equal(d, 1.)

            # query with index element
            q = test_descriptors[3]
            r, dists = index.nn(q, 1)
            ntools.assert_equal(r[0], q)
            ntools.assert_equal(dists[0], 0.)

            r, dists = index.nn(q, dim)
            ntools.assert_equal(r[0], q)
            ntools.assert_equal(dists[0], 0.)
開發者ID:mrG7,項目名稱:SMQTK,代碼行數:36,代碼來源:test_NNI_FLANN.py

示例9: test_fit_short_descriptors_for_bit_length

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_fit_short_descriptors_for_bit_length(self):
        # Should error when input descriptors have fewer dimensions than set bit
        # length for output hash codes (limitation of PCA method currently
        # used).
        fit_descriptors = []
        for i in range(3):
            d = DescriptorMemoryElement(six.b('test'), i)
            d.set_vector([-1+i, -1+i])
            fit_descriptors.append(d)

        itq = ItqFunctor(bit_length=8)
        self.assertRaisesRegexp(
            ValueError,
            "Input descriptors have fewer features than requested bit encoding",
            itq.fit, fit_descriptors
        )
        self.assertIsNone(itq.mean_vec)
        self.assertIsNone(itq.rotation)

        # Should behave the same when input is an iterable
        self.assertRaisesRegexp(
            ValueError,
            "Input descriptors have fewer features than requested bit encoding",
            itq.fit, iter(fit_descriptors)
        )
        self.assertIsNone(itq.mean_vec)
        self.assertIsNone(itq.rotation)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:29,代碼來源:test_itq.py

示例10: test_fit_with_cache

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_fit_with_cache(self):
        fit_descriptors = []
        for i in range(5):
            d = DescriptorMemoryElement(six.b('test'), i)
            d.set_vector([-2. + i, -2. + i])
            fit_descriptors.append(d)

        itq = ItqFunctor(DataMemoryElement(), DataMemoryElement(),
                         bit_length=1, random_seed=0)
        itq.fit(fit_descriptors)

        # TODO: Explanation as to why this is the expected result.
        numpy.testing.assert_array_almost_equal(itq.mean_vec, [0, 0])
        numpy.testing.assert_array_almost_equal(itq.rotation, [[1 / sqrt(2)],
                                                               [1 / sqrt(2)]])
        self.assertIsNotNone(itq.mean_vec_cache_elem)
        numpy.testing.assert_array_almost_equal(
            numpy.load(BytesIO(itq.mean_vec_cache_elem.get_bytes())),
            [0, 0]
        )

        self.assertIsNotNone(itq.rotation_cache_elem)
        numpy.testing.assert_array_almost_equal(
            numpy.load(BytesIO(itq.rotation_cache_elem.get_bytes())),
            [[1 / sqrt(2)],
             [1 / sqrt(2)]]
        )
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:29,代碼來源:test_itq.py

示例11: test_output_immutability

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
 def test_output_immutability(self):
     # make sure that data stored is not susceptible to modifications after
     # extraction
     v = numpy.ones(16)
     d = DescriptorMemoryElement('test', 0)
     ntools.assert_false(d.has_vector())
     d.set_vector(v)
     r = d.vector()
     r[:] = 0
     ntools.assert_equal(r.sum(), 0)
     ntools.assert_equal(d.vector().sum(), 16)
開發者ID:dhandeo,項目名稱:SMQTK,代碼行數:13,代碼來源:test_DescriptorMemoryElement.py

示例12: test_none_set

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_none_set(self):
        d = DescriptorMemoryElement('test', 0)
        self.assertFalse(d.has_vector())

        d.set_vector(numpy.ones(16))
        self.assertTrue(d.has_vector())
        numpy.testing.assert_equal(d.vector(), numpy.ones(16))

        d.set_vector(None)
        self.assertFalse(d.has_vector())
        self.assertIs(d.vector(), None)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:13,代碼來源:test_DescriptorMemoryElement.py

示例13: test_build_index_one

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
 def test_build_index_one(self):
     d = DescriptorMemoryElement('test', 0)
     d.set_vector(numpy.zeros(8, float))
     index = self._make_inst('euclidean')
     index.build_index([d])
     self.assertListEqual(
         index._descr_cache,
         [d]
     )
     self.assertIsNotNone(index._flann)
     self.assertIsInstance(index._flann_build_params, dict)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:13,代碼來源:test_NNI_FLANN.py

示例14: test_none_set

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
    def test_none_set(self):
        d = DescriptorMemoryElement('test', 0)
        ntools.assert_false(d.has_vector())

        d.set_vector(numpy.ones(16))
        ntools.assert_true(d.has_vector())
        numpy.testing.assert_equal(d.vector(), numpy.ones(16))

        d.set_vector(None)
        ntools.assert_false(d.has_vector())
        ntools.assert_is(d.vector(), None)
開發者ID:dhandeo,項目名稱:SMQTK,代碼行數:13,代碼來源:test_DescriptorMemoryElement.py

示例15: test_build_index_read_only

# 需要導入模塊: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 別名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import set_vector [as 別名]
        def test_build_index_read_only(self):
            v = np.zeros(5, float)
            v[0] = 1.
            d = DescriptorMemoryElement('unit', 0)
            d.set_vector(v)
            test_descriptors = [d]

            index = self._make_inst(read_only=True)
            self.assertRaises(
                ReadOnlyError,
                index.build_index, test_descriptors
            )
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:14,代碼來源:test_NNI_FAISS.py


注:本文中的smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement.set_vector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。