コード例 #1
0
  def testTensorStr(self):
    a = array_ops.placeholder_v2(tf.float32, shape=None, name="a")
    self.assertEqual("<tf.Tensor 'a:0' shape=<unknown> dtype=float32>", repr(a))

    b = array_ops.placeholder_v2(tf.int32, shape=(32, 40), name="b")
    self.assertEqual("<tf.Tensor 'b:0' shape=(32, 40) dtype=int32>", repr(b))

    c = array_ops.placeholder_v2(tf.qint32, shape=(32, None, 2), name="c")
    self.assertEqual("<tf.Tensor 'c:0' shape=(32, ?, 2) dtype=qint32>", repr(c))
コード例 #2
0
 def testScalarShape(self):
     with self.test_session():
         p = array_ops.placeholder_v2(dtypes_lib.float32,
                                      shape=[],
                                      name="p")
         p_identity = array_ops.identity(p)
         self.assertAllClose(p_identity.eval(feed_dict={p: 5}), 5)
コード例 #3
0
 def testControlDependency(self):
   with self.test_session():
     p = array_ops.placeholder_v2(tf.int32, shape=[], name="p")
     with tf.control_dependencies([p]):
       c = tf.constant(5, tf.int32)
     d = tf.mul(p, c)
     val = np.array(2).astype(np.int)
     self.assertEqual(10, d.eval(feed_dict={p: val}))
コード例 #4
0
 def testControlDependency(self):
   with self.test_session():
     p = array_ops.placeholder_v2(dtypes_lib.int32, shape=[], name="p")
     with ops.control_dependencies([p]):
       c = constant_op.constant(5, dtypes_lib.int32)
     d = math_ops.multiply(p, c)
     val = np.array(2).astype(np.int)
     self.assertEqual(10, d.eval(feed_dict={p: val}))
コード例 #5
0
 def testControlDependency(self):
   with self.test_session():
     p = array_ops.placeholder_v2(dtypes_lib.int32, shape=[], name="p")
     with ops.control_dependencies([p]):
       c = constant_op.constant(5, dtypes_lib.int32)
     d = math_ops.multiply(p, c)
     val = np.array(2).astype(np.int)
     self.assertEqual(10, d.eval(feed_dict={p: val}))
コード例 #6
0
ファイル: constant_op_test.py プロジェクト: brchiu/tensorflow
    def testPartialShape(self):
        with self.test_session():
            p = array_ops.placeholder_v2(tf.float32, shape=[None, 3], name="p")
            p_identity = tf.identity(p)
            feed_array = np.random.rand(10, 3)
            self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}), feed_array)

            with self.assertRaisesWithPredicateMatch(ValueError, lambda e: "Cannot feed value of shape" in str(e)):
                p_identity.eval(feed_dict={p: feed_array[:5, :2]})
コード例 #7
0
ファイル: constant_op_test.py プロジェクト: brchiu/tensorflow
 def testUnknownShape(self):
     with self.test_session():
         p = array_ops.placeholder_v2(tf.float32, shape=None, name="p")
         p_identity = tf.identity(p)
         # can feed anything
         feed_array = np.random.rand(10, 3)
         self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}), feed_array)
         feed_array = np.random.rand(4, 2, 5)
         self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}), feed_array)
コード例 #8
0
ファイル: constant_op_test.py プロジェクト: brchiu/tensorflow
    def testDtype(self):
        with self.test_session():
            p = array_ops.placeholder_v2(tf.float32, shape=None, name="p")
            p_identity = tf.identity(p)
            feed_array = np.random.rand(10, 10)
            self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}), feed_array)

            with self.assertRaisesOpError("must feed a value for placeholder tensor 'p' with dtype float"):
                p_identity.eval()
コード例 #9
0
 def testUnknownShape(self):
     with self.test_session():
         p = array_ops.placeholder_v2(tf.float32, shape=None, name="p")
         p_identity = tf.identity(p)
         # can feed anything
         feed_array = np.random.rand(10, 3)
         self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}),
                             feed_array)
         feed_array = np.random.rand(4, 2, 5)
         self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}),
                             feed_array)
コード例 #10
0
  def testDtype(self):
    with self.test_session():
      p = array_ops.placeholder_v2(dtypes_lib.float32, shape=None, name="p")
      p_identity = array_ops.identity(p)
      feed_array = np.random.rand(10, 10)
      self.assertAllClose(
          p_identity.eval(feed_dict={p: feed_array}), feed_array)

      with self.assertRaisesOpError(
          "must feed a value for placeholder tensor 'p' with dtype float"):
        p_identity.eval()
コード例 #11
0
    def testPartialShape(self):
        with self.test_session():
            p = array_ops.placeholder_v2(tf.float32, shape=[None, 3], name="p")
            p_identity = tf.identity(p)
            feed_array = np.random.rand(10, 3)
            self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}),
                                feed_array)

            with self.assertRaisesWithPredicateMatch(
                    ValueError,
                    lambda e: "Cannot feed value of shape" in str(e)):
                p_identity.eval(feed_dict={p: feed_array[:5, :2]})
コード例 #12
0
ファイル: constant_op_test.py プロジェクト: brchiu/tensorflow
    def testShape(self):
        with self.test_session():
            p = array_ops.placeholder_v2(tf.float32, shape=(10, 10), name="p")
            p_identity = tf.identity(p)
            feed_array = np.random.rand(10, 10)
            self.assertAllClose(p_identity.eval(feed_dict={p: feed_array}), feed_array)

            with self.assertRaisesOpError(
                "must feed a value for placeholder tensor 'p' with dtype float and " r"shape \[10,10\]"
            ):
                p_identity.eval()

            with self.assertRaisesWithPredicateMatch(ValueError, lambda e: "Cannot feed value of shape" in str(e)):
                p_identity.eval(feed_dict={p: feed_array[:5, :5]})
コード例 #13
0
  def testShape(self):
    with self.test_session():
      p = array_ops.placeholder_v2(dtypes_lib.float32, shape=(10, 10), name="p")
      p_identity = array_ops.identity(p)
      feed_array = np.random.rand(10, 10)
      self.assertAllClose(
          p_identity.eval(feed_dict={p: feed_array}), feed_array)

      with self.assertRaisesOpError(
          "must feed a value for placeholder tensor 'p' with dtype float and "
          r"shape \[10,10\]"):
        p_identity.eval()

      with self.assertRaisesWithPredicateMatch(
          ValueError, lambda e: "Cannot feed value of shape" in str(e)):
        p_identity.eval(feed_dict={p: feed_array[:5, :5]})
コード例 #14
0
 def testBadShape(self):
   with self.assertRaises(ValueError):
     array_ops.placeholder_v2(tf.float32, shape=(-1, 10))
コード例 #15
0
 def testScalarShape(self):
   with self.test_session():
     p = array_ops.placeholder_v2(tf.float32, shape=[], name="p")
     p_identity = tf.identity(p)
     self.assertAllClose(p_identity.eval(feed_dict={p: 5}), 5)