{"record":{"id":"228def2283ba5d1a","repo":"ultralytics/yolov5","slug":"invalid-names-field-in-dataset-yaml-file-please","errorCode":null,"errorMessage":"Invalid 'names' field in dataset yaml file. Please use a list or dictionary","messagePattern":"Invalid 'names' field in dataset yaml file\\. Please use a list or dictionary","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"utils/loggers/comet/__init__.py","lineNumber":383,"sourceCode":"        self.experiment.log_artifact(artifact)\n\n    def download_dataset_artifact(self, artifact_path):\n        \"\"\"Downloads a dataset artifact to a specified directory using the experiment's logged artifact.\"\"\"\n        logged_artifact = self.experiment.get_artifact(artifact_path)\n        artifact_save_dir = str(Path(self.opt.save_dir) / logged_artifact.name)\n        logged_artifact.download(artifact_save_dir)\n\n        metadata = logged_artifact.metadata\n        data_dict = metadata.copy()\n        data_dict[\"path\"] = artifact_save_dir\n\n        metadata_names = metadata.get(\"names\")\n        if isinstance(metadata_names, dict):\n            data_dict[\"names\"] = {int(k): v for k, v in metadata.get(\"names\").items()}\n        elif isinstance(metadata_names, list):\n            data_dict[\"names\"] = {int(k): v for k, v in zip(range(len(metadata_names)), metadata_names)}\n        else:\n            raise ValueError(\"Invalid 'names' field in dataset yaml file. Please use a list or dictionary\")  # noqa: TRY004\n\n        return self.update_data_paths(data_dict)\n\n    def update_data_paths(self, data_dict):\n        \"\"\"Updates data paths in the dataset dictionary, defaulting 'path' to an empty string if not present.\"\"\"\n        path = data_dict.get(\"path\", \"\")\n\n        for split in [\"train\", \"val\", \"test\"]:\n            if data_dict.get(split):\n                split_path = data_dict.get(split)\n                data_dict[split] = (\n                    f\"{path}/{split_path}\" if isinstance(split_path, str) else [f\"{path}/{x}\" for x in split_path]\n                )\n\n        return data_dict\n\n    def on_pretrain_routine_end(self, paths):\n        \"\"\"Called at the end of pretraining routine to handle paths if training is not being resumed.\"\"\"","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/utils/loggers/comet/__init__.py#L365-L401","documentation":"Raised while restoring a dataset config from a Comet.ml artifact in the Comet logger's resume/download path. The artifact's stored metadata must contain a 'names' field that is either a dict (class-index -> name) or a list of class names; anything else (None, a string, a number) is rejected. This mirrors YOLOv5's requirement that dataset YAML 'names' be a list or dict so it can be normalized to {int: str}.","triggerScenarios":"Calling the Comet dataset-restore path (e.g. resuming a run whose data was logged as a Comet artifact, or downloading an experiment's dataset artifact via this logger) where the artifact metadata's 'names' key is missing (metadata.get('names') returns None) or is not a dict/list (e.g. a plain string like 'person' or an int nc).","commonSituations":"The dataset YAML uploaded with the Comet artifact had a malformed 'names' field (a string, or omitted entirely); the artifact was created manually or by an older/newer YOLOv5 version whose metadata schema differs; Comet metadata was stripped or altered when the artifact was versioned; a custom names format (e.g. comma-separated string) was used.","solutions":["Inspect the artifact metadata (logged_artifact.metadata) and fix the 'names' entry to a list like ['person', 'car'] or a dict like {0: 'person', 1: 'car'}, then re-upload the artifact.","If the source dataset YAML has a malformed 'names' field, correct it there and re-log the artifact from a fresh training run.","If you don't need artifact-based dataset restore, bypass this path: point --data directly at your local dataset YAML instead of resuming the Comet artifact.","As a last resort, patch the metadata before download: overwrite data_dict['names'] with a valid dict of length nc before calling update_data_paths."],"exampleFix":"# before (artifact metadata): metadata = {\"names\": \"person,car\", \"nc\": 2}\n# after\nmetadata = {\"names\": [\"person\", \"car\"], \"nc\": 2}\n# or equivalently\nmetadata = {\"names\": {0: \"person\", 1: \"car\"}, \"nc\": 2}","handlingStrategy":"validation","validationCode":"names = artifact_metadata.get(\"names\")\nif not isinstance(names, (dict, list)) or len(names) == 0:\n    raise ValueError(\n        f\"Comet artifact metadata 'names' must be a non-empty list or dict, got {type(names).__name__}; \"\n        \"fix the artifact metadata or point --data at a local dataset YAML\"\n    )","typeGuard":"def is_valid_names_field(names) -> bool:\n    \"\"\"True when 'names' can be normalized to {int: str}.\"\"\"\n    if isinstance(names, dict):\n        return all(isinstance(k, (int, str)) and str(k).lstrip(\"-\").isdigit() for k in names)\n    if isinstance(names, list):\n        return all(isinstance(v, str) for v in names)\n    return False","tryCatchPattern":"try:\n    data_dict = comet_logger.restore_dataset_from_artifact(...)  # or the download path\nexcept ValueError as e:\n    if \"Invalid 'names' field\" in str(e):\n        LOGGER.warning(\"Comet artifact metadata malformed; falling back to local --data YAML\")\n        data_dict = yaml_load(local_data_yaml)\n    else:\n        raise","preventionTips":["Validate dataset YAML 'names' (list or dict) before logging the dataset artifact to Comet.","Log the artifact from a run whose data dict was produced by check_font/check_dataset-normalized code so metadata matches the expected schema.","Pin the YOLOv5 version used for artifact creation and resume so the metadata schema stays consistent."],"tags":["comet","dataset","yaml","metadata","resume","mlflow-logger"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}