且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TensorFlow提要一个整数

更新时间:2023-11-10 16:08:34

我不确定这是***的方法,但是您可以使用:

I'm not sure that it's the best way, but you can get dynamically the shape of self.input_x in a list with :

input_shape = tf.unpack(tf.shape(self.input_x))

tf.shape(self.input_x)为您提供一个表示self形状的张量.input_x和f.unpack将其转换为张量列表.

tf.shape(self.input_x) give you a Tensor representing the shape of self.input_x and f.unpack convert it to a list of Tensor.

现在,您可以使用来创建最大池节点:

Now you can create your max pooling node with :

pooled = tf.nn.max_pool(
                h,
                ksize=tf.pack([1, input_size[1] - filter_size + 1, 1, 1]),
                strides=[1, 1, 1, 1],
                padding='VALID',
                name="pool")

(如果需要input_x的第二维)

(if you needed the 2nd dimension of input_x)