以下错误的原因是给模型feed数据的时候shape不一致
1、错误1如下图所示:
报错程序:
x = tf.placeholder(tf.float32, [None,128*128*3])
batch_images = tf.reshape(x, [-1, 128, 128, 3])
修改后程序:
x = tf.placeholder(tf.float32, [None,128,128,3])
batch_images = tf.reshape(x, [-1, 128, 128, 3])
2、错误2如下图所示:
报错程序:
label = tf.placeholder(tf.float32,[batch_size,19])
for step in range(total_batch):
image0, label0 = sess.run([image_batch, label_batch])
train_feed_dict = {
x: image0,
label: label0,
learning_rate: epoch_learning_rate,
training_flag : True
}
修改后程序:
label = tf.placeholder(tf.float32,[batch_size,19])
for step in range(total_batch):
image0, label0 = sess.run([image_batch, label_batch])
label0 = one_hot(label0,19)
train_feed_dict = {
x: image0,
label: label0,
learning_rate: epoch_learning_rate,
training_flag : True
}
def one_hot(labels,Label_class):
one_hot_label = np.array([[int(i == int(labels[j]))
for i in range(Label_class)]
for j in range(len(labels))])
return one_hot_label