當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。