我的模型的Feed标签存在一些问题。 我只是使用猫/狗图像和37类物种获取了一些数据集。 制作了get_batch函数,该函数返回20个图像矩阵和20个标签。 我不知道如何处理这些批次,以及如何将这些参数传递给我的训练。收到该错误: 无法为形状为((?,37)''的张量'Placeholder_1:0'提供形状(20,)的值
希望在这里找到一些帮助。
float()
batch_y输出:def get_batch(path) :
file_object = open(path, 'r')
num_lines = sum(1 for line in open(path))
list = [random.randint(0,num_lines) for x in range(20)]
x_batch = []
y_labels = []
for x in list:
photoname = linecache.getline(path, x)
photoname = photoname.split(" ")
imagename = photoname[0]
imagearray = read_image(imagepath+"\\"+imagename+".jpg", 28)
y_labels.append(photoname[1])
x_batch.append(imagearray.flatten())
file_object.close()
return x_batch, np.array(y_labels)
def read_image(image_path, size):
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
image = cv2.resize(image,(size,size))
data = np.array(image)
return data
steps = 500
with tf.Session() as sess:
sess.run(init)
batch_size = 20
for i in range(steps) :
batch_x , batch_y = get_batch(path)
print(batch_y)
batch_size = 20
sess.run(train, feed_dict={x: batch_x, y_true: batch_y, hold_prob: 0.5})
if i%100==0 :
print("ON STEP: {}".format(i))
print("Accuracy:")
matchs = tf.euqal(tf.argmax(y_pred,1), tf.argmax(y_true,1))
acc = tf.reduce_mean(tf.cast(matchs,tf.float32))
(随机更改)