一.用yolov5官方的训练代码可能会根据自己的数据集生成新的anchor,并没有用到配置文件中的anchor,如果不清楚这个问题,就会给后续的工作带来一些麻烦
下面是查看自己训练好的模型中的anchor:
import torch
import sys
weights = 'runs/train/test/weights/best.pt'
model = torch.load(str(weights[0] if isinstance(weights, list) else weights), map_location='cpu')
model1 = model['ema' if model.get('ema') else 'model']
model2 = model1.float().fuse().model.state_dict()
for k,v in model2.items():
    if 'anchor' in k:
        # print(k)
        # print(v)
        print(v.numpy().flatten().tolist())
这样你就可以直接查看自己模型的anchor了。