当前位置: 首页>>代码示例>>Python>>正文


Python utils.build_tensor_info方法代码示例

本文整理汇总了Python中tensorflow.python.saved_model.utils.build_tensor_info方法的典型用法代码示例。如果您正苦于以下问题:Python utils.build_tensor_info方法的具体用法?Python utils.build_tensor_info怎么用?Python utils.build_tensor_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.saved_model.utils的用法示例。


在下文中一共展示了utils.build_tensor_info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_signature

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def build_signature(inputs, outputs):
  """Build the signature.

  Not using predic_signature_def in saved_model because it is replacing the
  tensor name, b/35900497.

  Args:
    inputs: a dictionary of tensor name to tensor
    outputs: a dictionary of tensor name to tensor
  Returns:
    The signature, a SignatureDef proto.
  """
  signature_inputs = {key: saved_model_utils.build_tensor_info(tensor)
                      for key, tensor in inputs.items()}
  signature_outputs = {key: saved_model_utils.build_tensor_info(tensor)
                       for key, tensor in outputs.items()}

  signature_def = signature_def_utils.build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.PREDICT_METHOD_NAME)

  return signature_def 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-edge-automation,代码行数:24,代码来源:model.py

示例2: build_inputs_and_outputs

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def build_inputs_and_outputs(self):
    if self.frame_features:
      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      fn = lambda x: self.build_prediction_graph(x)
      video_id_output, top_indices_output, top_predictions_output = (
          tf.map_fn(fn, serialized_examples,
                    dtype=(tf.string, tf.int32, tf.float32)))

    else:
      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      video_id_output, top_indices_output, top_predictions_output = (
          self.build_prediction_graph(serialized_examples))

    inputs = {"example_bytes":
              saved_model_utils.build_tensor_info(serialized_examples)}

    outputs = {
        "video_id": saved_model_utils.build_tensor_info(video_id_output),
        "class_indexes": saved_model_utils.build_tensor_info(top_indices_output),
        "predictions": saved_model_utils.build_tensor_info(top_predictions_output)}

    return inputs, outputs 
开发者ID:miha-skalic,项目名称:youtube8mchallenge,代码行数:26,代码来源:export_model.py

示例3: save_signature

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def save_signature(self, directory):

        signature = signature_def_utils.build_signature_def(
            inputs={
                'input':
                saved_model_utils.build_tensor_info(self.input),
                'dropout_rate':
                saved_model_utils.build_tensor_info(self.dropout_rate)
            },
            outputs={
                'output': saved_model_utils.build_tensor_info(self.output)
            },
            method_name=signature_constants.PREDICT_METHOD_NAME)
        signature_map = {
            signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature
        }
        model_builder = saved_model_builder.SavedModelBuilder(directory)
        model_builder.add_meta_graph_and_variables(
            self.sess,
            tags=[tag_constants.SERVING],
            signature_def_map=signature_map,
            clear_devices=True)
        model_builder.save(as_text=False) 
开发者ID:leimao,项目名称:Frozen_Graph_TensorFlow,代码行数:25,代码来源:cnn.py

示例4: build_inputs_and_outputs

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def build_inputs_and_outputs(self):
        if self.frame_features:
            serialized_examples = tf.placeholder(tf.string, shape=(None,))

            fn = lambda x: self.build_prediction_graph(x)
            video_id_output, top_indices_output, top_predictions_output = (
                tf.map_fn(fn, serialized_examples,
                          dtype=(tf.string, tf.int32, tf.float32)))

        else:
            serialized_examples = tf.placeholder(tf.string, shape=(None,))

            video_id_output, top_indices_output, top_predictions_output = (
                self.build_prediction_graph(serialized_examples))

        inputs = {"example_bytes":
                      saved_model_utils.build_tensor_info(serialized_examples)}

        outputs = {
            "video_id": saved_model_utils.build_tensor_info(video_id_output),
            "class_indexes": saved_model_utils.build_tensor_info(top_indices_output),
            "predictions": saved_model_utils.build_tensor_info(top_predictions_output)}

        return inputs, outputs 
开发者ID:pomonam,项目名称:AttentionCluster,代码行数:26,代码来源:export_model.py

