本文整理汇总了Python中utils.util.is_tfrecord_input方法的典型用法代码示例。如果您正苦于以下问题:Python util.is_tfrecord_input方法的具体用法?Python util.is_tfrecord_input怎么用?Python util.is_tfrecord_input使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.util
的用法示例。
在下文中一共展示了util.is_tfrecord_input方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inference
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import is_tfrecord_input [as 别名]
def inference(
self, inference_input, checkpoint_path, batch_size=None, **kwargs):
"""Defines 3 of modes of inference.
Inputs:
* Mode 1: Input is an input_fn.
* Mode 2: Input is a TFRecord (or list of TFRecords).
* Mode 3: Input is a numpy array holding an image (or array of images).
Outputs:
* Mode 1: this returns an iterator over embeddings and additional
metadata. See
https://www.tensorflow.org/api_docs/python/tf/estimator/Estimator#predict
for details.
* Mode 2: Returns an iterator over tuples of
(embeddings, raw_image_strings, sequence_name), where embeddings is a
2-D float32 numpy array holding [sequence_size, embedding_size] image
embeddings, raw_image_strings is a 1-D string numpy array holding
[sequence_size] jpeg-encoded image strings, and sequence_name is a
string holding the name of the embedded sequence.
* Mode 3: Returns a tuple of (embeddings, raw_image_strings), where
embeddings is a 2-D float32 numpy array holding
[batch_size, embedding_size] image embeddings, raw_image_strings is a
1-D string numpy array holding [batch_size] jpeg-encoded image strings.
Args:
inference_input: This can be a tf.Estimator input_fn, a TFRecord path,
a list of TFRecord paths, a numpy image, or an array of numpy images.
checkpoint_path: String, path to the checkpoint to restore for inference.
batch_size: Int, the size of the batch to use for inference.
**kwargs: Additional keyword arguments, depending on the mode.
See _input_fn_inference, _tfrecord_inference, and _np_inference.
Returns:
inference_output: Inference output depending on mode, see above for
details.
Raises:
ValueError: If inference_input isn't a tf.Estimator input_fn,
a TFRecord path, a list of TFRecord paths, or a numpy array,
"""
# Mode 1: input is a callable tf.Estimator input_fn.
if callable(inference_input):
return self._input_fn_inference(
input_fn=inference_input, checkpoint_path=checkpoint_path, **kwargs)
# Mode 2: Input is a TFRecord path (or list of TFRecord paths).
elif util.is_tfrecord_input(inference_input):
return self._tfrecord_inference(
records=inference_input, checkpoint_path=checkpoint_path,
batch_size=batch_size, **kwargs)
# Mode 3: Input is a numpy array of raw images.
elif util.is_np_array(inference_input):
return self._np_inference(
np_images=inference_input, checkpoint_path=checkpoint_path, **kwargs)
else:
raise ValueError(
'inference input must be a tf.Estimator input_fn, a TFRecord path,'
'a list of TFRecord paths, or a numpy array. Got: %s' % str(type(
inference_input)))