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


Python tensorflow.make_tensor_proto方法代码示例

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


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

示例1: make_grpc_request_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def make_grpc_request_fn(servable_name, server, timeout_secs):
  """Wraps function to make grpc requests with runtime args."""
  stub = _create_stub(server)

  def _make_grpc_request(examples):
    """Builds and sends request to TensorFlow model server."""
    request = predict_pb2.PredictRequest()
    request.model_spec.name = servable_name
    request.inputs["input"].CopyFrom(
        tf.make_tensor_proto(
            [ex.SerializeToString() for ex in examples], shape=[len(examples)]))
    response = stub.Predict(request, timeout_secs)
    outputs = tf.make_ndarray(response.outputs["outputs"])
    scores = tf.make_ndarray(response.outputs["scores"])
    assert len(outputs) == len(scores)
    return [{  # pylint: disable=g-complex-comprehension
        "outputs": output,
        "scores": score
    } for output, score in zip(outputs, scores)]

  return _make_grpc_request 
开发者ID:yyht,项目名称:BERT,代码行数:23,代码来源:serving_utils.py

示例2: send_request

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def send_request(stub, model_name, batch_tokens, timeout=5.0):
  """Sends a translation request.

  Args:
    stub: The prediction service stub.
    model_name: The model to request.
    tokens: A list of tokens.
    timeout: Timeout after this many seconds.

  Returns:
    A future.
  """
  batch_tokens, lengths, max_length = pad_batch(batch_tokens)
  batch_size = len(lengths)
  request = predict_pb2.PredictRequest()
  request.model_spec.name = model_name
  request.inputs["tokens"].CopyFrom(tf.make_tensor_proto(
      batch_tokens, dtype=tf.string, shape=(batch_size, max_length)))
  request.inputs["length"].CopyFrom(tf.make_tensor_proto(
      lengths, dtype=tf.int32, shape=(batch_size,)))
  return stub.Predict.future(request, timeout) 
开发者ID:OpenNMT,项目名称:OpenNMT-tf,代码行数:23,代码来源:ende_client.py

示例3: test_compute_returns_result

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def test_compute_returns_result(self, mock_stub):
    tensor_proto = tf.make_tensor_proto(1)
    any_pb = any_pb2.Any()
    any_pb.Pack(tensor_proto)
    value = executor_pb2.Value(tensor=any_pb)
    response = executor_pb2.ComputeResponse(value=value)
    instance = mock_stub.return_value
    instance.Compute = mock.Mock(side_effect=[response])
    loop = asyncio.get_event_loop()
    executor = create_remote_executor()
    type_signature = computation_types.FunctionType(None, tf.int32)
    comp = remote_executor.RemoteValue(executor_pb2.ValueRef(), type_signature,
                                       executor)

    result = loop.run_until_complete(comp.compute())

    instance.Compute.assert_called_once()
    self.assertEqual(result, 1) 
开发者ID:tensorflow,项目名称:federated,代码行数:20,代码来源:remote_executor_test.py

示例4: test_op_info

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def test_op_info():
    np_array = np.array([1, 2, 3], dtype=np.float32)
    t_proto = tf.make_tensor_proto(np_array, dtype=np.float32)
    ugraph = uTensorGraph(output_nodes=['dummy'])
    op_info = OperationInfo(name='testing_op',
                            input_tensors=[],
                            n_inputs=0,
                            output_tensors=[],
                            n_outputs=0,
                            op_type='no_op',
                            lib_name='tensorflow',
                            op_attr={
                                '_utensor_to_skip': [1, 2, 3],
                                '_utensor_skip_this_too': None,
                                'tensor_no_skip': t_proto
                            },
                            ugraph=ugraph)
    assert op_info.op_attr.get('_utensor_to_skip', None) == [1, 2, 3]
    assert op_info.op_attr.get('_utensor_skip_this_too') is None
    generic_tensor = op_info.op_attr.get('tensor_no_skip')
    assert isinstance(generic_tensor,
                      TensorProtoConverter.__utensor_generic_type__)
    assert (generic_tensor.np_array == np_array).all()
    assert op_info.name in ugraph.ops_info 
