From 21cc7a4cff87f248029160b4bb76e6f9186435a4 Mon Sep 17 00:00:00 2001 From: YangYang <1525927685@qq.com> Date: Sat, 6 Nov 2021 17:15:04 +0800 Subject: [PATCH 1/2] add fp16 turn-off mode for eval --- classification/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classification/main.py b/classification/main.py index c4eccbf..f50e591 100644 --- a/classification/main.py +++ b/classification/main.py @@ -361,7 +361,7 @@ def main(args): loss_scaler.load_state_dict(checkpoint['scaler']) if args.eval: - test_stats = evaluate(data_loader_val, model, device) + test_stats = evaluate(data_loader_val, model, device, fp32=args.fp32_resume) print(f"Accuracy of the network on the {len(dataset_val)} test images: {test_stats['acc1']:.1f}%") return From a9fffd18c9fc4d0a32682e32e59fab0e1c8fdb24 Mon Sep 17 00:00:00 2001 From: YangYang <1525927685@qq.com> Date: Sat, 6 Nov 2021 17:15:48 +0800 Subject: [PATCH 2/2] add fp16 turn-off mode for eval --- classification/engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classification/engine.py b/classification/engine.py index 65eb52e..cc31103 100644 --- a/classification/engine.py +++ b/classification/engine.py @@ -68,7 +68,7 @@ def train_one_epoch(model: torch.nn.Module, criterion: DistillationLoss, @torch.no_grad() -def evaluate(data_loader, model, device): +def evaluate(data_loader, model, device, fp32=False): criterion = torch.nn.CrossEntropyLoss() metric_logger = utils.MetricLogger(delimiter=" ") @@ -82,7 +82,7 @@ def evaluate(data_loader, model, device): target = target.to(device, non_blocking=True) # compute output - with torch.cuda.amp.autocast(): + with torch.cuda.amp.autocast(enabled=not fp32): output = model(images) loss = criterion(output, target)