示例5: build_inputs_and_outputs

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def build_inputs_and_outputs(self):

    if self.frame_features:

      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      fn = lambda x: self.build_prediction_graph(x)
      video_id_output, top_indices_output, top_predictions_output = (
          tf.map_fn(fn, serialized_examples, 
                    dtype=(tf.string, tf.int32, tf.float32)))

    else:

      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      video_id_output, top_indices_output, top_predictions_output = (
          self.build_prediction_graph(serialized_examples))

    inputs = {"example_bytes": 
              saved_model_utils.build_tensor_info(serialized_examples)}

    outputs = {
        "video_id": saved_model_utils.build_tensor_info(video_id_output),
        "class_indexes": saved_model_utils.build_tensor_info(top_indices_output),
        "predictions": saved_model_utils.build_tensor_info(top_predictions_output)}

    return inputs, outputs 
开发者ID:antoine77340,项目名称:Youtube-8M-WILLOW,代码行数:29,代码来源:export_model.py

示例6: regression_signature_def

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def regression_signature_def(examples, predictions):
  """Creates regression signature from given examples and predictions.

  Args:
    examples: `Tensor`.
    predictions: `Tensor`.

  Returns:
    A regression-flavored signature_def.

  Raises:
    ValueError: If examples is `None`.
  """
  if examples is None:
    raise ValueError('examples cannot be None for regression.')
  if predictions is None:
    raise ValueError('predictions cannot be None for regression.')

  input_tensor_info = utils.build_tensor_info(examples)
  signature_inputs = {signature_constants.REGRESS_INPUTS: input_tensor_info}

  output_tensor_info = utils.build_tensor_info(predictions)
  signature_outputs = {signature_constants.REGRESS_OUTPUTS: output_tensor_info}
  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.REGRESS_METHOD_NAME)

  return signature_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:signature_def_utils_impl.py

示例7: classification_signature_def

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def classification_signature_def(examples, classes, scores):
  """Creates classification signature from given examples and predictions.

  Args:
    examples: `Tensor`.
    classes: `Tensor`.
    scores: `Tensor`.

  Returns:
    A classification-flavored signature_def.

  Raises:
    ValueError: If examples is `None`.
  """
  if examples is None:
    raise ValueError('examples cannot be None for classification.')
  if classes is None and scores is None:
    raise ValueError('classes and scores cannot both be None for '
                     'classification.')

  input_tensor_info = utils.build_tensor_info(examples)
  signature_inputs = {signature_constants.CLASSIFY_INPUTS: input_tensor_info}

  signature_outputs = {}
  if classes is not None:
    classes_tensor_info = utils.build_tensor_info(classes)
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES] = (
        classes_tensor_info)
  if scores is not None:
    scores_tensor_info = utils.build_tensor_info(scores)
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_SCORES] = (
        scores_tensor_info)

  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.CLASSIFY_METHOD_NAME)

  return signature_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:signature_def_utils_impl.py

示例8: predict_signature_def

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def predict_signature_def(inputs, outputs):
  """Creates prediction signature from given inputs and outputs.

  Args:
    inputs: dict of string to `Tensor`.
    outputs: dict of string to `Tensor`.

  Returns:
    A prediction-flavored signature_def.

  Raises:
    ValueError: If inputs or outputs is `None`.
  """
  if inputs is None or not inputs:
    raise ValueError('inputs cannot be None or empty for prediction.')
  if outputs is None:
    raise ValueError('outputs cannot be None or empty for prediction.')

  signature_inputs = {key: utils.build_tensor_info(tensor)
                      for key, tensor in inputs.items()}
  signature_outputs = {key: utils.build_tensor_info(tensor)
                       for key, tensor in outputs.items()}

  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.PREDICT_METHOD_NAME)

  return signature_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:signature_def_utils_impl.py

示例9: testBuildTensorInfo

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def testBuildTensorInfo(self):
    x = array_ops.placeholder(dtypes.float32, 1, name="x")
    x_tensor_info = utils.build_tensor_info(x)
    self.assertEqual("x:0", x_tensor_info.name)
    self.assertEqual(types_pb2.DT_FLOAT, x_tensor_info.dtype)
    self.assertEqual(1, len(x_tensor_info.tensor_shape.dim))
    self.assertEqual(1, x_tensor_info.tensor_shape.dim[0].size) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:9,代码来源:utils_test.py

