如何使用Keras模型预测图像?

时间:2020-03-17 03:46:24

标签: keras siamese-network

我已经完成了训练过程,并获得了.hdf5格式的模型

我使用的神经网络是暹罗卷积神经网络。

验证时,预测的图像是来自我的测试文件夹的随机图像。 我在测试时使用

test_alphabets = glob('{}/TEST/*'.format(dataset_dirname))

testset={}
for alph in test_alphabets:
    dirs = glob('{}/*'.format(alph))
    alphabet = {}
    for dirname in dirs:
        alphabet[dirname] = glob('{}/*'.format(dirname))
    testset[alph] = alphabet        

然后,使用

显示结果
display_validation_test(siamese_model1, testset)

结果是这样的 enter image description here 输入我想要的图像,然后更早地使用.h5模型显示适当的图像,该如何进行测试过程?

1 个答案:

答案 0 :(得分:0)

  1. 首先使用与您训练过的模型相同的体系结构创建模型(keras.Model或keras.Sequential实例)。
  2. 从.h5文件model.load_weights('your_weight_file.h5')加载权重
  3. 阅读您的图片。如果是单个图像,请确保添加 1 作为批次尺寸。
  4. 致电预测prediction = model.predict(images)