yolov2 推理测试 - 模型转换❤️darknet 转 ncnn❤️【yolov2之darknet】

2023-12-21 22:38

本文主要是介绍yolov2 推理测试 - 模型转换❤️darknet 转 ncnn❤️【yolov2之darknet】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本博文基本按照 YOLOv2 darknet 官方教程,对预训练模型 展开测试,简单记录


YOLOv2 模型转 ncnn 部分遇到报错,本博文未做处理;对这部分有兴趣可参考


yolov3(darknet )训练 - 测试 - 模型转换❤️darknet 转 ncnn 之C++运行推理❤️【yolov3 实战一览】

文章目录

    • 🥇 基础信息
    • 📕 运行过程如下【darknet 模型测试】
        • 下载仓库代码
        • make 【基础环境编译】
        • 下载模型
        • run the detector【测试 dog.jpg】
        • run the detector【测试二 horses.jpg 】
        • yolov2-tiny-voc.weights 测试
    • 📘 darknet 版本 yolo2 转 ncnn【darknet2ncnn】
    • 📙 pytorch 版本 yolo2 转 ncnn


🥇 基础信息


  • yolov2【yolo-9000】 来自 2016 年,至今已有 pytorch、keras、darknet 等多个框架的训练版本
  • 本博文围绕 官方 darknet 模型进行测试 和 ncnn 尝试转换

依照如下 darknet/yolov2 官网 依次运行即可


https://pjreddie.com/darknet/yolov2/

1-0


📕 运行过程如下【darknet 模型测试】


下载仓库代码
git clone https://github.com/pjreddie/darknet
cd darknet
make 【基础环境编译】
make
# 输出如下:
mkdir -p obj
mkdir -p backup
mkdir -p results
gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/gemm.c -o obj/gemm.o...
下载模型

wget 命令下载 或者 手动到浏览器下载

 wget https://pjreddie.com/media/files/yolov2.weights--2021-10-09 14:52:58--  https://pjreddie.com/media/files/yolov2.weights
Resolving pjreddie.com (pjreddie.com)... 128.208.4.108
Connecting to pjreddie.com (pjreddie.com)|128.208.4.108|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 203934260 (194M) [application/octet-stream]
Saving to: ‘yolov2.weights’yolov2.weights                                                100%[================================================================================================================================================>] 194.49M   161KB/s    in 8m 48s  2021-10-09 15:01:46 (377 KB/s) - ‘yolov2.weights’ saved [203934260/203934260]# 或者 
wget https://pjreddie.com/media/files/yolov2-tiny-voc.weights
run the detector【测试 dog.jpg】
./darknet detect cfg/yolov2.cfg yolov2.weights data/dog.jpg# 输出如下
layer     filters    size              input                output0 conv     32  3 x 3 / 1   608 x 608 x   3   ->   608 x 608 x  32  0.639 BFLOPs1 max          2 x 2 / 2   608 x 608 x  32   ->   304 x 304 x  322 conv     64  3 x 3 / 1   304 x 304 x  32   ->   304 x 304 x  64  3.407 BFLOPs3 max          2 x 2 / 2   304 x 304 x  64   ->   152 x 152 x  644 conv    128  3 x 3 / 1   152 x 152 x  64   ->   152 x 152 x 128  3.407 BFLOPs5 conv     64  1 x 1 / 1   152 x 152 x 128   ->   152 x 152 x  64  0.379 BFLOPs6 conv    128  3 x 3 / 1   152 x 152 x  64   ->   152 x 152 x 128  3.407 BFLOPs7 max          2 x 2 / 2   152 x 152 x 128   ->    76 x  76 x 1288 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs9 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs10 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs11 max          2 x 2 / 2    76 x  76 x 256   ->    38 x  38 x 25612 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs13 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs14 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs15 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs16 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs17 max          2 x 2 / 2    38 x  38 x 512   ->    19 x  19 x 51218 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs19 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs20 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs21 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs22 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs23 conv   1024  3 x 3 / 1    19 x  19 x1024   ->    19 x  19 x1024  6.814 BFLOPs24 conv   1024  3 x 3 / 1    19 x  19 x1024   ->    19 x  19 x1024  6.814 BFLOPs25 route  1626 conv     64  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x  64  0.095 BFLOPs27 reorg              / 2    38 x  38 x  64   ->    19 x  19 x 25628 route  27 2429 conv   1024  3 x 3 / 1    19 x  19 x1280   ->    19 x  19 x1024  8.517 BFLOPs30 conv    425  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 425  0.314 BFLOPs31 detection
mask_scale: Using default '1.000000'
Loading weights from yolov2.weights...Done!
data/dog.jpg: Predicted in 10.937355 seconds.
dog: 82%
truck: 64%
bicycle: 85%

2-1

run the detector【测试二 horses.jpg 】
./darknet detect cfg/yolov2.cfg yolov2.weights data/horses.jpg # 输出如下mask_scale: Using default '1.000000'
Loading weights from yolov2.weights...Done!
data/horses.jpg: Predicted in 11.372653 seconds.
horse: 91%
horse: 84%
horse: 62%

