【发布时间】:2021-05-29 15:35:31
【问题描述】:
我得到一个错误是 tensorflow/keras 说我只有一个输出,所以我应该在密集层有一个 (1) 而不是 (4),我制作了一组标签
#goes through files and turns images into arrays
#going through each folder
for categories in os.listdir('train'):
category = str('train/' + folder)
#going through each file in folder
for files in os.listdir(category):
#creates file path
filePath = category + '/' + files
image = keras.preprocessing.image.load_img(filePath)
imageArr = keras.preprocessing.image.img_to_array(image)
features.append(imageArr)
# makes labels
# iterates over folders
for names in os.listdir('train'):
label = 0
#increment as value of current folder
label += 1
for files in os.listdir('train/' + names):
#adds a number per label
labels.append(label)
features = np.asarray(features)
labels = np.asarray(labels)
model = keras.Sequential()
model.add(Conv2D(30, (20, 20), input_shape=(600, 600, 3), activation='relu'))
model.add(Flatten())
model.add(Dense(4, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
我得到的错误表明,当我知道我有 4 个时,我只有一个输出,因为当我打印“标签”时,我得到一系列从 1 到 4 的数字,是因为它们都在一个数组中吗?感谢您的帮助
错误:
ValueError: logits and labels must have the same shape ((None, 4) vs (None, 1))
【问题讨论】:
-
你有几节课?
标签: python numpy tensorflow keras