Stay Hungry,Stay Foolish!

yolov & ncnn

YOLOv

https://docs.ultralytics.com/

Introducing Ultralytics YOLOv8, the latest version of the acclaimed real-time object detection and image segmentation model. YOLOv8 is built on cutting-edge advancements in deep learning and computer vision, offering unparalleled performance in terms of speed and accuracy. Its streamlined design makes it suitable for various applications and easily adaptable to different hardware platforms, from edge devices to cloud APIs.

Explore the YOLOv8 Docs, a comprehensive resource designed to help you understand and utilize its features and capabilities. Whether you are a seasoned machine learning practitioner or new to the field, this hub aims to maximize YOLOv8's potential in your projects

 

YOLO: A Brief History

YOLO (You Only Look Once), a popular object detection and image segmentation model, was developed by Joseph Redmon and Ali Farhadi at the University of Washington. Launched in 2015, YOLO quickly gained popularity for its high speed and accuracy.

  • YOLOv2, released in 2016, improved the original model by incorporating batch normalization, anchor boxes, and dimension clusters.
  • YOLOv3, launched in 2018, further enhanced the model's performance using a more efficient backbone network, multiple anchors and spatial pyramid pooling.
  • YOLOv4 was released in 2020, introducing innovations like Mosaic data augmentation, a new anchor-free detection head, and a new loss function.
  • YOLOv5 further improved the model's performance and added new features such as hyperparameter optimization, integrated experiment tracking and automatic export to popular export formats.
  • YOLOv6 was open-sourced by Meituan in 2022 and is in use in many of the company's autonomous delivery robots.
  • YOLOv7 added additional tasks such as pose estimation on the COCO keypoints dataset.
  • YOLOv8 is the latest version of YOLO by Ultralytics. As a cutting-edge, state-of-the-art (SOTA) model, YOLOv8 builds on the success of previous versions, introducing new features and improvements for enhanced performance, flexibility, and efficiency. YOLOv8 supports a full range of vision AI tasks, including detection, segmentation, pose estimation, tracking, and classification. This versatility allows users to leverage YOLOv8's capabilities across diverse applications and domains.
  • YOLOv9 introduces innovative methods like Programmable Gradient Information (PGI) and the Generalized Efficient Layer Aggregation Network (GELAN).
  • YOLOv10 is created by researchers from Tsinghua University using the Ultralytics Python package. This version provides real-time object detection advancements by introducing an End-to-End head that eliminates Non-Maximum Suppression (NMS) requirements.

 

中文介绍

https://blog.csdn.net/wjinjie/article/details/107509243

 

yolov5

https://docs.ultralytics.com/zh/models/yolov5/

 

https://blog.csdn.net/m0_37754853/article/details/134814685?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-4-134814685-blog-134059833.235^v43^pc_blog_bottom_relevance_base7&spm=1001.2101.3001.4242.3&utm_relevant_index=5

将训练好的YOLOV5模型转换成ONNX(Open Neural Network Exchange 开放神经网络交换格式)。V5可训练的模型如下:
在这里插入图片描述
4.模型说明如下
YOLOv5s:YOLOv5 系列中最小的模型。“s” 代表 “small”(小)。该模型在计算资源有限的设备上表现最佳,如移动设备或边缘设备。YOLOv5s 的检测速度最快,准确度相对较低。
YOLOv5m:YOLOv5 系列中一个中等大小的模型。“m” 代表 “medium”(中)。YOLOv5m 在速度和准确度之间提供了较好的平衡,适用于具有一定计算能力的设备。
YOLOv5l:YOLOv5 系列中一个较大的模型。“l” 代表 “large”(大)。YOLOv5l 的准确度相对较高,但检测速度较慢。适用于需要较高准确度,且具有较强计算能力的设备。
YOLOv5x:YOLOv5 系列中最大的模型。“x” 代表 “extra large”(超大)。YOLOv5x 在准确度方面表现最好,但检测速度最慢。适用于需要极高准确度的任务,且具有强大计算能力(如 GPU)的设备。
YOLOv5n:YOLOv5 系列中的一个变体,专为 Nano 设备(如 NVIDIA Jetson Nano)进行优化。YOLOv5n 在保持较快速度的同时,提供适用于边缘设备的准确度。
移动端建议选择v5s,也可选择v5m,

 

