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))
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)
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}))
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}))
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]})
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)
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()
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()
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]})
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]})
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]})
def testBadShape(self): with self.assertRaises(ValueError): array_ops.placeholder_v2(tf.float32, shape=(-1, 10))
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)