欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 人工智能 > chatgpt >内容正文

chatgpt

深度学习和目标检测系列教程 2-凯发k8官方网

发布时间:2024/10/8 chatgpt 0 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 深度学习和目标检测系列教程 2-300:小试牛刀,使用 imageai 进行对象检测 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

@author:runsen

对象检测是一种属于更广泛的计算机视觉领域的技术。它处理识别和跟踪图像和视频中存在的对象。目标检测有多种应用,如人脸检测、车辆检测、行人计数、自动驾驶汽车、安全系统等。imageai提供了非常方便和强大的方法来对图像进行对象检测并从图像中提取每个对象。

imageai

imageai 包含几乎所有最先进的深度学习算法的 python 实现,如retinanet、yolov3和 tinyyolov3。

imageai 使用了对象检测、视频检测和对象跟踪 api,无需访问网络即可调用。imageai 使用预先训练的模型并且可以轻松定制。

imageai 中的objectdetectionimageai 库的类包含使用预训练模型对任何图像或图像集执行对象检测的函数。借助 imageai,可以检测和识别 80 种不同的常见日常物品。

具体官方教程:https://imageai.readthedocs.io/en/latest/detection/index.html

下载链接:https://github.com/olafenwamoses/imageai/releases/download/2.0.2/imageai-2.0.2-py3-none-any.whl

安装imageai 成功后,下载包含将用于对象检测的分类模型的tinyyolov3模型文件。

下载地址:https://github.com/olafenwamoses/imageai/releases/download/1.0/yolo-tiny.h5

下面,我们小试牛刀,使用 imageai 进行对象检测

我们先创建必要的文件夹。

  • object-detection:根文件夹
  • models:存储预先训练的模型
  • input : 存储我们要执行对象检测的图像文件
  • output:存储检测到对象的图像文件

创建文件夹后,object-detection文件夹应具有以下子文件夹:

├── input ├── models └── output

下面创建一个新文件detector.py.,从 imageai 库导入objectdetection类。

from imageai.detection import objectdetection

接下来是创建 class 的实例objectdetection,如下所示:

detector = objectdetection()

指定输入图像、输出图像和模型的路径。

model_path = "./models/yolo-tiny.h5" input_path = "./input/image.jpg" output_path = "./output/newimage.jpg"

实例化objectdetection类后,我们现在可以从类中调用各种函数。该类包含以下功能调用预先训练模式:setmodeltypeasretinanet(),setmodeltypeasyolov3(),和setmodeltypeastinyyolov3()。

我使用预训练tinyyolov3模型,因此我们将使用该setmodeltypeastinyyolov3()函数加载我们的模型。

接下来,将调用函数setmodelpath()。此函数接受一个包含预训练模型路径的字符串:

detector.setmodelpath(model_path)

从detector实例调用函数loadmodel()。它使用setmodelpath()类方法从上面指定的路径加载模型

detector.loadmodel()

要检测图像中的对象,我们需要detectobjectsfromimage使用detector创建的对象。

下面是完整代码

from imageai.detection import objectdetectiondetector = objectdetection()model_path = "./models/yolo-tiny.h5" input_path = "./input/img.png" output_path = "./output/img.png"detector.setmodeltypeastinyyolov3() detector.setmodelpath(model_path) detector.loadmodel() detection = detector.detectobjectsfromimage(input_image=input_path, output_image_path=output_path)for eachitem in detection:print(eachitem["name"] , " : ", eachitem["percentage_probability"])


总结

以上是凯发k8官方网为你收集整理的深度学习和目标检测系列教程 2-300:小试牛刀,使用 imageai 进行对象检测的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图