简体   繁体   English

多通道卷积神经网络——负维尺寸误差

[英]Multi channel Convolutional neural network - negative dimension size error

I want to design, multi channel CNN.我想设计,多通道CNN。

I got a error message in first Conv2d step.我在第一个 Conv2d 步骤中收到一条错误消息。 (in figure, first layer to second layer) (图中,第一层到第二层)

My code is as bellows我的代码如下

_concat_embeded = keras.layers.concatenate([_embeding1, _embeding2], axis= -1)
_biCH_embeded = keras.layers.Reshape((2, self.lexicalMaxLength, charWeights.shape[1]))(_concat_embeded)
_1stConv = keras.layers.Conv2D(filters=512, kernel_size=(5, charWeights.shape[1]),
                               activation=tf.nn.relu)(_biCH_embeded)

Shape at _biCH_embeded is [? _biCH_embeded 处的形状是 [? 2, 131 ,131] (my embeddings have 131 dimension = charWeights.shape[1]) 2, 131 ,131](我的嵌入有 131 个维度 = charWeights.shape[1])

I want to generate 512 filters, which has (5, 131) shape.我想生成 512 个过滤器,它们具有 (5, 131) 形状。

Then, I've got a message, "Negative dimension size caused by subtracting 5 from 2 for 'conv2d_1/convolution' (op: 'Conv2D') with input shapes: [?,2,33,131], [5,131,131,512]"然后,我收到一条消息,“由输入形状为 [?,2,33,131], [5,131,131,512] 的 'conv2d_1/convolution'(操作:'Conv2D')从 2 中减去 5 导致的负尺寸大小”

Where is problem?问题出在哪里?

Y. Kim 用于文本分类的多通道 CNN

I find the issue.我找到了问题。

I reshaped my tensor with "channel_first" rule (2, 133, 133)我用“channel_first”规则重塑了我的张量 (2, 133, 133)

But my Keras config is set by "channel_last"但是我的 Keras 配置是由“channel_last”设置的

I change the reshape rule to "channel_last" (133,133,2)and training is running now.我将重塑规则更改为“channel_last”(133,133,2)并且现在正在运行培训。

(If you want change the Keras config, look at "~/.keras/keras.json") (如果您想更改 Keras 配置,请查看“~/.keras/keras.json”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM