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

相关文章

Nginx设置连接超时并进行测试的方法步骤

《Nginx设置连接超时并进行测试的方法步骤》在高并发场景下,如果客户端与服务器的连接长时间未响应,会占用大量的系统资源,影响其他正常请求的处理效率,为了解决这个问题,可以通过设置Nginx的连接... 目录设置连接超时目的操作步骤测试连接超时测试方法:总结:设置连接超时目的设置客户端与服务器之间的连接

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

Spring AI Alibaba接入大模型时的依赖问题小结

《SpringAIAlibaba接入大模型时的依赖问题小结》文章介绍了如何在pom.xml文件中配置SpringAIAlibaba依赖,并提供了一个示例pom.xml文件,同时,建议将Maven仓... 目录(一)pom.XML文件:(二)application.yml配置文件(一)pom.xml文件:首

Java数字转换工具类NumberUtil的使用

《Java数字转换工具类NumberUtil的使用》NumberUtil是一个功能强大的Java工具类,用于处理数字的各种操作,包括数值运算、格式化、随机数生成和数值判断,下面就来介绍一下Number... 目录一、NumberUtil类概述二、主要功能介绍1. 数值运算2. 格式化3. 数值判断4. 随机

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

Python实现视频转换为音频的方法详解

《Python实现视频转换为音频的方法详解》这篇文章主要为大家详细Python如何将视频转换为音频并将音频文件保存到特定文件夹下,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果5. 注意事项

本地私有化部署DeepSeek模型的详细教程

《本地私有化部署DeepSeek模型的详细教程》DeepSeek模型是一种强大的语言模型,本地私有化部署可以让用户在自己的环境中安全、高效地使用该模型,避免数据传输到外部带来的安全风险,同时也能根据自... 目录一、引言二、环境准备(一)硬件要求(二)软件要求(三)创建虚拟环境三、安装依赖库四、获取 Dee

使用Python实现图片和base64转换工具

《使用Python实现图片和base64转换工具》这篇文章主要为大家详细介绍了如何使用Python中的base64模块编写一个工具,可以实现图片和Base64编码之间的转换,感兴趣的小伙伴可以了解下... 简介使用python的base64模块来实现图片和Base64编码之间的转换。可以将图片转换为Bas