From 84fd8f6e4937bec58e431699ec274d7680b70c30 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 8 Oct 2024 16:59:13 +0200 Subject: [PATCH] Prevent final val if val=False (#16776) Co-authored-by: UltralyticsAssistant --- ultralytics/models/yolo/detect/val.py | 2 +- ultralytics/utils/autobatch.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ultralytics/models/yolo/detect/val.py b/ultralytics/models/yolo/detect/val.py index 0823f75144..aef60d65eb 100644 --- a/ultralytics/models/yolo/detect/val.py +++ b/ultralytics/models/yolo/detect/val.py @@ -75,7 +75,7 @@ class DetectionValidator(BaseValidator): ) # is COCO self.is_lvis = isinstance(val, str) and "lvis" in val and not self.is_coco # is LVIS self.class_map = converter.coco80_to_coco91_class() if self.is_coco else list(range(len(model.names))) - self.args.save_json |= (self.is_coco or self.is_lvis) and not self.training # run on final val if training COCO + self.args.save_json |= self.args.val and (self.is_coco or self.is_lvis) and not self.training # run final val self.names = model.names self.nc = len(model.names) self.metrics.names = self.names diff --git a/ultralytics/utils/autobatch.py b/ultralytics/utils/autobatch.py index 86619998a1..581fe09027 100644 --- a/ultralytics/utils/autobatch.py +++ b/ultralytics/utils/autobatch.py @@ -1,6 +1,7 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license """Functions for estimating the best YOLO batch size to use a fraction of the available CUDA memory in PyTorch.""" +import os from copy import deepcopy import numpy as np @@ -57,7 +58,7 @@ def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch): # Inspect CUDA memory gb = 1 << 30 # bytes to GiB (1024 ** 3) - d = str(device).upper() # 'CUDA:0' + d = f"CUDA:{os.getenv('CUDA_VISIBLE_DEVICES', '0').strip()[0]}" # 'CUDA:0' properties = torch.cuda.get_device_properties(device) # device properties t = properties.total_memory / gb # GiB total r = torch.cuda.memory_reserved(device) / gb # GiB reserved