前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用ImageAI快速构建常见对象检测应用

使用ImageAI快速构建常见对象检测应用

作者头像
OpenCV学堂
发布2019-12-09 16:58:40
9700
发布2019-12-09 16:58:40
举报

微信公众号:OpenCV学堂 关注获取更多计算机视觉与深度学习知识

ImageAI介绍

纯Python的快速对象检测训练与测试平台,基于tensorflow+opencv构建,支持

  • RetinaNet
  • YOLOv3
  • TinyYOLOv3

在COCO数据集上预训练模型的调用,同时支持自定义对象训练与导出。支持

  • 图像分类
  • 对象检测
  • 视频对象检测与跟踪

安装ImageAI

ImageAI的后台依赖tensorflow框架与keras,所以需要首先安装tensoflow,当前还不支持tensorflow2.0版本

  • tensorflow 1.4.x以上版本
  • opencv-python

安装imageai,只需要执行如下命令行即可

代码语言:javascript
复制
pip install imageai

代码演示

1. 图像分类

代码语言:javascript
复制
from imageai.Prediction import ImagePrediction
import os

execution_path = os.getcwd()

prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, "resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
prediction.loadModel()

predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
for eachPrediction, eachProbability in zip(predictions, probabilities):
    print(eachPrediction , " : " , eachProbability)

图像

运行输出:

convertible : 52.459555864334106 sports_car : 37.61284649372101 pickup : 3.1751200556755066 car_wheel : 1.817505806684494 minivan : 1.7487050965428352

2. 对象检测

代码语言:javascript
复制
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("--------------------------------")

运行输出:

github地址

https://github.com/OlafenwaMoses/ImageAI/

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-12-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 OpenCV学堂 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ImageAI介绍
  • 安装ImageAI
  • 代码演示
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档