从Darknet的预训练权重中获取权重值的方法? [英] Approach to get the weight values from the pre-trained weights from Darknet?

查看:124
本文介绍了从Darknet的预训练权重中获取权重值的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在C语言中实现YOLOv3对象检测模型(仅检测而不是训练).

I'm currently trying to implement YOLOv3 object detection model in C(only detection, not training).

我已经用任意值测试了卷积方法,它似乎按预期工作了.

I have tested my convolution method with arbitrary values and it seems to be working as I expected.

在堆叠多个方法调用以进行正向传播之前,我认为使用实际的预训练重量文件数据进行测试是安全的.

Before stacking up multiple method calls to do forward propagation, I thought it would be safe to test with the actual pretrained weight file data.

当我查找Darknet的预训练重量文件时,它是很大的二进制文件.我试图将其转换为十六进制和小数,但要指出要使用的值的哪一部分仍然不容易.

When I look up Darknet's pre-trained weight file, it was a huge chunk of binary files. I tried to convert it to hex and decimals, but it still doesn't look simple to pinpoint what part of values to use.

所以,我的问题是,我应该怎么做才能提取权重或过滤器值的十进制数字,以便可以按照YOLOv3中发生的正向传播的相同顺序来使用它们?

So, my question is, what should I do to extract the decimal numbers of the weights or the filter values so that I can use them in the same order of the forward propagation happening in YOLOv3?

**我目前正在尝试使用https://www.itread01.com/content/1541167345.html

*I'm currently trying to build my c version of YOLOv3 using the structure image shown in https://www.itread01.com/content/1541167345.html

*我的c代码以及其他HDL代码将在名为MicroZed的FPGA板上运行.

*My c code will be run on an FPGA board called MicroZed, along with other HDL code.

*我试图将一些printf函数插入Darknet代码的某些地方,以查看YOLOv3运行时正在移动的数据类型,但是,当我在Linux终端中运行该数据时,它没有显示任何新内容并保存下来输出相同的结果.

*I tried to plug some printf functions into some places of Darknet code to see what kinds of data are moving around when YOLOv3 runs, however, when I ran it on in Linux terminal, it didn't show anything new and kept outputting the same results.

任何帮助或建议将不胜感激.谢谢!

Any help or advice will be really appreciated. Thank you!

推荐答案

我不太确定是否可以直接读取暗网权重,但是您可以将其转换为 .h5 格式并从中获取重量值

I am not too sure if there is a direct way to read darknet weights, but you can convert it into .h5 format and obtain the weight values from it

您可以使用您可以从链接存储库的自述文件中显示的列表中,根据您的Yolo版本选择命令.对于标准yolov3,转换命令为

You can choose the command based on your Yolo version from the list shown in the ReadMe of the linked repo. For the standard yolov3, the command for converting is

python工具/model_converter/convert.py cfg/yolov3.cfg weights/yolov3.weights weights/yolov3.h5 有了 .h5 权重后,就可以使用以下代码段获取权重中的值.信贷/来源

python tools/model_converter/convert.py cfg/yolov3.cfg weights/yolov3.weights weights/yolov3.h5 Once you have the .h5weights, you can use the below code snippet for obtaining the values from the weights. credit/source

import h5py

path = "<path to weights>.h5"
weights = {}
keys = []
with h5py.File(path, 'r') as f: # open file
  f.visit(keys.append) # append all keys to list
  for key in keys:
      if ':' in key: # contains data if ':' in key
          param_name = f[key].name
          weights[f[key].name] = f[key].value
          print(param_name,weights[f[key].name])

这篇关于从Darknet的预训练权重中获取权重值的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