Implement @torch.no_grad() decorator (#3312)

* `@torch.no_grad()` decorator

* Update detect.py
This commit is contained in:
Glenn Jocher authored and GitHub committed 2021-05-24 13:23:09 +02:00
1 parent 73a92dc1b6
commit 61ea23c3fe
2 files changed
+20 -20

No files matched your search

+6 -6
View File
@@ -14,6 +14,7 @@ from utils.plots import colors, plot_one_box
from utils.torch_utils import select_device, load_classifier, time_synchronized
@torch.no_grad()
def detect(opt):
source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size
save_img = not opt.nosave and not source.endswith('.txt') # save inference images
@@ -175,10 +176,9 @@ if __name__ == '__main__':
print(opt)
check_requirements(exclude=('tensorboard', 'pycocotools', 'thop'))
with torch.no_grad():
if opt.update: # update all models (to fix SourceChangeWarning)
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
detect(opt=opt)
strip_optimizer(opt.weights)
else:
if opt.update: # update all models (to fix SourceChangeWarning)
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
detect(opt=opt)
strip_optimizer(opt.weights)
else:
detect(opt=opt)