Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何利用Keras模型对图像进行预测?_Keras_Siamese Network - Fatal编程技术网

如何利用Keras模型对图像进行预测?

如何利用Keras模型对图像进行预测?,keras,siamese-network,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

我已经完成了训练过程,得到了.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)
结果是这样的 如何通过输入所需的图像,然后使用.h5模型显示相应的图像来执行测试过程

  • 首先,使用与您培训的模型相同的体系结构创建模型(keras.model或keras.Sequential instance)
  • 从.h5文件
    model.load_weights('your_weight_file.h5')加载权重
  • 阅读你的图片。如果是单个图像,请确保添加1作为批次维度
  • 调用predict:
    prediction=model.predict(图像)

  • 在3号桥,你能解释一下吗?我不明白。。请帮助meLet's说,你有一个图像加载为numpy矩阵,形状为(128128,3),你需要告诉模型,预测时它是一个单一的图像。您必须将其重塑为(1128128,3),其中1显示批次维度(此处,批次大小为1)。这可以使用
    image=np来完成。展开dims(0,image)