[英]ValueError: Dimensions must be equal, but are 1 and 3 for 'Conv2D' (op: 'Conv2D') with input shapes: [1,400,400,1], [1,3,3,1]
[英]Dimensions must be equal, but are 1 and 2 for 'Conv2D' (op: 'Conv2D') with input shapes: [2,2,2,1], [1,1,2,1]
我正在嘗試通過此代碼學習Conv2d。
基於conv2d doc:
輸入的形狀= [批處理,in_height,in_width,in_channels]
過濾器的形狀= [filter_height,filter_width,in_channels,out_channels]
當我嘗試運行它時,它向我發送了錯誤消息。
#-*-coding:utf-8-*-
import tensorflow as tf
input_batch = tf.constant([
[
[[0.0], [1.0]],
[[2.0], [3.0]]
],
[
[[2.0], [4.0]],
[[6.0], [8.0]]
]
])
kernel = tf.constant([
[
[[1.0], [2.0]],
]
])
conv2d = tf.nn.conv2d(input_batch, kernel, strides=[1, 1, 1, 1],padding='SAME')
with tf.Session() as sess:
sess.run(conv2d)
錯誤信息:
ValueError: Dimensions must be equal, but are 1 and 2 for 'Conv2D' (op: 'Conv2D') with input shapes: [2,2,2,1], [1,1,2,1].
正如您在輸入和過濾器的形狀中提到的in_channels
,兩種情況下的in_channels
應該相同。 但是input
的大小為[2, 2, 2, 1]
in_channel
[2, 2, 2, 1]
,過濾器的大小為[1, 1, 2, 1]
in_channel
[1, 1, 2, 1]
並且在輸入中聲明的in_channel
為1,但對於過濾器,其值為2。這就是錯誤的原因:
尺寸必須相等,但對於'Conv2D'(op:'Conv2D')必須為1和2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.