【发布时间】:2020-05-03 13:59:24
【问题描述】:
我有一个训练有素的 CNN 模型,它可以预测 5 种情绪中的一种:愤怒、厌恶、恐惧、中性或悲伤。 我正在使用
ImageDataGenerator(rescale = 1./255,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True)
和
low_from_directory('../large-dataset-copy/training/',
color_mode='grayscale',
target_size=(48,48),
class_mode = 'categorical',
batch_size = 32)
用于读取和转换图像。
训练后我不知道如何提取模型预测的对应类。 我使用下面的代码来读取和转换图像:
def test_data(img_path):
img_array = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
new_img = cv2.resize(img_array,(48,48))
return new_img.reshape(-1,48,48,1)
img = test_data('Abdullah_Gul_0006.jpg')
emotionClassifier = k.models.load_model('moedel.h5',compile=False)
emotion = emotionClassifier.predict(img)
print(emotion)
这是我得到的输出总是:[[0. 1. 0. 0. 0.]]
print(test_data.class_indices) 的输出也是 {'anger': 0, 'disgust': 1, 'fear': 2, 'neutral': 3, '悲伤':4}
【问题讨论】:
标签: keras label conv-neural-network