glenn-jocher
commited on
Commit
•
e670a33
1
Parent(s):
8669f45
update test.py for FP16 testing during training
Browse files
test.py
CHANGED
@@ -25,7 +25,6 @@ def test(data,
|
|
25 |
if model is None:
|
26 |
training = False
|
27 |
device = torch_utils.select_device(opt.device, batch_size=batch_size)
|
28 |
-
half = device.type != 'cpu' # half precision only supported on CUDA
|
29 |
|
30 |
# Remove previous
|
31 |
for f in glob.glob('test_batch*.jpg'):
|
@@ -37,20 +36,19 @@ def test(data,
|
|
37 |
torch_utils.model_info(model)
|
38 |
model.fuse()
|
39 |
model.to(device)
|
40 |
-
if half:
|
41 |
-
model.half() # to FP16
|
42 |
|
43 |
-
# Multi-GPU disabled, incompatible with .half()
|
44 |
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
|
45 |
# model = nn.DataParallel(model)
|
46 |
|
47 |
else: # called by train.py
|
48 |
training = True
|
49 |
device = next(model.parameters()).device # get model device
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
# Configure
|
56 |
model.eval()
|
@@ -237,6 +235,7 @@ def test(data,
|
|
237 |
'See https://github.com/cocodataset/cocoapi/issues/356')
|
238 |
|
239 |
# Return results
|
|
|
240 |
maps = np.zeros(nc) + map
|
241 |
for i, c in enumerate(ap_class):
|
242 |
maps[c] = ap[i]
|
|
|
25 |
if model is None:
|
26 |
training = False
|
27 |
device = torch_utils.select_device(opt.device, batch_size=batch_size)
|
|
|
28 |
|
29 |
# Remove previous
|
30 |
for f in glob.glob('test_batch*.jpg'):
|
|
|
36 |
torch_utils.model_info(model)
|
37 |
model.fuse()
|
38 |
model.to(device)
|
|
|
|
|
39 |
|
40 |
+
# Multi-GPU disabled, incompatible with .half() https://github.com/ultralytics/yolov5/issues/99
|
41 |
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
|
42 |
# model = nn.DataParallel(model)
|
43 |
|
44 |
else: # called by train.py
|
45 |
training = True
|
46 |
device = next(model.parameters()).device # get model device
|
47 |
+
|
48 |
+
# Half
|
49 |
+
half = device.type != 'cpu' and torch.cuda.device_count() == 1 # half precision only supported on single-GPU
|
50 |
+
if half:
|
51 |
+
model.half() # to FP16
|
52 |
|
53 |
# Configure
|
54 |
model.eval()
|
|
|
235 |
'See https://github.com/cocodataset/cocoapi/issues/356')
|
236 |
|
237 |
# Return results
|
238 |
+
model.float() # for training
|
239 |
maps = np.zeros(nc) + map
|
240 |
for i, c in enumerate(ap_class):
|
241 |
maps[c] = ap[i]
|