當前位置: 首頁>>代碼示例>>Python>>正文


Python tensorflow.space_to_batch_nd方法代碼示例

本文整理匯總了Python中tensorflow.space_to_batch_nd方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.space_to_batch_nd方法的具體用法?Python tensorflow.space_to_batch_nd怎麽用?Python tensorflow.space_to_batch_nd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.space_to_batch_nd方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _checkGrad

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _checkGrad(self, x, block_shape, paddings):
    block_shape = np.array(block_shape)
    paddings = np.array(paddings).reshape((len(block_shape), 2))
    with self.test_session():
      tf_x = tf.convert_to_tensor(x)
      tf_y = tf.space_to_batch_nd(tf_x, block_shape, paddings)
      epsilon = 1e-5
      ((x_jacob_t, x_jacob_n)) = tf.test.compute_gradient(
          tf_x,
          x.shape,
          tf_y,
          tf_y.get_shape().as_list(),
          x_init_value=x,
          delta=epsilon)

    self.assertAllClose(x_jacob_t, x_jacob_n, rtol=1e-2, atol=epsilon) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:18,代碼來源:spacetobatch_op_test.py

示例2: _testPad

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _testPad(self, inputs, block_shape, paddings, outputs):
    block_shape = np.array(block_shape)
    paddings = np.array(paddings).reshape((len(block_shape), 2))
    for use_gpu in [False, True]:
      with self.test_session(use_gpu=use_gpu):
        # outputs = space_to_batch(inputs)
        x_tf = tf.space_to_batch_nd(tf.to_float(inputs), block_shape, paddings)
        self.assertAllEqual(x_tf.eval(), outputs)
        # inputs = batch_to_space(outputs)
        x_tf = tf.batch_to_space_nd(tf.to_float(outputs), block_shape, paddings)
        self.assertAllEqual(x_tf.eval(), inputs) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:spacetobatch_op_test.py

示例3: _testStaticShape

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _testStaticShape(self, input_shape, block_shape, paddings, error):
    block_shape = np.array(block_shape)
    paddings = np.array(paddings)

    # Try with sizes known at graph construction time.
    with self.assertRaises(error):
      _ = tf.space_to_batch_nd(
          np.zeros(input_shape, np.float32), block_shape, paddings) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:10,代碼來源:spacetobatch_op_test.py

示例4: _testDynamicShape

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _testDynamicShape(self, input_shape, block_shape, paddings):
    block_shape = np.array(block_shape)
    paddings = np.array(paddings)
    # Try with sizes unknown at graph construction time.
    input_placeholder = tf.placeholder(tf.float32)
    block_shape_placeholder = tf.placeholder(tf.int32, shape=block_shape.shape)
    paddings_placeholder = tf.placeholder(tf.int32)
    t = tf.space_to_batch_nd(input_placeholder, block_shape_placeholder,
                             paddings_placeholder)

    with self.assertRaises(ValueError):
      _ = t.eval({input_placeholder: np.zeros(input_shape, np.float32),
                  block_shape_placeholder: block_shape,
                  paddings_placeholder: paddings}) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:spacetobatch_op_test.py

