from imageai.Classification.Custom import CustomImageClassification
import os
execution_path = os.getcwd()
def predict():
prediction = CustomImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(os.path.join(execution_path, "model_ex-008_acc-0.360000.h5"))
prediction.setJsonPath(os.path.join(execution_path, "model_class.json"))
prediction.loadModel(num_objects=10)
predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "9.jpg"), result_count=5)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction, " : ", eachProbability)
if __name__ == '__main__':
predict()
结果:
换其它图片检测,结果也是这个。