经典的目标检测算法有哪些?

发布于:2024-04-29 ⋅ 阅读:(28) ⋅ 点赞:(0)

一、经典的目标检测算法有哪些?

目标检测算法根据其处理流程可以分为两大类:One-Stage(单阶段)算法和Two-Stage(两阶段)算法。以下是一些经典的目标检测算法:

单阶段算法:

  • YOLO (You Only Look Once): 是一种非常快速的目标检测算法,它将目标检测任务作为回归问题来解决,直接在图像中预测边界框和类别概率。
  • SSD (Single Shot MultiBox Detector): 通过在不同尺度的特征图上进行检测,能够有效地检测出不同大小的目标,速度和精度都较为平衡。
  • RetinaNet: 引入了Focal Loss来解决类别不平衡问题,提高了模型对于难分样本的识别能力,从而提升了检测性能。

两阶段算法:

  • R-CNN (Region-based Convolutional Neural Networks): 是最早的深度学习目标检测模型之一,它首先生成候选区域,然后对每个区域进行卷积神经网络特征提取,并使用支持向量机(SVM)进行分类,最后通过边界框回归精确定位目标位置。
  • Fast R-CNN: 在R-CNN的基础上进行了改进,使用全卷积网络提取图像特征,并通过区域池化操作将不同尺寸的候选区域对齐到固定尺寸的特征图上,然后进行分类和边界框回归。
  • Faster R-CNN: 引入了区域提议网络(RPN)来生成高质量的候选区域,进一步提高了检测的速度和精度。

这些算法各有优势,选择哪种算法通常取决于具体应用场景中对速度和精度的要求。

二、YOLO 的简单例子

from ultralytics import YOLO

# 加载模型
model = YOLO('E:\PycharmProjects\\yolov8n.pt')

# 识别图片的物体
results = model(['E:\\testImage\\cat1.png', 'E:\\testImage\\heixiong.jpg'])

# 处理图片列表
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    result.show()  # display to screen
    result.save(filename='result.jpg')  # save to disk
输出的结果图片:

 

模型下载地址:

Detect - Ultralytics YOLOv8 DocsOfficial documentation for YOLOv8 by Ultralytics. Learn how to train, validate, predict and export models in various formats. Including detailed performance stats.icon-default.png?t=N7T8https://docs.ultralytics.com/tasks/detect/

三、“糟心的PIP源

安装:

pip install ultralytics

但是总是很糟心的timeout

换国内的源速度杠杠的,分分钟搞定!!!

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

 国内的其他pip源:

# 清华

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 阿里

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

# 腾讯

pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple

# 豆瓣

pip config set global.index-url http://pypi.douban.com/simple/ 

四、如果PIP不可用,咋办?

如果PIP不可用?请检查PIP的路径是否加入到path(本说明仅限windows平台)

报错:

pip : 无法将“pip”项识别为 cmdlet

配置成功后测试: