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


Python tensor_util.make_tensor_proto方法代码示例

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


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

示例1: testHalf

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testHalf(self):
    t = tensor_util.make_tensor_proto(np.array([10.0, 20.0], dtype=np.float16))
    self.assertProtoEquals("""
      dtype: DT_HALF
      tensor_shape {
        dim {
          size: 2
        }
      }
      half_val: 18688
      half_val: 19712
      """, t)

    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.float16, a.dtype)
    self.assertAllClose(np.array([10.0, 20.0], dtype=np.float16), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:tensor_util_test.py

示例2: testIntTypes

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testIntTypes(self):
    for dtype, nptype in [
        (tf.int32, np.int32),
        (tf.uint8, np.uint8),
        (tf.uint16, np.uint16),
        (tf.int16, np.int16),
        (tf.int8, np.int8)]:
      # Test with array.
      t = tensor_util.make_tensor_proto([10, 20, 30], dtype=dtype)
      self.assertEquals(dtype, t.dtype)
      self.assertProtoEquals("dim { size: 3 }", t.tensor_shape)
      a = tensor_util.MakeNdarray(t)
      self.assertEquals(nptype, a.dtype)
      self.assertAllClose(np.array([10, 20, 30], dtype=nptype), a)
      # Test with ndarray.
      t = tensor_util.make_tensor_proto(np.array([10, 20, 30], dtype=nptype))
      self.assertEquals(dtype, t.dtype)
      self.assertProtoEquals("dim { size: 3 }", t.tensor_shape)
      a = tensor_util.MakeNdarray(t)
      self.assertEquals(nptype, a.dtype)
      self.assertAllClose(np.array([10, 20, 30], dtype=nptype), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:tensor_util_test.py

示例3: testComplex64N

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testComplex64N(self):
    t = tensor_util.make_tensor_proto([(1+2j), (3+4j), (5+6j)], shape=[1, 3],
                                      dtype=tf.complex64)
    self.assertProtoEquals("""
      dtype: DT_COMPLEX64
      tensor_shape { dim { size: 1 } dim { size: 3 } }
      scomplex_val: 1
      scomplex_val: 2
      scomplex_val: 3
      scomplex_val: 4
      scomplex_val: 5
      scomplex_val: 6
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex64, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j), (5+6j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:tensor_util_test.py

示例4: testComplex64NpArray

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testComplex64NpArray(self):
    t = tensor_util.make_tensor_proto(
        np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), dtype=tf.complex64)
    # scomplex_val are real_0, imag_0, real_1, imag_1, ...
    self.assertProtoEquals("""
      dtype: DT_COMPLEX64
      tensor_shape { dim { size: 2 } dim { size: 2 } }
      scomplex_val: 1
      scomplex_val: 2
      scomplex_val: 3
      scomplex_val: 4
      scomplex_val: 5
      scomplex_val: 6
      scomplex_val: 7
      scomplex_val: 8
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex64, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:tensor_util_test.py

示例5: testComplex128NpArray

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testComplex128NpArray(self):
    t = tensor_util.make_tensor_proto(
        np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), dtype=tf.complex128)
    # scomplex_val are real_0, imag_0, real_1, imag_1, ...
    self.assertProtoEquals("""
      dtype: DT_COMPLEX128
      tensor_shape { dim { size: 2 } dim { size: 2 } }
      dcomplex_val: 1
      dcomplex_val: 2
      dcomplex_val: 3
      dcomplex_val: 4
      dcomplex_val: 5
      dcomplex_val: 6
      dcomplex_val: 7
      dcomplex_val: 8
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex128, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:tensor_util_test.py

示例6: _populate_const_op

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def _populate_const_op(output_node, node_name, dtype, data, data_shape):
  """Creates a Const op.

  Args:
    output_node: TensorFlow NodeDef.
    node_name: str node name.
    dtype: AttrValue with a populated .type field.
    data: numpy data value.
    data_shape: Tuple of integers containing data shape.
  """
  output_node.op = "Const"
  output_node.name = node_name
  output_node.attr["dtype"].CopyFrom(dtype)
  tensor = tensor_util.make_tensor_proto(
      data, dtype=dtype.type, shape=data_shape)
  output_node.attr["value"].tensor.CopyFrom(tensor) 
开发者ID:onnx,项目名称:keras-onnx,代码行数:18,代码来源:_graph_cvt.py

示例7: set_attr_tensor

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def set_attr_tensor(self, node, key, value, dtype, shape=None):
    node.attr[key].CopyFrom(
        attr_value_pb2.AttrValue(tensor=tensor_util.make_tensor_proto(
            value, dtype=dtype, shape=shape))) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:6,代码来源:optimize_for_inference_test.py

示例8: testToFloat32

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testToFloat32(self):
    with self.test_session():
      expected = np.random.rand(3, 4, 5).astype(np.float32)
      tensor_proto = tensor_util.make_tensor_proto(expected)

      serialized = tf.placeholder(tf.string)
      tensor = tf.parse_tensor(serialized, tf.float32)

      result = tensor.eval(
          feed_dict={serialized: tensor_proto.SerializeToString()})

      self.assertAllEqual(expected, result) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:parsing_ops_test.py

示例9: testToUint8

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testToUint8(self):
    with self.test_session():
      expected = np.random.rand(3, 4, 5).astype(np.uint8)
      tensor_proto = tensor_util.make_tensor_proto(expected)

      serialized = tf.placeholder(tf.string)
      tensor = tf.parse_tensor(serialized, tf.uint8)

      result = tensor.eval(
          feed_dict={serialized: tensor_proto.SerializeToString()})

      self.assertAllEqual(expected, result) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:parsing_ops_test.py

示例10: testTypeMismatch

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testTypeMismatch(self):
    with self.test_session():
      expected = np.random.rand(3, 4, 5).astype(np.uint8)
      tensor_proto = tensor_util.make_tensor_proto(expected)

      serialized = tf.placeholder(tf.string)
      tensor = tf.parse_tensor(serialized, tf.uint16)

      with self.assertRaisesOpError(
          r"Type mismatch between parsed tensor \(uint8\) and dtype "
          r"\(uint16\)"):
        tensor.eval(feed_dict={serialized: tensor_proto.SerializeToString()}) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:parsing_ops_test.py

示例11: set_attr_tensor

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def set_attr_tensor(self, node, key, value, dtype, shape=None):
    node.attr[key].CopyFrom(tf.AttrValue(
        tensor=tensor_util.make_tensor_proto(value,
                                             dtype=dtype,
                                             shape=shape))) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:7,代码来源:optimize_for_inference_test.py

示例12: testFloat

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testFloat(self):
    value = 10.0
    t = tensor_util.make_tensor_proto(value)
    self.assertProtoEquals("""
      dtype: DT_FLOAT
      tensor_shape {}
      float_val: %.1f
      """ % value, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.float32, a.dtype)
    self.assertAllClose(np.array(value, dtype=np.float32), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:13,代码来源:tensor_util_test.py

示例13: testFloatTyped

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testFloatTyped(self):
    t = tensor_util.make_tensor_proto([10.0, 20.0, 30.0], dtype=tf.float32)
    self.assertProtoEquals("""
      dtype: DT_FLOAT
      tensor_shape { dim { size: 3 } }
      tensor_content: "\000\000 A\000\000\240A\000\000\360A"
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.float32, a.dtype)
    self.assertAllClose(np.array([10.0, 20.0, 30.0], dtype=np.float32), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:tensor_util_test.py

示例14: testFloatTypeCoerce

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testFloatTypeCoerce(self):
    t = tensor_util.make_tensor_proto([10, 20, 30], dtype=tf.float32)
    self.assertProtoEquals("""
      dtype: DT_FLOAT
      tensor_shape { dim { size: 3 } }
      tensor_content: "\000\000 A\000\000\240A\000\000\360A"
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.float32, a.dtype)
    self.assertAllClose(np.array([10.0, 20.0, 30.0], dtype=np.float32), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:tensor_util_test.py

示例15: testFloatTypeCoerceNdarray

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import make_tensor_proto [as 别名]
def testFloatTypeCoerceNdarray(self):
    arr = np.asarray([10, 20, 30], dtype="int")
    t = tensor_util.make_tensor_proto(arr, dtype=tf.float32)
    self.assertProtoEquals("""
      dtype: DT_FLOAT
      tensor_shape { dim { size: 3 } }
      tensor_content: "\000\000 A\000\000\240A\000\000\360A"
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.float32, a.dtype)
    self.assertAllClose(np.array([10.0, 20.0, 30.0], dtype=np.float32), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:13,代码来源:tensor_util_test.py


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