读取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())