我的keras模型对所有输出给出相同的预测

时间:2019-10-27 16:49:19

标签: python machine-learning keras

我以前曾问过一个问题,认为问题出在我的模型体系结构上,并被告知问题可能出在我的培训/预测代码中。我在那儿张贴了该代码,但没有得到进一步的答案。我的模型显示的精度为0.9530581049962875,损失为0.2506975952616229。但是,当我给它进行图像分类时,每次都会得到相同的预测。图片为64x64,带有三个通道

这是我的训练和预测代码

batch_size = 60
pic_size = 64

train_datagen = ImageDataGenerator()

test_datagen = ImageDataGenerator()

train_generator = train_datagen.flow_from_directory(
        '/DATASET/Training_Samples',
       target_size=(64, 64),
        color_mode='rgb',
        batch_size=batch_size,
        class_mode="categorical",
        shuffle=True)

validation_generator = test_datagen.flow_from_directory(
        '/DATASET/Test_Samples',
        target_size=(64, 64),
        color_mode='rgb',
        batch_size=batch_size,
        class_mode="categorical",
        shuffle=False)



history = model.fit_generator(generator=train_generator,
                            steps_per_epoch=train_generator.n//train_generator.batch_size,
                            epochs=150,
                            validation_data=validation_generator,
                            validation_steps = validation_generator.n//validation_generator.batch_size)

from skimage.transform import resize
import matplotlib.pyplot as plt
%matplotlib inline

my_image = plt.imread('image.jpg')
my_image_resized = resize(my_image, (64,64,3))

import numpy as np
probabilities = model.predict(np.array( [my_image_resized,] ))

print(probabilities)

0 个答案:

没有答案