本文整理汇总了Python中smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement.uuid方法的典型用法代码示例。如果您正苦于以下问题:Python DescriptorMemoryElement.uuid方法的具体用法?Python DescriptorMemoryElement.uuid怎么用?Python DescriptorMemoryElement.uuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement
的用法示例。
在下文中一共展示了DescriptorMemoryElement.uuid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_known_descriptors_euclidean_ordered
# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import uuid [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)
示例2: _known_ordered_euclidean
# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import uuid [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)
示例3: test_set_state_version_1
# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import uuid [as 别名]
def test_set_state_version_1(self):
# Test support of older state version
expected_type = 'test-type'
expected_uid = 'test-uid'
expected_v = numpy.array([1, 2, 3])
expected_v_b = BytesIO()
# noinspection PyTypeChecker
numpy.save(expected_v_b, expected_v)
expected_v_dump = expected_v_b.getvalue()
e = DescriptorMemoryElement(None, None)
e.__setstate__((expected_type, expected_uid, expected_v_dump))
self.assertEqual(e.type(), expected_type)
self.assertEqual(e.uuid(), expected_uid)
numpy.testing.assert_array_equal(e.vector(), expected_v)
示例4: test_known_descriptors_euclidean_ordered
# 需要导入模块: from smqtk.representation.descriptor_element.local_elements import DescriptorMemoryElement [as 别名]
# 或者: from smqtk.representation.descriptor_element.local_elements.DescriptorMemoryElement import uuid [as 别名]
def test_known_descriptors_euclidean_ordered(self):
index = self._make_inst('euclidean')
# make vectors to return in a known euclidean distance order
i = 10
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', 99)
q.set_vector(numpy.array([0, 0], float))
r, dists = index.nn(q, i)
for j, d, dist in zip(range(i), r, dists):
ntools.assert_equal(d.uuid(), j)