火车图像集40的长度 X_train形状:(40、32、32、3) y_train形状:(40,) 我收到这个错误:无法为张量为'(1,32,32,3)'的张量'Placeholder_17:0'输入形状(40,32,32,3)的值
x = tf.placeholder(dtype=tf.float32, shape=[1, 32, 32, 3])
c1 = tf.layers.conv2d(inputs=x, activation=tf.nn.relu, filters=32,
kernel_size=[5,5], padding='VALID', strides=1)
p1 = tf.layers.max_pooling2d(inputs=c1, pool_size=[2,2], strides=2)
c2 = tf.layers.conv2d(inputs=p1, activation=tf.nn.relu, filters=64,
kernel_size=[5,5], padding='VALID', strides=1)
p2 = tf.layers.max_pooling2d(inputs=c2, pool_size=[2,2], strides=2)
f = tf.contrib.layers.flatten(p2)
fc1 = tf.layers.dense(inputs=f, units=64, activation=tf.nn.relu)
logits = tf.layers.dense(inputs = fc1, units=2)
tf.layers.dropout(inputs = fc1, rate = 0.4)
epochs = 50
for i in range(epochs):
sess.run([trainer], feed_dict={x:X_train/255., y:y_train})
[acc, l] = sess.run([accuracy, loss], feed_dict={x:X_train/255., y:y_train})
print('Epoch %d - Loss: | %.2f Accuracy: %.2f'%(i,np.mean(l),acc))
答案 0 :(得分:0)
您需要使占位符尺寸和输入尺寸匹配。因此,您将必须将placeholder_17设置为(40, 32, 32, 3)
或以尺寸(1, 32, 32, 3)
迭代地将每个图像馈入placeholder_17。