开发者ID:uTensor,项目名称:utensor_cgen,代码行数:26,代码来源:test_graph.py

示例5: _post_process

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def _post_process(
      self, elements: List[Union[tf.train.Example, tf.train.SequenceExample]],
      outputs: Sequence[Mapping[Text, Any]]
  ) -> Iterable[prediction_log_pb2.PredictLog]:
    result = []
    for output in outputs:
      predict_log = prediction_log_pb2.PredictLog()
      for output_alias, values in output.items():
        values = np.array(values)
        tensor_proto = tf.make_tensor_proto(
            values=values,
            dtype=tf.as_dtype(values.dtype).as_datatype_enum,
            shape=np.expand_dims(values, axis=0).shape)
        predict_log.response.outputs[output_alias].CopyFrom(tensor_proto)
      result.append(predict_log)
    return result


# TODO(b/131873699): Add typehints once
# [BEAM-8381](https://issues.apache.org/jira/browse/BEAM-8381)
# is fixed.
# TODO(b/143484017): Add batch_size back off in the case there are functional
# reasons large batch sizes cannot be handled. 
开发者ID:tensorflow,项目名称:tfx-bsl,代码行数:25,代码来源:run_inference.py

示例6: grpc_predict_raw

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def grpc_predict_raw(data):
    port = 8500
    channel = grpc.insecure_channel('{host}:{port}'.format(host=host, port=port))
    # channel = implementations.insecure_channel(host, int(port))

    stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'textcnn_model'
    request.model_spec.signature_name = "serving_default"

    tensor_protos = {
        # 一条一条的请求方式
        'sentence':tf.make_tensor_proto(data['sentence'], dtype=tf.int64, shape=[1, 55])
    }
    for k in tensor_protos:
        request.inputs[k].CopyFrom(tensor_protos[k])

    response = stub.Predict(request, 5.0)
    print(response) 
开发者ID:sladesha,项目名称:deep_learning,代码行数:21,代码来源:serving_grpc_client.py

示例7: _write_checkpoint_path_to_summary

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def _write_checkpoint_path_to_summary(output_dir, checkpoint_path,
                                      current_global_step):
  """Writes `checkpoint_path` into summary file in the given output directory.

  Args:
    output_dir: `str`, directory to write the summary file in.
    checkpoint_path: `str`, checkpoint file path to be written to summary file.
    current_global_step: `int`, the current global step.
  """

  checkpoint_path_tag = 'checkpoint_path'

  tf.compat.v1.logging.info('Saving \'%s\' summary for global step %d: %s',
                            checkpoint_path_tag, current_global_step,
                            checkpoint_path)
  summary_proto = summary_pb2.Summary()
  summary_proto.value.add(
      tag=checkpoint_path_tag,
      tensor=tf.make_tensor_proto(checkpoint_path, dtype=tf.dtypes.string))
  summary_writer = tf.compat.v1.summary.FileWriterCache.get(output_dir)
  summary_writer.add_summary(summary_proto, current_global_step)
  summary_writer.flush() 
开发者ID:tensorflow,项目名称:estimator,代码行数:24,代码来源:estimator.py

示例8: text

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def text(self, tag, textdata, step=None):
    """Saves a text summary.

    Args:
      tag: str: label for this data
      textdata: string, or 1D/2D list/numpy array of strings
      step: int: training step
    Note: markdown formatting is rendered by tensorboard.
    """
    if step is None:
      step = self._step
    else:
      self._step = step
    smd = SummaryMetadata(
        plugin_data=SummaryMetadata.PluginData(plugin_name='text'))
    if isinstance(textdata, (str, bytes)):
      tensor = tf.make_tensor_proto(
          values=[textdata.encode(encoding='utf_8')], shape=(1,))
    else:
      textdata = onp.array(textdata)  # convert lists, jax arrays, etc.
      datashape = onp.shape(textdata)
      if len(datashape) == 1:
        tensor = tf.make_tensor_proto(
            values=[td.encode(encoding='utf_8') for td in textdata],
            shape=(datashape[0],))
      elif len(datashape) == 2:
        tensor = tf.make_tensor_proto(
            values=[
                td.encode(encoding='utf_8') for td in onp.reshape(textdata, -1)
            ],
            shape=(datashape[0], datashape[1]))
    summary = Summary(
        value=[Summary.Value(tag=tag, metadata=smd, tensor=tensor)])
    self.add_summary(summary, step)


