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

相关文章

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

Java对象转换的实现方式汇总

《Java对象转换的实现方式汇总》:本文主要介绍Java对象转换的多种实现方式,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java对象转换的多种实现方式1. 手动映射(Manual Mapping)2. Builder模式3. 工具类辅助映

python实现svg图片转换为png和gif

《python实现svg图片转换为png和gif》这篇文章主要为大家详细介绍了python如何实现将svg图片格式转换为png和gif,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录python实现svg图片转换为png和gifpython实现图片格式之间的相互转换延展:基于Py

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

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