Skip to content

Commit f414133

Browse files
committed
Cleanup printing
1 parent a39de1e commit f414133

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

utils/autobatch.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16):
3434
print(f'{prefix}CUDA not detected, using default CPU batch-size {batch_size}')
3535
return batch_size
3636

37+
d = str(device).upper() # 'CUDA:0'
3738
t = torch.cuda.get_device_properties(device).total_memory / 1024 ** 3 # (GB)
3839
r = torch.cuda.memory_reserved(device) / 1024 ** 3 # (GB)
3940
a = torch.cuda.memory_allocated(device) / 1024 ** 3 # (GB)
4041
f = t - (r + a) # free inside reserved
41-
print(f'{prefix}{t:.3g}G total, {r:.3g}G reserved, {a:.3g}G allocated, {f:.3g}G free')
42+
print(f'{prefix}{d} {t:.3g}G total, {r:.3g}G reserved, {a:.3g}G allocated, {f:.3g}G free')
4243

4344
batch_sizes = [1, 2, 4, 8, 16]
4445
try:
@@ -50,9 +51,8 @@ def autobatch(model, imgsz=640, fraction=0.9, batch_size=16):
5051
y = [x[2] for x in y if x] # memory [2]
5152
batch_sizes = batch_sizes[:len(y)]
5253
p = np.polyfit(batch_sizes, y, deg=1) # first degree polynomial fit
53-
f_intercept = int((f * fraction - p[1]) / p[0]) # optimal batch size
54-
print(f'{prefix}batch-size {f_intercept} estimated to utilize '
55-
f'{str(device).upper()} {t * fraction:.3g}G/{t:.3g}G ({fraction * 100:.0f}%)')
56-
return f_intercept
54+
b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size)
55+
print(f'{prefix}batch-size {b} estimated to utilize {d} {t * fraction:.3g}G/{t:.3g}G ({fraction * 100:.0f}%)')
56+
return b
5757

5858
# autobatch(torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False))

0 commit comments

Comments
 (0)