1.安装依赖
yum install mesa-libGL.x86_64

pip3 install tensorflow==2.4.0
pip3 install keras
pip3 install pandas
pip3 install numpy
pip3 install pillow
pip3 install scipy
pip3 install h5py
pip3 install matplotlib
pip3 install opencv-python
pip3 install keras-resnet
pip3 install imageai --upgrade
2.下载模型
# 下载一张图片
# wget -O image3.jpg  https://xxx/example.png
wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5
3.参考示例
from imageai.Detection import ObjectDetection
import os
import time

execution_path = os.getcwd()

detector = ObjectDetection()
# detector.setModelTypeAsRetinaNet()
detector.setModelTypeAsYOLOv3()

# 载入已训练好的文件
# detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.1.0.h5"))
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

# 将检测后的结果保存为新图片
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path, "image1.jpg"),
                                             output_image_path=os.path.join(execution_path, "image3new.jpg"))


for eachObject in detections:
    print(eachObject["name"], " : ", eachObject["percentage_probability"], " : ",
          eachObject["box_points"])  ##预测物体名:预测概率:物体两点坐标(左上,右下)
    print("--------------------------------")

在这里插入图片描述
参考:https://blog.csdn.net/qingfengxd1/article/details/108203954
参考:https://imageai.readthedocs.io/en/latest/detection/
参考:https://blog.csdn.net/zkt286468541/article/details/81040274

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