我想實現的EEG信號的1D CNN,和我得到它說1d conv錯誤 - 輸入和過濾器大小需要相同?
ValueError: Dimension 1 in both shapes must be equal, but are 492 and 1 From merging shape 0 with other shapes. for 'MaxPool/input' (op: 'Pack') with > input shapes: [?,492,64], [50,1,64].
錯誤[?,492,64](BATCHSIZE,in_width,頻道)我相信這是輸出張量對於第一個Conv1d層
[50,1,64](filter_width,in_channels,out_channels)是第一個Conv1d權重的形狀。
爲什麼492和1必須相等?我不理解這個阻止我找到問題的錯誤。我的第一週張量流和任何幫助將不勝感激。謝謝。下面導致錯誤的代碼。
# Convolutional Layer 1s
filter_size_1s = 50
num_filters_1s = 64
stride_1s = 6
# Convolutional Layer 2s , 3s , 4s
filter_size_s = 8
num_filters_s = 128
stride_s = 1
#weights and biases
# filter tensor of shape [filter_width, in_channels, out_channels]
W_1s = tf.Variable(tf.truncated_normal([50, 1, 64], stddev=0.1))
B_1s = tf.Variable(tf.constant(0.1, tf.float32, [64]))
W_2s = tf.Variable(tf.truncated_normal([8, 64, 128], stddev=0.1))
B_2s = tf.Variable(tf.constant(0.1, tf.float32, [128]))
W_3s = tf.Variable(tf.truncated_normal([8, 128, 128], stddev=0.1))
B_3s = tf.Variable(tf.constant(0.1, tf.float32, [128]))
W_4s = tf.Variable(tf.truncated_normal([8, 128, 128], stddev=0.1))
B_4s = tf.Variable(tf.constant(0.1, tf.float32, [128]))
def CNN_small(input, phase_test, iteration):
conv1s = new_conv_layer(input, W_1s, B_1s, stride_1s, phase_test, iteration)
max_pool1s = tf.nn.max_pool(conv1s,
ksize=[1, pool_size_1s, 1, 1],
strides=[1, pool_stride_1s, 1, 1],
padding='VALID')
dropout_s = tf.nn.dropout(max_pool1s, dropout_prob)
conv2s = new_conv_layer(dropout_s, W_2s, B_2s, stride_s, phase_test, iteration)
conv3s = new_conv_layer(conv2s, W_3s, B_3s, stride_s, phase_test, iteration)
conv4s = new_conv_layer(conv3s, W_4s, B_4s, stride_s, phase_test, iteration)
max_pool2s = tf.nn.max_pool(conv4s,
ksize=[1, pool_size_2s, 1, 1],
strides=[1, pool_stride_2s, 1, 1],
padding='VALID')
return max_pool2s
def new_conv_layer(input, weights, bias, stride, phase_test, iteration):
conv = tf.nn.conv1d(value=input, filters=weights, stride=stride, padding='VALID') + bias
#bn = batch_norm(conv, biases, phase_test, iteration) #biases added into batch_norm
activation = tf.nn.relu(conv)
return activation, weights
x = tf.placeholder(tf.float32, shape=[None, stage_length], name='x')
x_stage = tf.reshape(x, [-1, stage_length, num_channels]) #batch, in_width, channels
#And the line which is giving the error
#cnn layer
max_pool2s = CNN_small(x_stage, phase_test, iteration)
謝謝!這是問題所在。感謝你的幫助。 –