示例10: testBuildSignatureDef

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def testBuildSignatureDef(self):
    x = array_ops.placeholder(dtypes.float32, 1, name="x")
    x_tensor_info = utils.build_tensor_info(x)
    inputs = dict()
    inputs["foo-input"] = x_tensor_info

    y = array_ops.placeholder(dtypes.float32, name="y")
    y_tensor_info = utils.build_tensor_info(y)
    outputs = dict()
    outputs["foo-output"] = y_tensor_info

    signature_def = signature_def_utils.build_signature_def(inputs, outputs,
                                                            "foo-method-name")
    self.assertEqual("foo-method-name", signature_def.method_name)

    # Check inputs in signature def.
    self.assertEqual(1, len(signature_def.inputs))
    x_tensor_info_actual = signature_def.inputs["foo-input"]
    self.assertEqual("x:0", x_tensor_info_actual.name)
    self.assertEqual(types_pb2.DT_FLOAT, x_tensor_info_actual.dtype)
    self.assertEqual(1, len(x_tensor_info_actual.tensor_shape.dim))
    self.assertEqual(1, x_tensor_info_actual.tensor_shape.dim[0].size)

    # Check outputs in signature def.
    self.assertEqual(1, len(signature_def.outputs))
    y_tensor_info_actual = signature_def.outputs["foo-output"]
    self.assertEqual("y:0", y_tensor_info_actual.name)
    self.assertEqual(types_pb2.DT_FLOAT, y_tensor_info_actual.dtype)
    self.assertEqual(0, len(y_tensor_info_actual.tensor_shape.dim)) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:31,代码来源:signature_def_utils_test.py

示例11: predict_signature_def

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def predict_signature_def(inputs, outputs):
  """Creates prediction signature from given inputs and outputs.

  Args:
    inputs: dict of string to `Tensor`.
    outputs: dict of string to `Tensor`.

  Returns:
    A prediction-flavored signature_def.

  Raises:
    ValueError: If inputs or outputs is `None`.
  """
  if inputs is None or not inputs:
    raise ValueError('inputs cannot be None or empty for prediction.')
  if outputs is None:
    raise ValueError('outputs cannot be None or empty for prediction.')

  # If there's only one input or output, we can standardize keys
  if len(inputs) == 1:
    (_, value), = inputs.items()
    inputs = {signature_constants.PREDICT_INPUTS: value}
  if len(outputs) == 1:
    (_, value), = outputs.items()
    outputs = {signature_constants.PREDICT_OUTPUTS: value}

  signature_inputs = {key: utils.build_tensor_info(tensor)
                      for key, tensor in inputs.items()}
  signature_outputs = {key: utils.build_tensor_info(tensor)
                       for key, tensor in outputs.items()}

  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.PREDICT_METHOD_NAME)

  return signature_def 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:38,代码来源:signature_def_utils_impl.py

示例12: export

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def export(model_version, model_dir, sess, inputs, y_op):
    """导出tensorflow_serving可用的模型(Saved Model方式)(推荐)
    prediction_signature必备的三个参数分别是输入inputs、输出outputs和方法名method_name,如果缺失方法名将会报错:“grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.INTERNAL, details="Expected prediction signature method_name to be one of {tensorflow/serving/predict, tensorflow/serving/classify, tensorflow/serving/regress}. Was: ")”。每一个SavedModel关联着一个独立的checkpoint。每一个图元都绑定一个或多个标签,这些标签用来明确图元被加载的方式。标签只接受两种类型:serve或者train,保存时可以同时包含两个标签。其中tag_constants.SERVING = "serve",tag_constants.TRAINING = "train"。模型用于TensorFlow Serving时,标签必须包含serve类型。如果标签只包含train类型,TensorFlow Serving加载模型时会报错:“E tensorflow_serving/core/aspired_versions_manager.cc:351] Servable {name: default version: 2} cannot be loaded: Not found: Could not find meta graph def matching supplied tags.”。定义signature_def_map时注意定义默认服务签名键,如果缺少则会报错:“grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Default serving signature key not found.")”。
    """
    if model_version <= 0:
        print('Please specify a positive value for version number.')
        sys.exit()

    path = os.path.dirname(os.path.abspath(model_dir))
    if os.path.isdir(path) == False:
        logging.warning('Path (%s) not exists, making directories...', path)
        os.makedirs(path)

    export_path = os.path.join(
        compat.as_bytes(model_dir),
        compat.as_bytes(str(model_version)))

    if os.path.isdir(export_path) == True:
        logging.warning('Path (%s) exists, removing directories...', export_path)
        shutil.rmtree(export_path)

    builder = saved_model_builder.SavedModelBuilder(export_path)
    tensor_info_x = utils.build_tensor_info(inputs)
    tensor_info_y = utils.build_tensor_info(y_op)

    prediction_signature = signature_def_utils.build_signature_def(
        inputs={'x': tensor_info_x},
        outputs={'y': tensor_info_y},
        method_name=signature_constants.PREDICT_METHOD_NAME)

    builder.add_meta_graph_and_variables(
        sess,
        [tag_constants.SERVING],
        signature_def_map={
            'predict_text': prediction_signature,
            signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature
        })

    builder.save() 
