问题描述
我正在尝试制作一个 CNN 模型,该模型采用可变大小的输入(句子矩阵)并为后续的全连接层生成固定大小的输出(类似于本文).
I am trying to make a CNN model that takes variable size input (sentence matrix) and produce a fixed size output for a subsequent fully connected layer (similar to this paper).
我正在尝试为最大池化层实现动态内核大小,因此我需要在运行时输入的形状来实现这一点.
I am trying to implement a dynamic kernel size for a max pooling layer so I need the shape of the input at runtime to achieve this.
input = tf.placeholder(tf.float32)
# convolution layer here ....
tf.nn.max_pool(convolution_output, ksize=[1, s, 1, 1],
strides=[1, 1, 1, 1], padding='VALID')
s
in ksize=[1, s, 1, 1]
应该从输入的形状中推断出来.
s
in ksize=[1, s, 1, 1]
should be inferred from the input shape.
但是,我找不到使用 Tensorflow 的方法.
However, I can't find a way to do it with Tensorflow.
有人知道怎么做吗?
推荐答案
我知道这是一个旧线程,但对于正在寻找解决方案的人来说.它已在 tensorflow 1.4.0
I know it's an old thread, but for people who are looking for a solution. It has been implemented in tensorflow 1.4.0
tf.nn.max_pool() 现在将一维张量作为输入,而不是旧版本中的整数列表.所以你可以使用占位符作为 ksize 的参数.
tf.nn.max_pool() now takes 1d tensor as an input as opposed to a list of ints in the older versions. So you can use a placeholder as the argument of ksize.
这篇关于可变尺寸卷积神经网络输入和固定输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!