From 0303ced8ab059a474caf6f2ea3dfbf2e4301937f Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Wed, 28 Dec 2022 21:01:51 +0530 Subject: [PATCH] Model enhancements 2 (#109) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher --- ultralytics/yolo/engine/model.py | 10 ++++++---- ultralytics/yolo/engine/predictor.py | 16 +++------------- ultralytics/yolo/engine/validator.py | 7 +++++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ultralytics/yolo/engine/model.py b/ultralytics/yolo/engine/model.py index e7720e7..15ffd12 100644 --- a/ultralytics/yolo/engine/model.py +++ b/ultralytics/yolo/engine/model.py @@ -112,8 +112,9 @@ class YOLO: source (str): Accepts all source types accepted by yolo **kwargs : Any other args accepted by the predictors. Too see all args check 'configuration' section in the docs """ - kwargs.update(self.overrides) - predictor = self.PredictorClass(overrides=kwargs) + overrides = self.overrides.copy() + overrides.update(kwargs) + predictor = self.PredictorClass(overrides=overrides) # check size type sz = predictor.args.imgsz @@ -136,8 +137,9 @@ class YOLO: if not self.model: raise Exception("model not initialized!") - kwargs.update(self.overrides) - args = get_config(config=DEFAULT_CONFIG, overrides=kwargs) + overrides = self.overrides.copy() + overrides.update(kwargs) + args = get_config(config=DEFAULT_CONFIG, overrides=overrides) args.data = data or args.data args.task = self.task diff --git a/ultralytics/yolo/engine/predictor.py b/ultralytics/yolo/engine/predictor.py index 94b2b72..a1aefc0 100644 --- a/ultralytics/yolo/engine/predictor.py +++ b/ultralytics/yolo/engine/predictor.py @@ -46,7 +46,9 @@ class BasePredictor: def __init__(self, config=DEFAULT_CONFIG, overrides={}): self.args = get_config(config, overrides) - self.save_dir = increment_path(Path(self.args.project) / self.args.name, exist_ok=self.args.exist_ok) + project = overrides.get("project") or self.args.task + name = overrides.get("name") or self.args.mode + self.save_dir = increment_path(Path("runs") / project / name, exist_ok=self.args.exist_ok) (self.save_dir / 'labels' if self.args.save_txt else self.save_dir).mkdir(parents=True, exist_ok=True) self.done_setup = False @@ -84,18 +86,6 @@ class BasePredictor: if is_url and is_file: source = check_file(source) # download - # data - if self.data: - try: - if self.data.endswith(".yaml"): - self.data = check_dataset_yaml(self.data) - else: - self.data = check_dataset(self.data) - except AssertionError as e: - LOGGER.info(f"Error ocurred: {e}") - finally: - LOGGER.info("Predictor will continue without reading the dataset") - # model device = select_device(self.args.device) model = model or self.args.model diff --git a/ultralytics/yolo/engine/validator.py b/ultralytics/yolo/engine/validator.py index aae1daa..f8fcd42 100644 --- a/ultralytics/yolo/engine/validator.py +++ b/ultralytics/yolo/engine/validator.py @@ -31,8 +31,11 @@ class BaseValidator: self.training = True self.speed = None self.jdict = None - self.save_dir = save_dir if save_dir is not None else \ - increment_path(Path(self.args.project) / self.args.name, exist_ok=self.args.exist_ok) + + project = self.args.project if self.args.project != "runs/train" else self.args.task + name = self.args.name if self.args.name != "exp" else self.args.mode + self.save_dir = increment_path(Path("runs") / project / name, exist_ok=self.args.exist_ok) + (self.save_dir / 'labels' if self.args.save_txt else self.save_dir).mkdir(parents=True, exist_ok=True) @smart_inference_mode() def __call__(self, trainer=None, model=None):