1. 打开Colaboratory
2. 点击左上角的【文件】【新建笔记本】
3. 点击菜单【代码执行程序】【更改运行时类型】,修改为为GPU 4. !wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5 5. !wget https://github.com/OlafenwaMoses/ImageAI/raw/master/data-images/image2.jpg 6. !pip install imageai 7. 进行代码测试,将生成Image2new.jpg
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image2.jpg"), output_image_path=os.path.join(execution_path , "image2new.jpg"), minimum_percentage_probability=30)
for eachObject in detections:
print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("--------------------------------")