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批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

Python中Json和其他类型相互转换的实现示例

《Python中Json和其他类型相互转换的实现示例》本文介绍了在Python中使用json模块实现json数据与dict、object之间的高效转换,包括loads(),load(),dumps()... 项目中经常会用到json格式转为object对象、dict字典格式等。在此做个记录,方便后续用到该方

使用Java读取本地文件并转换为MultipartFile对象的方法

《使用Java读取本地文件并转换为MultipartFile对象的方法》在许多JavaWeb应用中,我们经常会遇到将本地文件上传至服务器或其他系统的需求,在这种场景下,MultipartFile对象非... 目录1. 基本需求2. 自定义 MultipartFile 类3. 实现代码4. 代码解析5. 自定

基于Python Playwright进行前端性能测试的脚本实现

《基于PythonPlaywright进行前端性能测试的脚本实现》在当今Web应用开发中,性能优化是提升用户体验的关键因素之一,本文将介绍如何使用Playwright构建一个自动化性能测试工具,希望... 目录引言工具概述整体架构核心实现解析1. 浏览器初始化2. 性能数据收集3. 资源分析4. 关键性能指

Python进行JSON和Excel文件转换处理指南

《Python进行JSON和Excel文件转换处理指南》在数据交换与系统集成中,JSON与Excel是两种极为常见的数据格式,本文将介绍如何使用Python实现将JSON转换为格式化的Excel文件,... 目录将 jsON 导入为格式化 Excel将 Excel 导出为结构化 JSON处理嵌套 JSON:

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

关于集合与数组转换实现方法

《关于集合与数组转换实现方法》:本文主要介绍关于集合与数组转换实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、Arrays.asList()1.1、方法作用1.2、内部实现1.3、修改元素的影响1.4、注意事项2、list.toArray()2.1、方

利用Python脚本实现批量将图片转换为WebP格式

《利用Python脚本实现批量将图片转换为WebP格式》Python语言的简洁语法和库支持使其成为图像处理的理想选择,本文将介绍如何利用Python实现批量将图片转换为WebP格式的脚本,WebP作为... 目录简介1. python在图像处理中的应用2. WebP格式的原理和优势2.1 WebP格式与传统

使用Python进行GRPC和Dubbo协议的高级测试

《使用Python进行GRPC和Dubbo协议的高级测试》GRPC(GoogleRemoteProcedureCall)是一种高性能、开源的远程过程调用(RPC)框架,Dubbo是一种高性能的分布式服... 目录01 GRPC测试安装gRPC编写.proto文件实现服务02 Dubbo测试1. 安装Dubb