环境
Install Python on your computer system
Install ImageAI and its dependencies
依赖
2.tensorflow==1.14.0
i. TensorFlow
pip3 install tensorflow==1.14.0
ii. OpenCV
pip3 install opencv-python
iii. Keras
pip3 install keras
iv. ImageAI
pip3 install imageai --upgrade
源码
#FirstDetection.py
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path , "./resnet50_coco_best_v2.0.1.h5"))
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:
print(eachObject["name"] + " : " + str(eachObject["percentage_probability"]) )
代码都是网上来的。只改了输出的str
原文地址: https://towardsdatascience.com/object-detection-with-10-lines-of-code-d6cb4d86f606
正文完