本文整理汇总了Python中smqtk.representation.DescriptorElementFactory类的典型用法代码示例。如果您正苦于以下问题:Python DescriptorElementFactory类的具体用法?Python DescriptorElementFactory怎么用?Python DescriptorElementFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DescriptorElementFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_configuration
def test_configuration(self):
c = DescriptorElementFactory.get_default_config()
self.assertIsNone(c['type'])
self.assertIn('DescriptorMemoryElement', c)
c['type'] = 'DescriptorMemoryElement'
factory = DescriptorElementFactory.from_config(c)
self.assertEqual(factory._d_type.__name__,
DescriptorMemoryElement.__name__)
self.assertEqual(factory._d_type_config, {})
d = factory.new_descriptor('test', 'foo')
self.assertEqual(d.type(), 'test')
self.assertEqual(d.uuid(), 'foo')
开发者ID:Kitware,项目名称:SMQTK,代码行数:14,代码来源:test_DescriptorElementFactory.py
示例2: test_configuration
def test_configuration(self):
c = DescriptorElementFactory.get_default_config()
ntools.assert_is_none(c['type'])
ntools.assert_in('DescriptorMemoryElement', c)
c['type'] = 'DescriptorMemoryElement'
factory = DescriptorElementFactory.from_config(c)
ntools.assert_equal(factory._d_type.__name__,
DescriptorMemoryElement.__name__)
ntools.assert_equal(factory._d_type_config, {})
d = factory.new_descriptor('test', 'foo')
ntools.assert_equal(d.type(), 'test')
ntools.assert_equal(d.uuid(), 'foo')
DescriptorMemoryElement.MEMORY_CACHE = {}
开发者ID:dhandeo,项目名称:SMQTK,代码行数:15,代码来源:test_DescriptorElementFactory.py
示例3: from_config
def from_config(cls, config_dict, type_str, uuid, merge_default=True):
# convert factory configuration
config_dict["wrapped_element_factory"] = DescriptorElementFactory.from_config(
config_dict["wrapped_element_factory"]
)
return super(CachingDescriptorElement, cls).from_config(config_dict, type_str, uuid, merge_default)
开发者ID:liangkai,项目名称:SMQTK,代码行数:7,代码来源:cached_element_wrapper.py
示例4: get_default_config
def get_default_config(cls):
d = super(IqrSearch, cls).get_default_config()
# Remove parent_app slot for later explicit specification.
del d['parent_app']
# fill in plugin configs
d['data_set'] = plugin.make_config(get_data_set_impls())
d['descr_generator'] = \
plugin.make_config(get_descriptor_generator_impls())
d['nn_index'] = plugin.make_config(get_nn_index_impls())
ri_config = plugin.make_config(get_relevancy_index_impls())
if d['rel_index_config']:
ri_config.update(d['rel_index_config'])
d['rel_index_config'] = ri_config
df_config = DescriptorElementFactory.get_default_config()
if d['descriptor_factory']:
df_config.update(d['descriptor_factory'].get_config())
d['descriptor_factory'] = df_config
return d
开发者ID:dhandeo,项目名称:SMQTK,代码行数:25,代码来源:iqr_search.py
示例5: from_config
def from_config(cls, config, parent_app):
"""
Instantiate a new instance of this class given the configuration
JSON-compliant dictionary encapsulating initialization arguments.
:param config: JSON compliant dictionary encapsulating
a configuration.
:type config: dict
:param parent_app: Parent containing flask app instance
:type parent_app: smqtk.web.search_app.app.search_app
:return: Constructed instance from the provided config.
:rtype: IqrSearch
"""
merged = cls.get_default_config()
merged.update(config)
# construct nested objects via configurations
merged['data_set'] = \
plugin.from_plugin_config(merged['data_set'],
get_data_set_impls())
merged['descr_generator'] = \
plugin.from_plugin_config(merged['descr_generator'],
get_descriptor_generator_impls())
merged['nn_index'] = \
plugin.from_plugin_config(merged['nn_index'],
get_nn_index_impls())
merged['descriptor_factory'] = \
DescriptorElementFactory.from_config(merged['descriptor_factory'])
return cls(parent_app, **merged)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:34,代码来源:iqr_search.py
示例6: get_default_config
def get_default_config(cls):
c = super(SmqtkClassifierService, cls).get_default_config()
c[cls.CONFIG_ENABLE_CLASSIFIER_REMOVAL] = False
# Static classifier configurations
c[cls.CONFIG_CLASSIFIER_COLLECTION] = \
ClassifierCollection.get_default_config()
# Classification element factory for new classification results.
c[cls.CONFIG_CLASSIFICATION_FACTORY] = \
ClassificationElementFactory.get_default_config()
# Descriptor generator for new content
c[cls.CONFIG_DESCRIPTOR_GENERATOR] = smqtk.utils.plugin.make_config(
get_descriptor_generator_impls()
)
# Descriptor factory for new content descriptors
c[cls.CONFIG_DESCRIPTOR_FACTORY] = \
DescriptorElementFactory.get_default_config()
# from-IQR-state *supervised* classifier configuration
c[cls.CONFIG_IQR_CLASSIFIER] = smqtk.utils.plugin.make_config(
get_classifier_impls(
sub_interface=SupervisedClassifier
)
)
c[cls.CONFIG_IMMUTABLE_LABELS] = []
return c
开发者ID:Kitware,项目名称:SMQTK,代码行数:27,代码来源:classifier_server.py
示例7: test_no_params
def test_no_params(self, dei_init):
# So we don't break python
dei_init.return_value = None
test_params = {}
factory = DescriptorElementFactory(DummyElementImpl, test_params)
expected_type = 'type'
expected_uuid = 'uuid'
# Should construct a new DEI instance under they hood somewhere
r = factory.new_descriptor(expected_type, expected_uuid)
ntools.assert_true(dei_init.called)
dei_init.assert_called_once_with(expected_type, expected_uuid)
ntools.assert_is_instance(r, DummyElementImpl)
开发者ID:kod3r,项目名称:SMQTK,代码行数:16,代码来源:test_DescriptorElementFactory.py
示例8: default_config
def default_config():
return {
"descriptor_generator":
plugin.make_config(get_descriptor_generator_impls()),
"descriptor_factory": DescriptorElementFactory.get_default_config(),
"descriptor_index":
plugin.make_config(get_descriptor_index_impls())
}
开发者ID:dhandeo,项目名称:SMQTK,代码行数:8,代码来源:compute_many_descriptors.py
示例9: test_no_params
def test_no_params(self):
test_params = {}
factory = DescriptorElementFactory(DummyElementImpl, test_params)
expected_type = 'type'
expected_uuid = 'uuid'
expected_args = ()
expected_kwds = {}
# Should construct a new DEI instance under they hood somewhere
r = factory.new_descriptor(expected_type, expected_uuid)
ntools.assert_is_instance(r, DummyElementImpl)
ntools.assert_equal(r._type_label, expected_type)
ntools.assert_equal(r._uuid, expected_uuid)
ntools.assert_equal(r.args, expected_args)
ntools.assert_equal(r.kwds, expected_kwds)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:18,代码来源:test_DescriptorElementFactory.py
示例10: test_with_params
def test_with_params(self, dei_init):
# So we don't break python
dei_init.return_value = None
v = numpy.random.randint(0, 10, 10)
test_params = {
'p1': 'some dir',
'vec': v
}
factory = DescriptorElementFactory(DummyElementImpl, test_params)
ex_type = 'type'
ex_uuid = 'uuid'
# Should construct a new DEI instance under they hood somewhere
r = factory.new_descriptor(ex_type, ex_uuid)
ntools.assert_true(dei_init.called)
dei_init.assert_called_once_with(ex_type, ex_uuid, p1='some dir', vec=v)
ntools.assert_is_instance(r, DummyElementImpl)
开发者ID:kod3r,项目名称:SMQTK,代码行数:20,代码来源:test_DescriptorElementFactory.py
示例11: get_default_config
def get_default_config():
return {
"descriptor_factory":
DescriptorElementFactory.get_default_config(),
"descriptor_generator":
plugin.make_config(get_descriptor_generator_impls()),
"classification_factory":
ClassificationElementFactory.get_default_config(),
"classifier":
plugin.make_config(get_classifier_impls()),
}
开发者ID:Kitware,项目名称:SMQTK,代码行数:11,代码来源:classifyFiles.py
示例12: test_with_params
def test_with_params(self):
v = numpy.random.randint(0, 10, 10)
test_params = {
'p1': 'some dir',
'vec': v
}
factory = DescriptorElementFactory(DummyElementImpl, test_params)
ex_type = 'type'
ex_uuid = 'uuid'
ex_args = ()
ex_kwds = test_params
# Should construct a new DEI instance under they hood somewhere
r = factory.new_descriptor(ex_type, ex_uuid)
ntools.assert_is_instance(r, DummyElementImpl)
ntools.assert_equal(r._type_label, ex_type)
ntools.assert_equal(r._uuid, ex_uuid)
ntools.assert_equal(r.args, ex_args)
ntools.assert_equal(r.kwds, ex_kwds)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:21,代码来源:test_DescriptorElementFactory.py
示例13: from_config
def from_config(cls, config_dict, type_str, uuid):
merged_config = cls.get_default_config()
merged_config.update(config_dict)
# convert factory configuration
merged_config['wrapped_element_factory'] = \
DescriptorElementFactory.from_config(
merged_config['wrapped_element_factory']
)
return super(CachingDescriptorElement, cls).from_config(
merged_config, type_str, uuid
)
开发者ID:msarahan,项目名称:SMQTK,代码行数:13,代码来源:cached_element_wrapper.py
示例14: run_file_list
def run_file_list(c, filelist_filepath, checkpoint_filepath, batch_size=None,
check_image=False):
"""
Top level function handling configuration and inputs/outputs.
:param c: Configuration dictionary (JSON)
:type c: dict
:param filelist_filepath: Path to a text file that lists paths to data
files, separated by new lines.
:type filelist_filepath: str
:param checkpoint_filepath: Output file to which we write input filepath to
SHA1 (UUID) relationships.
:type checkpoint_filepath:
:param batch_size: Optional batch size (None default) of data elements to
process / descriptors to compute at a time. This causes files and
stores to be written to incrementally during processing instead of
one single batch transaction at a time.
:type batch_size:
"""
log = logging.getLogger(__name__)
file_paths = [l.strip() for l in open(filelist_filepath)]
log.info("Making descriptor factory")
factory = DescriptorElementFactory.from_config(c['descriptor_factory'])
log.info("Making descriptor index")
#: :type: smqtk.representation.DescriptorIndex
descriptor_index = plugin.from_plugin_config(c['descriptor_index'],
get_descriptor_index_impls())
log.info("Making descriptor generator '%s'",
c['descriptor_generator']['type'])
#: :type: smqtk.algorithms.DescriptorGenerator
generator = plugin.from_plugin_config(c['descriptor_generator'],
get_descriptor_generator_impls())
def test_image_load(dfe):
try:
PIL.Image.open(io.BytesIO(dfe.get_bytes()))
return True
except IOError, ex:
# noinspection PyProtectedMember
log.warn("Failed to convert '%s' bytes into an image "
"(error: %s). Skipping",
dfe._filepath, str(ex))
return False
开发者ID:dhandeo,项目名称:SMQTK,代码行数:51,代码来源:compute_many_descriptors.py
示例15: run_file_list
def run_file_list(c, filelist_filepath, checkpoint_filepath, batch_size):
log = logging.getLogger(__name__)
file_paths = [l.strip() for l in open(filelist_filepath)]
log.info("Making descriptor factory")
factory = DescriptorElementFactory.from_config(c["descriptor_factory"])
log.info("Making descriptor generator '%s'", c["descriptor_generator"]["type"])
#: :type: smqtk.algorithms.DescriptorGenerator
generator = from_plugin_config(c["descriptor_generator"], get_descriptor_generator_impls)
log.info("Making descriptor generator -- Done")
valid_file_paths = dict()
invalid_file_paths = dict()
def iter_valid_elements():
for fp in file_paths:
dfe = DataFileElement(fp)
ct = dfe.content_type()
if ct in generator.valid_content_types():
valid_file_paths[fp] = ct
yield dfe
else:
invalid_file_paths[fp] = ct
log.info("Computing descriptors")
m = compute_many_descriptors(iter_valid_elements(), generator, factory, batch_size=batch_size)
# Recording computed file paths and associated file UUIDs (SHA1)
cf = open(checkpoint_filepath, "a")
try:
for fp, descr in m:
cf.write("{:s},{:s}\n".format(fp, descr.uuid()))
cf.flush()
finally:
cf.close()
# Output valid file and invalid file dictionaries as pickle
log.info("Writing valid filepaths map")
with open("file_map.valid.pickle", "wb") as f:
cPickle.dump(valid_file_paths, f)
log.info("Writing invalid filepaths map")
with open("file_map.invalid.pickle", "wb") as f:
cPickle.dump(invalid_file_paths, f)
log.info("Done")
开发者ID:msarahan,项目名称:SMQTK,代码行数:47,代码来源:compute_many_descriptors.py
示例16: get_default_config
def get_default_config(cls):
"""
Generate and return a default configuration dictionary for this class.
This will be primarily used for generating what the configuration
dictionary would look like for this class without instantiating it.
:return: Default configuration dictionary for the class.
:rtype: dict
"""
c = super(DescriptorServiceServer, cls).get_default_config()
merge_dict(c, {
"descriptor_factory": DescriptorElementFactory.get_default_config(),
"descriptor_generators": {
"example": plugin.make_config(get_descriptor_generator_impls())
}
})
return c
开发者ID:Kitware,项目名称:SMQTK,代码行数:18,代码来源:__init__.py
示例17: __init__
def __init__(self, json_config):
super(SmqtkClassifierService, self).__init__(json_config)
self.enable_classifier_removal = \
bool(json_config[self.CONFIG_ENABLE_CLASSIFIER_REMOVAL])
self.immutable_labels = set(json_config[self.CONFIG_IMMUTABLE_LABELS])
# Convert configuration into SMQTK plugin instances.
# - Static classifier configurations.
# - Skip the example config key
# - Classification element factory
# - Descriptor generator
# - Descriptor element factory
# - from-IQR-state classifier configuration
# - There must at least be the default key defined for when no
# specific classifier type is specified at state POST.
# Classifier collection + factor
self.classification_factory = \
ClassificationElementFactory.from_config(
json_config[self.CONFIG_CLASSIFICATION_FACTORY]
)
self.classifier_collection = ClassifierCollection.from_config(
json_config[self.CONFIG_CLASSIFIER_COLLECTION]
)
# Descriptor generator + factory
self.descriptor_factory = DescriptorElementFactory.from_config(
json_config[self.CONFIG_DESCRIPTOR_FACTORY]
)
#: :type: smqtk.algorithms.DescriptorGenerator
self.descriptor_gen = smqtk.utils.plugin.from_plugin_config(
json_config[self.CONFIG_DESCRIPTOR_GENERATOR],
smqtk.algorithms.get_descriptor_generator_impls()
)
# Classifier config for uploaded IQR states.
self.iqr_state_classifier_config = \
json_config[self.CONFIG_IQR_CLASSIFIER]
self.add_routes()
开发者ID:Kitware,项目名称:SMQTK,代码行数:42,代码来源:classifier_server.py
示例18: __init__
def __init__(self, json_config):
"""
Initialize application based of supplied JSON configuration
:param json_config: JSON configuration dictionary
:type json_config: dict
"""
super(NearestNeighborServiceServer, self).__init__(json_config)
self.update_index = json_config['update_descriptor_index']
# Descriptor factory setup
self._log.info("Initializing DescriptorElementFactory")
self.descr_elem_factory = DescriptorElementFactory.from_config(
self.json_config['descriptor_factory']
)
#: :type: smqtk.representation.DescriptorIndex | None
self.descr_index = None
if self.update_index:
self._log.info("Initializing DescriptorIndex to update")
#: :type: smqtk.representation.DescriptorIndex | None
self.descr_index = plugin.from_plugin_config(
json_config['descriptor_index'],
get_descriptor_index_impls()
)
#: :type: smqtk.algorithms.NearestNeighborsIndex
self.nn_index = plugin.from_plugin_config(
json_config['nn_index'],
get_nn_index_impls()
)
#: :type: smqtk.algorithms.DescriptorGenerator
self.descriptor_generator_inst = plugin.from_plugin_config(
self.json_config['descriptor_generator'],
get_descriptor_generator_impls()
)
@self.route("/count", methods=['GET'])
def count():
"""
Return the number of elements represented in this index.
"""
return flask.jsonify(**{
"count": self.nn_index.count(),
})
@self.route("/compute/<path:uri>", methods=["POST"])
def compute(uri):
"""
Compute the descriptor for a URI specified data element using the
configured descriptor generator.
See ``compute_nearest_neighbors`` method docstring for URI
specifications accepted.
If the a descriptor index was configured and update was turned on,
we add the computed descriptor to the index.
JSON Return format::
{
"success": <bool>
"message": <str>
"descriptor": <None|list[float]>
"reference_uri": <str>
}
:param uri: URI data specification.
"""
descriptor = None
try:
descriptor = self.generate_descriptor_for_uri(uri)
message = "Descriptor generated"
descriptor = list(map(float, descriptor.vector()))
except ValueError as ex:
message = "Input value issue: %s" % str(ex)
except RuntimeError as ex:
message = "Descriptor extraction failure: %s" % str(ex)
return flask.jsonify(
success=descriptor is not None,
message=message,
descriptor=descriptor,
reference_uri=uri,
)
@self.route("/nn/<path:uri>")
@self.route("/nn/n=<int:n>/<path:uri>")
@self.route("/nn/n=<int:n>/<int:start_i>:<int:end_i>/<path:uri>")
def compute_nearest_neighbors(uri, n=10, start_i=None, end_i=None):
"""
Data modes for upload/use:
- local filepath
#.........这里部分代码省略.........
开发者ID:Kitware,项目名称:SMQTK,代码行数:101,代码来源:__init__.py
示例19: main
def main():
parser = cli_parser()
args = parser.parse_args()
output_filepath = args.output_filepath
overwrite = args.overwrite
verbose = args.verbose
llevel = logging.DEBUG if verbose else logging.INFO
bin_utils.initialize_logging(logging.getLogger(), llevel)
log = logging.getLogger("main")
# Merge loaded config with default
config_loaded = False
config = default_config()
if args.config:
if os.path.isfile(args.config):
with open(args.config, 'r') as f:
config.update(json.load(f))
config_loaded = True
elif not os.path.isfile(args.config):
log.error("Configuration file path not valid.")
exit(1)
bin_utils.output_config(args.output_config, config, log, True)
# Configuration must have been loaded at this point since we can't normally
# trust the default.
if not config_loaded:
log.error("No configuration provided")
exit(1)
if not args.input_file:
log.error("Failed to provide an input file path")
exit(1)
elif not os.path.isfile(args.input_file):
log.error("Given path does not point to a file.")
exit(1)
input_filepath = args.input_file
data_element = DataFileElement(input_filepath)
factory = DescriptorElementFactory.from_config(config['descriptor_factory'])
#: :type: smqtk.algorithms.descriptor_generator.DescriptorGenerator
cd = plugin.from_plugin_config(config['content_descriptor'],
get_descriptor_generator_impls())
descr_elem = cd.compute_descriptor(data_element, factory, overwrite)
vec = descr_elem.vector()
if vec is None:
log.error("Failed to generate a descriptor vector for the input data!")
if output_filepath:
numpy.save(output_filepath, vec)
else:
# Construct string, because numpy
s = []
# noinspection PyTypeChecker
for f in vec:
s.append('%15f' % f)
print ' '.join(s)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:61,代码来源:computeDescriptor.py
示例20: __init__
def __init__(self, json_config):
"""
Initialize application based of supplied JSON configuration
:param json_config: JSON configuration dictionary
:type json_config: dict
"""
super(NearestNeighborServiceServer, self).__init__(json_config)
# Descriptor factory setup
self.log.info("Initializing DescriptorElementFactory")
self.descr_elem_factory = DescriptorElementFactory.from_config(
self.json_config['descriptor_factory']
)
# Descriptor generator configuration labels
#: :type: dict[str, dict]
self.generator_config = self.json_config['descriptor_generator']
#: :type: smqtk.algorithms.NearestNeighborsIndex
self.nn_index = plugin.from_plugin_config(
json_config['nn_index'],
get_nn_index_impls
)
#: :type: smqtk.algorithms.DescriptorGenerator
self.descriptor_generator_inst = plugin.from_plugin_config(
self.generator_config,
get_descriptor_generator_impls)
@self.route("/nn/<path:uri>")
@self.route("/nn/n=<int:n>/<path:uri>")
@self.route("/nn/n=<int:n>/<int:start_i>:<int:end_i>/<path:uri>")
def compute_nearest_neighbors(uri, n=10, start_i=None, end_i=None):
"""
Data modes for upload/use::
- local filepath
- base64
- http/s URL
The following sub-sections detail how different URI's can be used.
Local Filepath
--------------
The URI string must be prefixed with ``file://``, followed by the
full path to the data file to describe.
Base 64 data
------------
The URI string must be prefixed with "base64://", followed by the
base64 encoded string. This mode also requires an additional
``?content_type=`` to provide data content type information. This
mode saves the encoded data to temporary file for processing.
HTTP/S address
--------------
This is the default mode when the URI prefix is none of the above.
This uses the requests module to locally download a data file
for processing.
JSON Return format::
{
"success": <bool>
"message": <str>
"neighbors": <None|list[float]>
"reference_uri": <str>
}
:type uri: str
"""
message = "execution nominal"
descriptor = None
de = None
try:
self.log.debug("Received URI: %s", uri)
de = self.resolve_data_element(uri)
except ValueError, ex:
message = "URI resolution issue: %s" % str(ex)
if de:
try:
descriptor = self.descriptor_generator_inst.\
compute_descriptor(de, self.descr_elem_factory)
except RuntimeError, ex:
message = "Descriptor extraction failure: %s" % str(ex)
except ValueError, ex:
message = "Data content type issue: %s" % str(ex)
开发者ID:msarahan,项目名称:SMQTK,代码行数:97,代码来源:__init__.py
注:本文中的smqtk.representation.DescriptorElementFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论