Python + AI 图片识别案例

根据CSDN人工智能头条发的《10行代码实现目标检测》的文档,实验了一把图片识别的小例子,挺有意思

原文链接:https://blog.csdn.net/guleileo/article/details/80767966

from imageai.Detection import ObjectDetection   #导入 ImageAI 目标检测类
import os
execution_path = os.getcwd()
detector = ObjectDetection() #定义目标检测类
detector.setModelTypeAsRetinaNet() #将模型的类型设置为 RetinaNet
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5")) #将模型路径设置为 RetinaNet 模型的路径
detector.loadModel() #将模型加载到的目标检测类
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg")) #调用目标检测函数,解析输入的和输出的图像路径
for eachObject in detections:   #迭代执行 detector.detectObjectsFromImage 函数并返回所有的结果
    print(eachObject["name"] + " : " + eachObject["percentage_probability"] ) #打印出所检测到的每个目标的名称及其概率值
Python + AI 图片识别案例_第1张图片

你可能感兴趣的:(Python,AI)