Dimensions must be equal, but are 64 and 32 for ‘conv1d/Conv2D’
tensorflow一维卷积踩过的坑
今天用tensorflow做一维卷积的时候总是报错
‘Dimensions must be equal, but are 64 and 32 for ‘conv1d/Conv2D’
很是头疼,在网上找了很久,也没有详细介绍conv1函数的文章,就自己调试,总算知道conv1函数中value和filters的格式了
官方给出的文档是这样的
tf.nn.conv1d(
value,
filters,
stride,
padding,
use_cudnn_on_gpu=None,
data_format=None,
name=None
)
Args:
value: A 3D Tensor. Must be of type float16, float32, or float64.
filters: A 3D Tensor. Must have the same type as value.
stride: An integer. The number of entries by which the filter is moved right at each step.
padding: ‘SAME’ or ‘VALID’
use_cudnn_on_gpu: An optional bool. Defaults to True.
data_format: An optional string from “NWC”, “NCW”. Defaults to “NWC”, the data is stored in the order of [batch, in_width, in_channels]. The “NCW” format stores data as [batch, in_channels, in_width].
name: A name for the operation (optional).
但是没有详细说value和filters的格式
value是一个三维的张量,[a, b, c],
其中a是batch_size,也就是每批输入的个数,b是输入的长度,c是输入的宽度。比如我的输入数据的shape是[a,b],需要reshape成[a,b,1]
filters是三维张量,[d,e,f].
其中,d是卷积窗口的长度,要小于b,e是卷积窗口的宽度,必须和c相等,否则会报错,可能是一维卷积默认不再宽度上卷,f是卷积核的个数