Smart_Construction application

https://github.com/PeterH0323/Smart_Construction

Base on YOLOv5 Head Person Helmet Detection on Construction Sites,基于目标检测工地安全帽和禁入危险区域识别系统

 

yolov5s 为基础训练,epoch = 50

分类PRmAP0.5
总体 0.884 0.899 0.888
人体 0.846 0.893 0.877
0.889 0.883 0.871
安全帽 0.917 0.921

0.917

 

yolov部署到android

基础(tencent开发的手机端的推理框架)

https://github.com/Tencent/ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform

 

ncnn is a high-performance neural network inference computing framework optimized for mobile platforms. ncnn is deeply considerate about deployment and uses on mobile phones from the beginning of design. ncnn does not have third-party dependencies. It is cross-platform and runs faster than all known open-source frameworks on mobile phone cpu. Developers can easily deploy deep learning algorithm models to the mobile platform by using efficient ncnn implementation, creating intelligent APPs, and bringing artificial intelligence to your fingertips. ncnn is currently being used in many Tencent applications, such as QQ, Qzone, WeChat, Pitu, and so on.

ncnn 是一个为手机端极致优化的高性能神经网络前向计算框架。 ncnn 从设计之初深刻考虑手机端的部署和使用。 无第三方依赖,跨平台,手机端 cpu 的速度快于目前所有已知的开源框架。 基于 ncnn,开发者能够将深度学习算法轻松移植到手机端高效执行, 开发出人工智能 APP,将 AI 带到你的指尖。 ncnn 目前已在腾讯多款应用中使用,如:QQ,Qzone,微信,天天 P 图等。

 

帮助文档

https://ncnn.readthedocs.io/en/latest/index.html

 

编译文件

https://github.com/Tencent/ncnn/releases?page=2

 

使用demo

https://github.com/Tencent/ncnn/wiki/

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "net.h"

int main()
{
    cv::Mat img = cv::imread("image.ppm", CV_LOAD_IMAGE_GRAYSCALE);
    int w = img.cols;
    int h = img.rows;

    // subtract 128, norm to -1 ~ 1
    ncnn::Mat in = ncnn::Mat::from_pixels_resize(img.data, ncnn::Mat::PIXEL_GRAY, w, h, 60, 60);
    float mean[1] = { 128.f };
    float norm[1] = { 1/128.f };
    in.substract_mean_normalize(mean, norm);

    ncnn::Net net;
    net.load_param("model.param");
    net.load_model("model.bin");

    ncnn::Extractor ex = net.create_extractor();

    ex.input("data", in);

    ncnn::Mat feat;
    ex.extract("output", feat);

    return 0;
}

 

ncnn对yolov5适配代码

https://github.com/Tencent/ncnn/blob/master/examples/yolov5.cpp

 

YOLOv5_NCNN (高赞版)

https://github.com/cmdbug/YOLOv5_NCNN

调试运行成功。

Ncnn deployment on mobile,support:YOLOv5s,YOLOv4-tiny,MobileNetV2-YOLOv3-nano,Simple-Pose,Yolact,ChineseOCR-lite,ENet,Landmark106,DBFace,MBNv2-FCN and MBNv3-Seg-small on camera.

 

Android:

  • Due to factors such as mobile phone performance and image size, FPS varies greatly on different mobile phones. This project mainly tests the use of the NCNN framework. For the conversion of specific models, you can go to the NCNN official to view the conversion tutorial.
  • Because the opencv library is too large, only arm64-v8a/armeabi-v7a is reserved. If you need other versions, go to the official download.
  • ncnn temporarily uses the vulkan version, and acceleration needs to be turned on before loading, which is not turned on in this project. If you want to use the ncnn version, you need to modify the CMakeLists.txt configuration.
  • Different AS versions may have various problems with compilation. If the compilation error cannot be solved, it is recommended to use AS4.0 or higher to try.
  • ncnn has been updated to a new version, which includes ncnn The official import method of cmake.

