1 Star 0 Fork 0

lshuncoding/YOLOv8-TensorRT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gen_pkl.py 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
triple-Mu 提交于 2023-01-08 23:28 . Add gen_pkl
import argparse
import pickle
from collections import OrderedDict
from ultralytics import YOLO
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-w',
'--weights',
type=str,
required=True,
help='YOLOv8 pytorch weights')
parser.add_argument('-o',
'--output',
type=str,
required=True,
help='Output file')
args = parser.parse_args()
return args
args = parse_args()
model = YOLO(args.weights)
model.model.fuse()
YOLOv8 = model.model.model
strides = YOLOv8[-1].stride.detach().cpu().numpy()
reg_max = YOLOv8[-1].dfl.conv.weight.shape[1]
state_dict = OrderedDict(GD=model.model.yaml['depth_multiple'],
GW=model.model.yaml['width_multiple'],
strides=strides,
reg_max=reg_max)
for name, value in YOLOv8.state_dict().items():
value = value.detach().cpu().numpy()
i = int(name.split('.')[0])
layer = YOLOv8[i]
module_name = layer.type.split('.')[-1]
stem = module_name + '.' + name
state_dict[stem] = value
with open(args.output, 'wb') as f:
pickle.dump(state_dict, f)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lshuncoding/YOLOv8-TensorRT.git
git@gitee.com:lshuncoding/YOLOv8-TensorRT.git
lshuncoding
YOLOv8-TensorRT
YOLOv8-TensorRT
main

搜索帮助