# Copied from gin/tf/utils.py:GinConfigSaverHook 
开发者ID:yyht,项目名称:BERT,代码行数:39,代码来源:jaxboard.py

示例9: test_predict_request_json

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def test_predict_request_json(sagemaker_session):
    data = [6.4, 3.2, 0.5, 1.5]
    tensor_proto = tf.make_tensor_proto(
        values=np.asarray(data), shape=[1, len(data)], dtype=tf.float32
    )
    predictor = RealTimePredictor(
        sagemaker_session=sagemaker_session,
        endpoint=ENDPOINT,
        deserializer=tf_json_deserializer,
        serializer=tf_json_serializer,
    )

    mock_response(
        json.dumps(CLASSIFICATION_RESPONSE).encode("utf-8"), sagemaker_session, JSON_CONTENT_TYPE
    )

    result = predictor.predict(tensor_proto)

    sagemaker_session.sagemaker_runtime_client.invoke_endpoint.assert_called_once_with(
        Accept=JSON_CONTENT_TYPE,
        Body=json_format.MessageToJson(tensor_proto),
        ContentType=JSON_CONTENT_TYPE,
        EndpointName="myendpoint",
    )

    assert result == CLASSIFICATION_RESPONSE 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:28,代码来源:test_tf_predictor.py

示例10: test_predict_tensor_request_csv

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def test_predict_tensor_request_csv(sagemaker_session):
    data = [6.4, 3.2, 0.5, 1.5]
    tensor_proto = tf.make_tensor_proto(
        values=np.asarray(data), shape=[1, len(data)], dtype=tf.float32
    )
    predictor = RealTimePredictor(
        serializer=tf_csv_serializer,
        deserializer=tf_json_deserializer,
        sagemaker_session=sagemaker_session,
        endpoint=ENDPOINT,
    )

    mock_response(
        json.dumps(CLASSIFICATION_RESPONSE).encode("utf-8"), sagemaker_session, JSON_CONTENT_TYPE
    )

    result = predictor.predict(tensor_proto)

    sagemaker_session.sagemaker_runtime_client.invoke_endpoint.assert_called_once_with(
        Accept=JSON_CONTENT_TYPE,
        Body="6.4,3.2,0.5,1.5",
        ContentType=CSV_CONTENT_TYPE,
        EndpointName="myendpoint",
    )

    assert result == CLASSIFICATION_RESPONSE 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:28,代码来源:test_tf_predictor.py

示例11: text

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def text(self, tag, textdata, step=None):
    """Saves a text summary.

    Args:
      tag: str: label for this data
      textdata: string, or 1D/2D list/numpy array of strings
      step: int: training step
    Note: markdown formatting is rendered by tensorboard.
    """
    if step is None:
      step = self._step
    else:
      self._step = step
    smd = tf.compat.v1.SummaryMetadata(
        plugin_data=tf.compat.v1.SummaryMetadata.PluginData(plugin_name='text'))
    if isinstance(textdata, (str, bytes)):
      tensor = tf.make_tensor_proto(
          values=[textdata.encode(encoding='utf_8')], shape=(1,))
    else:
      textdata = np.array(textdata)  # convert lists, jax arrays, etc.
      datashape = np.shape(textdata)
      if len(datashape) == 1:
        tensor = tf.make_tensor_proto(
            values=[td.encode(encoding='utf_8') for td in textdata],
            shape=(datashape[0],))
      elif len(datashape) == 2:
        tensor = tf.make_tensor_proto(
            values=[
                td.encode(encoding='utf_8') for td in np.reshape(textdata, -1)
            ],
            shape=(datashape[0], datashape[1]))
    summary = tf.compat.v1.Summary(
        value=[tf.compat.v1.Summary.Value(
            tag=tag, metadata=smd, tensor=tensor)])
    self.add_summary(summary, step)


