读取yolov5模型的权重

# coding=utf-8
import sys
sys.path.append('../yolov5')

import torch

weights_file = your_path+'best.pt'
ckpt = torch.load(weights_file)
print(type(ckpt))
# ckpt.keys(): dict_keys(['epoch', 'best_fitness', 'model', 'ema', 'updates', 'optimizer', 'wandb_id', 'training_results'])
cnt = 0
for name,weights in ckpt['model'].named_parameters():
    cnt+=1
    print('[{}] -----------------------'.format(cnt))
    print(name,':',weights.size())
    print(weights.detach())

  

posted @ 2021-09-28 11:04  wxiaoli  阅读(1259)  评论(0编辑  收藏  举报