Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip_package_creation_second_attempt #3773

Merged
merged 20 commits into from
Jun 26, 2021
Prev Previous commit
Next Next commit
more changes
  • Loading branch information
SkalskiP committed Jun 25, 2021
commit 0eb95618cdaf9efef386d67f71956e2c4ed1dbed
8 changes: 5 additions & 3 deletions yolov5/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,10 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non
return output


def strip_optimizer(f='best.pt', s=''): # from utils.general import *; strip_optimizer()
def strip_optimizer(f='best.pt', s=''):
# Strip optimizer from 'f' to finalize training, optionally save as 's'
x = torch.load(f, map_location=torch.device('cpu'))
with yolov5_in_syspath():
x = torch.load(f, map_location=torch.device('cpu'))
if x.get('ema'):
x['model'] = x['ema'] # replace model with ema
for k in 'optimizer', 'training_results', 'wandb_id', 'ema', 'updates': # keys
Expand All @@ -645,7 +646,8 @@ def strip_optimizer(f='best.pt', s=''): # from utils.general import *; strip_op
x['model'].half() # to FP16
for p in x['model'].parameters():
p.requires_grad = False
torch.save(x, s or f)
with yolov5_in_syspath():
torch.save(x, s or f)
mb = os.path.getsize(s or f) / 1E6 # filesize
print(f"Optimizer stripped from {f},{(' saved as %s,' % s) if s else ''} {mb:.1f}MB")

Expand Down