update test.py for FP16 testing during training
This commit is contained in:
1 parent
8669f4561c
commit
e670a3353b
1 file changed
+7
-8
@@ -25,7 +25,6 @@ def test(data,
|
|||||||
if model is None:
|
if model is None:
|
||||||
training = False
|
training = False
|
||||||
device = torch_utils.select_device(opt.device, batch_size=batch_size)
|
device = torch_utils.select_device(opt.device, batch_size=batch_size)
|
||||||
half = device.type != 'cpu' # half precision only supported on CUDA
|
|
||||||
|
|
||||||
# Remove previous
|
# Remove previous
|
||||||
for f in glob.glob('test_batch*.jpg'):
|
for f in glob.glob('test_batch*.jpg'):
|
||||||
@@ -37,20 +36,19 @@ def test(data,
|
|||||||
torch_utils.model_info(model)
|
torch_utils.model_info(model)
|
||||||
model.fuse()
|
model.fuse()
|
||||||
model.to(device)
|
model.to(device)
|
||||||
if half:
|
|
||||||
model.half() # to FP16
|
|
||||||
|
|
||||||
# Multi-GPU disabled, incompatible with .half()
|
# Multi-GPU disabled, incompatible with .half() https://github.com/ultralytics/yolov5/issues/99
|
||||||
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
|
# if device.type != 'cpu' and torch.cuda.device_count() > 1:
|
||||||
# model = nn.DataParallel(model)
|
# model = nn.DataParallel(model)
|
||||||
|
|
||||||
else: # called by train.py
|
else: # called by train.py
|
||||||
training = True
|
training = True
|
||||||
device = next(model.parameters()).device # get model device
|
device = next(model.parameters()).device # get model device
|
||||||
# half disabled https://github.com/ultralytics/yolov5/issues/99
|
|
||||||
half = False # device.type != 'cpu' and torch.cuda.device_count() == 1
|
# Half
|
||||||
if half:
|
half = device.type != 'cpu' and torch.cuda.device_count() == 1 # half precision only supported on single-GPU
|
||||||
model.half() # to FP16
|
if half:
|
||||||
|
model.half() # to FP16
|
||||||
|
|
||||||
# Configure
|
# Configure
|
||||||
model.eval()
|
model.eval()
|
||||||
@@ -237,6 +235,7 @@ def test(data,
|
|||||||
'See https://github.com/cocodataset/cocoapi/issues/356')
|
'See https://github.com/cocodataset/cocoapi/issues/356')
|
||||||
|
|
||||||
# Return results
|
# Return results
|
||||||
|
model.float() # for training
|
||||||
maps = np.zeros(nc) + map
|
maps = np.zeros(nc) + map
|
||||||
for i, c in enumerate(ap_class):
|
for i, c in enumerate(ap_class):
|
||||||
maps[c] = ap[i]
|
maps[c] = ap[i]
|
||||||
|
|||||||
Reference in new issue
Block a user