本文整理汇总了Python中smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex.iterkeys方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryDescriptorIndex.iterkeys方法的具体用法?Python MemoryDescriptorIndex.iterkeys怎么用?Python MemoryDescriptorIndex.iterkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex
的用法示例。
在下文中一共展示了MemoryDescriptorIndex.iterkeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iterkeys
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import iterkeys [as 别名]
def test_iterkeys(self):
i = MemoryDescriptorIndex()
descrs = [random_descriptor() for _ in xrange(100)]
i.add_many_descriptors(descrs)
ntools.assert_equal(set(i.iterkeys()),
set(d.uuid() for d in descrs))
示例2: MemoryDescriptorIndex
# 需要导入模块: from smqtk.representation.descriptor_index.memory import MemoryDescriptorIndex [as 别名]
# 或者: from smqtk.representation.descriptor_index.memory.MemoryDescriptorIndex import iterkeys [as 别名]
log.info("Loading plugins")
descriptor_index = MemoryDescriptorIndex(file_cache=DESCRIPTOR_INDEX_FILE_CACHE)
#: :type: smqtk.algorithms.Classifier
classifier = from_plugin_config(classifier_config['plugins']['classifier'],
get_classifier_impls())
c_factory = ClassificationElementFactory(MemoryClassificationElement, {})
#: :type: dict[str, list[str]]
phone2shas = json.load(open(PHONE_SHA1_JSON))
#: :type: dict[str, float]
phone2score = {}
log.info("Classifying phone imagery descriptors")
i = 0
descriptor_index_shas = set(descriptor_index.iterkeys())
for p in phone2shas:
log.info('%s (%d / %d)', p, i + 1, len(phone2shas))
# Not all source "images" have descriptors since some URLs returned
# non-image files. Intersect phone sha's with what was actually
# computed. Warn if this reduces descriptors for classification to zero.
indexed_shas = set(phone2shas[p]) & descriptor_index_shas
if not indexed_shas:
raise RuntimeError(
"Phone number '%s' has no valid images associated "
"with it.\nBefore:\n%s\n\nAfter:\n%s"
% (p, phone2shas[p], indexed_shas))
descriptor_elems = descriptor_index.get_many_descriptors(*indexed_shas)
e2c = classifier.classify_async(descriptor_elems, c_factory,
use_multiprocessing=True, ri=1.)