开发者ID:tensorlayer,项目名称:text-antispam,代码行数:41,代码来源:mlp_classifier.py

示例13: _prepare_signature

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def _prepare_signature(layers: dict, model_keys):
    if tf_version.split(".")[0] == "2":
        disable_eager_execution()
    signature = {}
    for key, value in model_keys.items():
        if value in layers.keys():
            x = array_ops.placeholder(
                dtype=type_mapping[layers[value].precision],
                shape=layers[value].shape, name=value)
            x_tensor_info = build_tensor_info(x)
            signature[key] = x_tensor_info
    return signature 
开发者ID:openvinotoolkit,项目名称:model_server,代码行数:14,代码来源:get_model_metadata_utils.py

示例14: build_inputs_and_outputs

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def build_inputs_and_outputs(self):
    if self.frame_features:
      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      fn = lambda x: self.build_prediction_graph(x)
      video_id_output, top_indices_output, top_predictions_output = (tf.map_fn(
          fn, serialized_examples, dtype=(tf.string, tf.int32, tf.float32)))

    else:
      serialized_examples = tf.placeholder(tf.string, shape=(None,))

      video_id_output, top_indices_output, top_predictions_output = (
          self.build_prediction_graph(serialized_examples))

    inputs = {
        "example_bytes":
            saved_model_utils.build_tensor_info(serialized_examples)
    }

    outputs = {
        "video_id":
            saved_model_utils.build_tensor_info(video_id_output),
        "class_indexes":
            saved_model_utils.build_tensor_info(top_indices_output),
        "predictions":
            saved_model_utils.build_tensor_info(top_predictions_output)
    }

    return inputs, outputs 
开发者ID:google,项目名称:youtube-8m,代码行数:31,代码来源:export_model.py

示例15: export_saved_model

# 需要导入模块: from tensorflow.python.saved_model import utils [as 别名]
# 或者: from tensorflow.python.saved_model.utils import build_tensor_info [as 别名]
def export_saved_model(sess, export_path, input_tensor, output_tensor):
    from tensorflow.python.saved_model import builder as saved_model_builder
    from tensorflow.python.saved_model import signature_constants
    from tensorflow.python.saved_model import signature_def_utils
    from tensorflow.python.saved_model import tag_constants
    from tensorflow.python.saved_model import utils
    builder = saved_model_builder.SavedModelBuilder(export_path)

    prediction_signature = signature_def_utils.build_signature_def(
        inputs={'images': utils.build_tensor_info(input_tensor)},
        outputs={
            'scores': utils.build_tensor_info(output_tensor)
        },
        method_name=signature_constants.PREDICT_METHOD_NAME)

    legacy_init_op = tf.group(
        tf.tables_initializer(), name='legacy_init_op')
    builder.add_meta_graph_and_variables(
        sess, [tag_constants.SERVING],
        signature_def_map={
            'predict_images':
                prediction_signature,
        },
        legacy_init_op=legacy_init_op)

    builder.save() 
开发者ID:PacktPublishing,项目名称:Machine-Learning-with-TensorFlow-1.x,代码行数:28,代码来源:models.py


注:本文中的tensorflow.python.saved_model.utils.build_tensor_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。