# Copied from gin/tf/utils.py:GinConfigSaverHook 
开发者ID:google,项目名称:trax,代码行数:40,代码来源:jaxboard.py

示例12: deserialize_tensor_value

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def deserialize_tensor_value(value_proto):
  """Deserializes a tensor value from `executor_pb2.Value`.

  Args:
    value_proto: An instance of `executor_pb2.Value`.

  Returns:
    A tuple `(value, type_spec)`, where `value` is a Numpy array that represents
    the deserialized value, and `type_spec` is an instance of `tff.TensorType`
    that represents its type.

  Raises:
    TypeError: If the arguments are of the wrong types.
    ValueError: If the value is malformed.
  """
  py_typecheck.check_type(value_proto, executor_pb2.Value)
  which_value = value_proto.WhichOneof('value')
  if which_value != 'tensor':
    raise ValueError('Not a tensor value: {}'.format(which_value))

  # TODO(b/134543154): Find some way of creating the `TensorProto` using a
  # proper public interface rather than creating a dummy value that we will
  # overwrite right away.
  tensor_proto = tf.make_tensor_proto(values=0)
  if not value_proto.tensor.Unpack(tensor_proto):
    raise ValueError('Unable to unpack the received tensor value.')

  tensor_value = tf.make_ndarray(tensor_proto)
  value_type = computation_types.TensorType(
      dtype=tf.dtypes.as_dtype(tensor_proto.dtype),
      shape=tf.TensorShape(tensor_proto.tensor_shape))

  return tensor_value, value_type 
开发者ID:tensorflow,项目名称:federated,代码行数:35,代码来源:executor_service_utils.py

示例13: pb

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def pb(tag, guest, display_name=None, description=None):
  """Create a greeting summary for the given guest.

  Arguments:
    tag: The string tag associated with the summary.
    guest: The string name of the guest to greet.
    display_name: If set, will be used as the display name in
      TensorBoard. Defaults to `tag`.
    description: A longform readable description of the summary data.
      Markdown is supported.
    """
  message = 'Hello, %s!' % guest
  tensor = tf.make_tensor_proto(message, dtype=tf.string)

  # We have no metadata to store, but we do need to add a plugin_data entry
  # so that we know this summary is associated with the greeter plugin.
  # We could use this entry to pass additional metadata other than the
  # PLUGIN_NAME by using the content parameter.
  summary_metadata = tf.SummaryMetadata(
      display_name=display_name,
      summary_description=description,
      plugin_data=tf.SummaryMetadata.PluginData(
          plugin_name=PLUGIN_NAME))

  summary = tf.Summary()
  summary.value.add(tag=tag,
                    metadata=summary_metadata,
                    tensor=tensor)
  return summary 
开发者ID:tensorflow,项目名称:tensorboard-plugin-example,代码行数:31,代码来源:greeter_summary.py

示例14: _BuildPredictRequests

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def _BuildPredictRequests(self, signature_name: Text,
                            serialized_input_key: Text):
    for record in self._records:
      request = predict_pb2.PredictRequest()
      request.model_spec.name = self._model_name
      request.model_spec.signature_name = signature_name
      request.inputs[serialized_input_key].CopyFrom(
          tf.make_tensor_proto([record]))
      yield request 
开发者ID:tensorflow,项目名称:tfx,代码行数:11,代码来源:request_builder.py

示例15: get_tf_value

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import make_tensor_proto [as 别名]
def get_tf_value(cls, value):
    return make_tensor_proto(value.np_array, dtype=value.dtype) 
开发者ID:uTensor,项目名称:utensor_cgen,代码行数:4,代码来源:converter.py


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