I脳波信号に1D CNNを実装しようとしている、と私は1d conv error - 入力とフィルタのサイズが同じである必要がありますか?
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](バッチサイズ、in_width、チャンネル)私は、これは出力テンソルであると考えてい第1のConv1d層の場合
[50、1,64](filter_width、in_channels、out_channels)は、最初のConv1dウェイトの形状です。
なぜ492と1は等しい必要がありますか?私は問題を見つけるのを止めているエラーを理解していません。テンソルフローと任意の助けを借りて私の第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)
ありがとうございます!それが問題でした。あなたの助けに感謝。 –