本文整理匯總了Python中utils.util.is_np_array方法的典型用法代碼示例。如果您正苦於以下問題:Python util.is_np_array方法的具體用法?Python util.is_np_array怎麽用?Python util.is_np_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils.util
的用法示例。
在下文中一共展示了util.is_np_array方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: inference
# 需要導入模塊: from utils import util [as 別名]
# 或者: from utils.util import is_np_array [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)))