Skip to content

Commit 072f76c

Browse files
jpkoponenJKO095
and
JKO095
authored
Fix a GPU memory leak in detect. No need to calculate gradients in inference. (WongKinYiu#900)
Co-authored-by: JKO095 <[email protected]>
1 parent 8b616af commit 072f76c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

detect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def detect(save_img=False):
8484

8585
# Inference
8686
t1 = time_synchronized()
87-
pred = model(img, augment=opt.augment)[0]
87+
with torch.no_grad(): # Calculating gradients would cause a GPU memory leak
88+
pred = model(img, augment=opt.augment)[0]
8889
t2 = time_synchronized()
8990

9091
# Apply NMS

0 commit comments

Comments
 (0)