示例5: testUnknown

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def testUnknown(self):
    # Verify that input shape and paddings shape can be unknown.
    _ = tf.space_to_batch_nd(
        tf.placeholder(tf.float32),
        tf.placeholder(tf.int32, shape=(2,)),
        tf.placeholder(tf.int32))

    # Only number of input dimensions is known.
    t = tf.space_to_batch_nd(
        tf.placeholder(tf.float32, shape=(None, None, None, None)),
        tf.placeholder(tf.int32, shape=(2,)),
        tf.placeholder(tf.int32))
    self.assertEqual(4, t.get_shape().ndims)

    # Dimensions are partially known.
    t = tf.space_to_batch_nd(
        tf.placeholder(tf.float32, shape=(None, None, None, 2)),
        tf.placeholder(tf.int32, shape=(2,)),
        tf.placeholder(tf.int32))
    self.assertEqual([None, None, None, 2], t.get_shape().as_list())

    # Dimensions are partially known.
    t = tf.space_to_batch_nd(
        tf.placeholder(tf.float32, shape=(3, None, None, 2)), [2, 3],
        tf.placeholder(tf.int32))
    self.assertEqual([3 * 2 * 3, None, None, 2], t.get_shape().as_list())

    # Dimensions are partially known.
    t = tf.space_to_batch_nd(
        tf.placeholder(tf.float32, shape=(3, None, 2, 2)), [2, 3],
        [[1, 1], [0, 1]])
    self.assertEqual([3 * 2 * 3, None, 1, 2], t.get_shape().as_list())

    # Dimensions are fully known.
    t = tf.space_to_batch_nd(
        tf.placeholder(tf.float32, shape=(3, 2, 3, 2)), [2, 3],
        [[1, 1], [0, 0]])
    self.assertEqual([3 * 2 * 3, 2, 1, 2], t.get_shape().as_list()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:40,代碼來源:spacetobatch_op_test.py

示例6: _generic_public_test

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _generic_public_test(t, block_shape, paddings):
        with tf.Session() as sess:
            out = tf.space_to_batch_nd(t, block_shape=block_shape, paddings=paddings)
            actual = sess.run(out)

        with tfe.protocol.Pond() as prot:
            b = prot.define_public_variable(t)
            out = prot.space_to_batch_nd(b, block_shape=block_shape, paddings=paddings)
            with tfe.Session() as sess:
                sess.run(tf.global_variables_initializer())
                final = sess.run(out)

        np.testing.assert_array_almost_equal(final, actual, decimal=3) 
開發者ID:tf-encrypted,項目名稱:tf-encrypted,代碼行數:15,代碼來源:ops_test.py

示例7: _generic_private_test

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _generic_private_test(t, block_shape, paddings):
        with tf.Session() as sess:
            out = tf.space_to_batch_nd(t, block_shape=block_shape, paddings=paddings)
            actual = sess.run(out)

        with tfe.protocol.Pond() as prot:
            b = prot.define_private_variable(t)
            out = prot.space_to_batch_nd(b, block_shape=block_shape, paddings=paddings)
            with tfe.Session() as sess:
                sess.run(tf.global_variables_initializer())
                final = sess.run(out.reveal())

        np.testing.assert_array_almost_equal(final, actual, decimal=3) 
開發者ID:tf-encrypted,項目名稱:tf-encrypted,代碼行數:15,代碼來源:ops_test.py

示例8: _generic_masked_test

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _generic_masked_test(t, block_shape, paddings):
        with tf.Session() as sess:
            out = tf.space_to_batch_nd(t, block_shape=block_shape, paddings=paddings)
            actual = sess.run(out)

        with tfe.protocol.Pond() as prot:
            b = prot.mask(prot.define_private_variable(t))
            out = prot.space_to_batch_nd(b, block_shape=block_shape, paddings=paddings)
            with tfe.Session() as sess:
                sess.run(tf.global_variables_initializer())
                final = sess.run(out.reveal())

        np.testing.assert_array_almost_equal(final, actual, decimal=3) 
開發者ID:tf-encrypted,項目名稱:tf-encrypted,代碼行數:15,代碼來源:ops_test.py

示例9: test_space_to_batch_nd_convert

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def test_space_to_batch_nd_convert(self):
        test_input = np.ones([2, 2, 4, 1])
        self._test_with_ndarray_input_fn(
            "space_to_batch_nd", test_input, protocol="Pond"
        ) 
開發者ID:tf-encrypted,項目名稱:tf-encrypted,代碼行數:7,代碼來源:convert_test.py

示例10: _construct_space_to_batch_nd

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _construct_space_to_batch_nd(input_shape):
    a = tf.placeholder(tf.float32, shape=input_shape, name="input")
    block_shape = tf.constant([2, 2], dtype=tf.int32)
    paddings = tf.constant([[0, 0], [2, 0]], dtype=tf.int32)
    x = tf.space_to_batch_nd(a, block_shape=block_shape, paddings=paddings)
    return x, a 
開發者ID:tf-encrypted,項目名稱:tf-encrypted,代碼行數:8,代碼來源:convert_test.py

示例11: _test_space_to_batch_nd

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _test_space_to_batch_nd(input_shape, block_shape, paddings, dtype='int32'):
    data = np.random.uniform(0, 5, size=input_shape).astype(dtype)

    with tf.Graph().as_default():
        in_data = tf.placeholder(shape=input_shape, dtype=dtype)
        out = tf.space_to_batch_nd(in_data, block_shape, paddings)

        compare_tf_with_tvm(data, in_data.name, out.name) 
開發者ID:apache,項目名稱:incubator-tvm,代碼行數:10,代碼來源:test_forward.py

示例12: _test_space_to_batch_nd_infer_paddings

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import space_to_batch_nd [as 別名]
def _test_space_to_batch_nd_infer_paddings(input_shape, block_shape, dtype='int32'):
    data = np.random.uniform(0, 5, size=input_shape).astype(dtype)
    padding_np = np.array([0, 1]).astype(np.int32).reshape((1, 2))
    with tf.Graph().as_default():
        in_data = tf.placeholder(shape=input_shape, dtype=dtype)
        const1 = tf.constant(padding_np, dtype=tf.int32)
        # make paddings an input to tf.transpose, but not an input to the graph,
        # so it can be extracted with infer_value_simulated
        paddings = tf.reverse(const1, axis=[-1])
        out = tf.space_to_batch_nd(in_data, block_shape, paddings)
        compare_tf_with_tvm(data, in_data.name, out.name) 
開發者ID:apache,項目名稱:incubator-tvm,代碼行數:13,代碼來源:test_forward.py


注:本文中的tensorflow.space_to_batch_nd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。