2-2

yolov2-tiny-voc.weights 测试
./darknet detector test cfg/voc.data cfg/yolov2-tiny-voc.cfg yolov2-tiny-voc.weights data/dog.jpg# 输出如下layer     filters    size              input                output0 conv     16  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  16  0.150 BFLOPs1 max          2 x 2 / 2   416 x 416 x  16   ->   208 x 208 x  162 conv     32  3 x 3 / 1   208 x 208 x  16   ->   208 x 208 x  32  0.399 BFLOPs3 max          2 x 2 / 2   208 x 208 x  32   ->   104 x 104 x  324 conv     64  3 x 3 / 1   104 x 104 x  32   ->   104 x 104 x  64  0.399 BFLOPs5 max          2 x 2 / 2   104 x 104 x  64   ->    52 x  52 x  646 conv    128  3 x 3 / 1    52 x  52 x  64   ->    52 x  52 x 128  0.399 BFLOPs7 max          2 x 2 / 2    52 x  52 x 128   ->    26 x  26 x 1288 conv    256  3 x 3 / 1    26 x  26 x 128   ->    26 x  26 x 256  0.399 BFLOPs9 max          2 x 2 / 2    26 x  26 x 256   ->    13 x  13 x 25610 conv    512  3 x 3 / 1    13 x  13 x 256   ->    13 x  13 x 512  0.399 BFLOPs11 max          2 x 2 / 1    13 x  13 x 512   ->    13 x  13 x 51212 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024  1.595 BFLOPs13 conv   1024  3 x 3 / 1    13 x  13 x1024   ->    13 x  13 x1024  3.190 BFLOPs14 conv    125  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 125  0.043 BFLOPs15 detectionmask_scale: Using default '1.000000'
Loading weights from yolov2-tiny-voc.weights...Done!
data/dog.jpg: Predicted in 1.149598 seconds.
dog: 78%
car: 55%
car: 50%

预测图像效果如下

2-3


📘 darknet 版本 yolo2 转 ncnn【darknet2ncnn】


darknet2ncnn

./darknet2ncnn yolov2.cfg yolov2.weights yolov2-darknet.param yolov2-darknet.bin 1# 输出如下Loading cfg...
Loading weights...
Converting model...
77 layers, 78 blobs generated.
NOTE: The input of darknet uses: mean_vals=0 and norm_vals=1/255.f.
NOTE: Remember to use ncnnoptimize for better performance.# 或者./darknet2ncnn yolov2-tiny-voc.cfg yolov2-tiny-voc.weights yolov2-darknet.param yolov2-darknet.bin 1Loading cfg...
Loading weights...
Converting model...
33 layers, 33 blobs generated.
NOTE: The input of darknet uses: mean_vals=0 and norm_vals=1/255.f.
NOTE: Remember to use ncnnoptimize for better performance.

ncnnoptimize 优化报错如下 【yolov2.weights 和 yolov2-tiny-voc.weights 转 ncnn 遇到一样的问题】

 ./ncnnoptimize darknet/yolov2-darknet.param darknet/yolov2-darknet.bin yolov2-darknet-opt.param yolov2-darknet-opt.bin 0# 运行报错,输出如下ParamDict parse value failed
ParamDict load_param 69 26_211_bn_leaky failed
parse top_count failed
load_model error at layer 69, parameter file has inconsistent content.
Segmentation fault (core dumped)

原因分析如下,【暂无法处理】

3-1


📙 pytorch 版本 yolo2 转 ncnn


ncnn 官方支持的 yolo2 模型转换貌似是 pytorch 版本


https://github.com/longcw/yolo2-pytorch


中间遇到 pytorch 版本过低的问题,因此没有继续下去

  • 一个报错的参考解决方法链接:ImportError: torch.utils.ffi is deprecated

4-1


遇到未知报错的我

9-8


这篇关于yolov2 推理测试 - 模型转换❤️darknet 转 ncnn❤️【yolov2之darknet】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/521728

相关文章

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

Java的IO模型、Netty原理解析

《Java的IO模型、Netty原理解析》Java的I/O是以流的方式进行数据输入输出的,Java的类库涉及很多领域的IO内容:标准的输入输出,文件的操作、网络上的数据传输流、字符串流、对象流等,这篇... 目录1.什么是IO2.同步与异步、阻塞与非阻塞3.三种IO模型BIO(blocking I/O)NI

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

基于Flask框架添加多个AI模型的API并进行交互

《基于Flask框架添加多个AI模型的API并进行交互》:本文主要介绍如何基于Flask框架开发AI模型API管理系统,允许用户添加、删除不同AI模型的API密钥,感兴趣的可以了解下... 目录1. 概述2. 后端代码说明2.1 依赖库导入2.2 应用初始化2.3 API 存储字典2.4 路由函数2.5 应

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

C语言中的数据类型强制转换

《C语言中的数据类型强制转换》:本文主要介绍C语言中的数据类型强制转换方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C语言数据类型强制转换自动转换强制转换类型总结C语言数据类型强制转换强制类型转换:是通过类型转换运算来实现的,主要的数据类型转换分为自动转换