This project is more about practicing the use and deployment of various models, without too much processing in terms of speed. If you have requirements for speed, you can directly obtain data such as YUV for direct input or use methods such as texture and opengl to achieve data input, reducing intermediate data transmission and conversion.

Convert locally(Will not upload model): xxxx -> ncnn

Minimal OpenCV:opencv-mobile

 

ncnn-android-yolov5(demo 最流行)

https://github.com/nihui/ncnn-android-yolov5

 

https://cloud.tencent.com/developer/article/2359636

https://blog.csdn.net/qq_60943902/article/details/132440203

https://blog.csdn.net/qq_40280673/article/details/137338040


ncnn-android-yolov5

The YOLOv5 object detection

this is a sample ncnn android project, it depends on ncnn library only

https://github.com/Tencent/ncnn

how to build and run

step1

https://github.com/Tencent/ncnn/releases

download ncnn-android-vulkan.zip or build ncnn for android yourself

step2

extract ncnn-android-vulkan.zip into app/src/main/jni or change the ncnn_DIR path to yours in app/src/main/jni/CMakeLists.txt

step3

open this project with Android Studio, build it and enjoy!

screenshot

 

模型转换

训练好的模型.pt通过onnx转换为nccn格式

https://www.bilibili.com/read/cv26932143/

https://zhuanlan.zhihu.com/p/590972438

https://blog.csdn.net/funBox/article/details/134059833

 

https://github.com/ultralytics/yolov5/blob/master/models/yolov5s.yaml

# Ultralytics YOLOv5 🚀, AGPL-3.0 license

# Parameters
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple
anchors:
  - [10, 13, 16, 30, 33, 23] # P3/8
  - [30, 61, 62, 45, 59, 119] # P4/16
  - [116, 90, 156, 198, 373, 326] # P5/32

# YOLOv5 v6.0 backbone
backbone:
  # [from, number, module, args]
  [
    [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
    [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
    [-1, 3, C3, [128]],
    [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
    [-1, 6, C3, [256]],
    [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
    [-1, 9, C3, [512]],
    [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
    [-1, 3, C3, [1024]],
    [-1, 1, SPPF, [1024, 5]], # 9
  ]

# YOLOv5 v6.0 head
head: [
    [-1, 1, Conv, [512, 1, 1]],
    [-1, 1, nn.Upsample, [None, 2, "nearest"]],
    [[-1, 6], 1, Concat, [1]], # cat backbone P4
    [-1, 3, C3, [512, False]], # 13

    [-1, 1, Conv, [256, 1, 1]],
    [-1, 1, nn.Upsample, [None, 2, "nearest"]],
    [[-1, 4], 1, Concat, [1]], # cat backbone P3
    [-1, 3, C3, [256, False]], # 17 (P3/8-small)

    [-1, 1, Conv, [256, 3, 2]],
    [[-1, 14], 1, Concat, [1]], # cat head P4
    [-1, 3, C3, [512, False]], # 20 (P4/16-medium)

    [-1, 1, Conv, [512, 3, 2]],
    [[-1, 10], 1, Concat, [1]], # cat head P5
    [-1, 3, C3, [1024, False]], # 23 (P5/32-large)

    [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
  ]

 

转换 ncnn使用命令行测试图片

https://blog.csdn.net/qq_40280673/article/details/137338040

 

模型转换后添加YOLOV5Focus算子

https://blog.csdn.net/qq_45057749/article/details/115013509 

 

专用工具

https://github.com/pnnx/pnnx

 

模型可视化工具

https://netron.app/

 

Good Practice

https://zhuanlan.zhihu.com/p/590972438

 

posted @ 2024-08-11 20:10  lightsong  阅读(156)  评论(0)    收藏  举报
千山鸟飞绝,万径人踪灭