基本上这个问题TensorFlow: Is there a way to convert a list with None type to a Tensor?
答案说明了为什么不可能但没有解决方法的原因
我正在尝试制作一个自动编码器,该编码器具有一些污染层,这些污染层被展平为一些完全连接的层并重新扩展到原始尺寸。但是,当我尝试将扁平化层的输出扩展为张量时,遇到了问题Tried to convert 'shape' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: (?, 14, 32, 128)
这基本上就是网络的样子
X=tf.placeholder(tf.float32,shape=[None, height, width, channel])
conv = Conv2D(32, (3, 3), activation='relu', padding='same')(X)
h1=actf(tf.matmul(conv,w)+b)
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, conv.shape))
如何在不指定批处理大小的情况下重塑中间层的输出?
我也尝试过
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, [None, 14, 32, 128]))
出现以下错误Failed to convert object of type <class 'list'> to Tensor. Contents: [None, 14, 32, 128]
答案 0 :(得分:1)
您应使用-1
而不是None
来指定应自动计算的尺寸。尝试tf.reshape(h1, [-1] + conv.shape.as_list()[1:])
。