Tensorflow:将占位符用于`pool_size`参数时出错

时间:2019-03-05 12:01:58

标签: python tensorflow

我想合并图像以降低其分辨率。我希望池大小以及跨度是动态的。但是,我不断收到以下错误:

ValueError: The `pool_size` argument must be a tuple of 2 integers.
Received: [<tf.Tensor 'Placeholder_1:0' shape=<unknown> dtype=int32>, 
<tf.Tensor 'Placeholder_2:0' shape=<unknown> dtype=int32>] including element
Tensor("Placeholder_1:0", dtype=int32) of type <class 
'tensorflow.python.framework.ops.Tensor'>

以某种方式使用

px_ = tf.placeholder(tf.int32)
py_ = tf.placeholder(tf.int32)

传递池大小并大步进入我的函数会导致错误。但是为什么它不起作用?

这是我的代码:

import numpy as np
import tensorflow as tf

in_width, in_height = 10, 10
R = np.random.rand(10000, in_width, in_height)
px, py = 5,5

def my_pool(R, px, py):
    # Reshape [N,W,H,C]
    X = tf.reshape(R, [tf.shape(R)[0], tf.shape(R)[1], tf.shape(R)[2], 1])
    # Pooling
    return tf.layers.average_pooling2d(X, pool_size=[px,py], strides=[px,py], padding="same", data_format='channels_last')

R_ = tf.placeholder(tf.float32, [None, in_width, in_height])
px_ = tf.placeholder(tf.int32)
py_ = tf.placeholder(tf.int32)

pooling = my_pool(R_, px_, py_)

with tf.Session() as sess:
    print(sess.run(pooling, feed_dict={R_:R, px_:px, py_:py}).shape)

0 个答案:

没有答案