def strip_optimizer(path, f='weights/best.pt', s=''): # from yolo_utils.general import *; strip_optimizer()
# Strip optimizer from 'f' to finalize training, optionally save as 's'
x = torch.load(f, map_location=torch.device('cpu'))
for key in 'optimizer', 'training_results', 'wandb_id':
x[key] = None
x['epoch'] = -1
x["model"].half() # to FP16
for p in x["model"].parameters():
p.requires_grad = False
# torch.save(x, s or f)
torch.save(x, path)
# mb = os.path.getsize(s or f) / 1E6 # filesize
# print('Optimizer stripped from %s,%s %.1fMB' % (f, (' saved as %s,' % s) if s else '', mb))
yolo 自带的模型大小减半方法
最新推荐文章于 2024-07-29 17:20:55 发布