diff --git a/ultralytics/engine/model.py b/ultralytics/engine/model.py index 09048bbf8e8..677361e2501 100644 --- a/ultralytics/engine/model.py +++ b/ultralytics/engine/model.py @@ -641,7 +641,12 @@ def train( checks.check_pip_update_available() overrides = yaml_load(checks.check_yaml(kwargs["cfg"])) if kwargs.get("cfg") else self.overrides - custom = {"data": DEFAULT_CFG_DICT["data"] or TASK2DATA[self.task]} # method defaults + custom = { + # NOTE: handle the case when 'cfg' includes 'data'. + "data": overrides.get("data") or DEFAULT_CFG_DICT["data"] or TASK2DATA[self.task], + "model": self.overrides["model"], + "task": self.task, + } # method defaults args = {**overrides, **custom, **kwargs, "mode": "train"} # highest priority args on the right if args.get("resume"): args["resume"] = self.ckpt_path