本文整理汇总了Python中tensorflow_hub.load_module_spec方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow_hub.load_module_spec方法的具体用法?Python tensorflow_hub.load_module_spec怎么用?Python tensorflow_hub.load_module_spec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow_hub
的用法示例。
在下文中一共展示了tensorflow_hub.load_module_spec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eval_from_hub
# 需要导入模块: import tensorflow_hub [as 别名]
# 或者: from tensorflow_hub import load_module_spec [as 别名]
def eval_from_hub(model_dir, input_fn, eval_steps):
"""Eval using hub module."""
hub_module_spec = hub.load_module_spec(model_dir)
run_config = tf.estimator.RunConfig(model_dir=model_dir)
image_classifier = tf.estimator.Estimator(
model_fn=_make_model_fn(hub_module_spec), config=run_config, params={})
eval_results = image_classifier.evaluate(input_fn=input_fn, steps=eval_steps)
tf.logging.info('Evaluation results: %s' % eval_results)
示例2: get_text_module_input_name
# 需要导入模块: import tensorflow_hub [as 别名]
# 或者: from tensorflow_hub import load_module_spec [as 别名]
def get_text_module_input_name():
"""Get the tag used for inputs to the text module.
Returns:
a string, probably "default"
"""
module_spec = hub.load_module_spec(FLAGS.module_handle)
return list(module_spec.get_input_info_dict())[0]
示例3: __init__
# 需要导入模块: import tensorflow_hub [as 别名]
# 或者: from tensorflow_hub import load_module_spec [as 别名]
def __init__(self,
tf_hub_module_spec=None,
tf_hub_module_path=None,):
"""Creates an instance to extract image features from a pre-trained model.
The model to use may be specified as a TF-hub module (either by ModuleSpec
or path) or as an Inception V4 model checkpoint.
If a TF-hub module is given, it is assumed to conform to the interface
described in [1]. Its default signature should take an input 'images' Tensor
with shape [batch_size, height, width, num_channels=3] and return a
[batch_size, feature_dim] Tensor of features. Pass
`tf_hub_module_spec=make_module_spec_for_testing()` to stub out the model
for tests.
[1]
https://www.tensorflow.org/hub/common_signatures/images#image_feature_vector
Args:
tf_hub_module_spec: `hub.ModuleSpec` or None, the TF-hub module to load.
tf_hub_module_path: str or None, the location of the TF-hub module to load
in a format understood by `load_module_spec()` (URL,
'@internal/module/name', '/on/disk/path', etc.)
Raises:
ValueError: if not exactly one kwarg specifying the model is given.
"""
self.spec_str = None # String describing the model/module being used.
# Input and output tensors for the image to representation computation.
# The output tensor will depend on the model options.
self._input = None
self._output = None
self._session = None
num_kwargs = sum(
int(kwarg is not None) for kwarg in
[tf_hub_module_spec, tf_hub_module_path])
if num_kwargs != 1:
raise ValueError(
'Must provide exactly one of "tf_hub_module_spec", '
'"tf_hub_module_path".')
if tf_hub_module_spec:
self.spec_str = 'user_provided_module'
self._initialize_from_hub_module(tf_hub_module_spec)
elif tf_hub_module_path:
self.spec_str = tf_hub_module_path
self._initialize_from_hub_module(hub.load_module_spec(tf_hub_module_path))