{"record":{"id":"09de5b62f3cd5441","repo":"ultralytics/yolov5","slug":"task-opt-task-not-in-train-val-test-09de5b","errorCode":null,"errorMessage":"--task {opt.task} not in (\"train\", \"val\", \"test\", \"speed\", \"study\")","messagePattern":"--task (.+?) not in \\(\"train\", \"val\", \"test\", \"speed\", \"study\"\\)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"val.py","lineNumber":523,"sourceCode":"            # python val.py --task speed --data coco.yaml --batch 1 --weights yolov5n.pt yolov5s.pt...\n            opt.conf_thres, opt.iou_thres, opt.save_json = 0.25, 0.45, False\n            for opt.weights in weights:\n                run(**vars(opt), plots=False)\n\n        elif opt.task == \"study\":  # speed vs mAP benchmarks\n            # python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n.pt yolov5s.pt...\n            for opt.weights in weights:\n                f = f\"study_{Path(opt.data).stem}_{Path(opt.weights).stem}.txt\"  # filename to save to\n                x, y = list(range(256, 1536 + 128, 128)), []  # x axis (image sizes), y axis\n                for opt.imgsz in x:  # img-size\n                    LOGGER.info(f\"\\nRunning {f} --imgsz {opt.imgsz}...\")\n                    r, _, t = run(**vars(opt), plots=False)\n                    y.append(r + t)  # results and times\n                np.savetxt(f, y, fmt=\"%10.4g\")  # save\n            subprocess.run([\"zip\", \"-r\", \"study.zip\", *glob.glob(\"study_*.txt\")], check=False)\n            plot_val_study(x=x)  # plot\n        else:\n            raise NotImplementedError(f'--task {opt.task} not in (\"train\", \"val\", \"test\", \"speed\", \"study\")')\n\n\nif __name__ == \"__main__\":\n    opt = parse_opt()\n    main(opt)\n","sourceCodeStart":505,"sourceCodeEnd":529,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/val.py#L505-L529","documentation":"Raised at the bottom of val.py's main() when opt.task is not one of the five supported validation tasks: 'train', 'val', 'test', 'speed', 'study'. main() dispatches via if/elif on opt.task; any other string falls through to NotImplementedError. 'speed' benchmarks inference speed and 'study' sweeps image sizes across weights, so only those five strings are meaningful here.","triggerScenarios":"Running python val.py --task <anything-else>, e.g. --task detect, --task trainval, --task Validation (case-sensitive), --task inference, or omitting the default via a script that sets opt.task programmatically to an invalid value.","commonSituations":"Confusing val.py's task vocabulary with train.py or detect.py (people try --task detect or --task predict); casing/typo errors; hyperparameter evolution or wrapper scripts that inject an unsupported task string; older YOLO versions with different task lists.","solutions":["Use one of the five allowed values: --task val (default), --task train, --task test, --task speed, or --task study.","If you meant detection inference, use detect.py instead of val.py --task detect.","Audit wrapper scripts/evolution configs that set opt.task programmatically and clamp the value to the allowed set."],"exampleFix":"# before\npython val.py --task detect --weights yolov5s.pt\n# after\npython detect.py --weights yolov5s.pt --source data/images\n# or, for metrics on the val split\npython val.py --task val --weights yolov5s.pt --data coco.yaml","handlingStrategy":"validation","validationCode":"VAL_TASKS = (\"train\", \"val\", \"test\", \"speed\", \"study\")\nassert opt.task in VAL_TASKS, f\"--task must be one of {VAL_TASKS}; for inference use detect.py, not val.py\"","typeGuard":"def is_valid_val_task(task: str) -> bool:\n    \"\"\"val.py supports exactly these task values, case-sensitive.\"\"\"\n    return isinstance(task, str) and task in {\"train\", \"val\", \"test\", \"speed\", \"study\"}","tryCatchPattern":"try:\n    main(opt)\nexcept NotImplementedError as e:\n    if \"not in\" in str(e):\n        print(f\"Unsupported --task {opt.task!r}; valid: train, val, test, speed, study. Use detect.py for inference.\")\n    else:\n        raise","preventionTips":["Remember the task vocabularies: val.py takes train/val/test/speed/study; detection inference lives in detect.py.","Copy CLI flags from val.py's parse_opt help text rather than from other scripts.","In wrapper scripts, validate task strings against the allowed set before invoking val.py."],"tags":["validation","cli-args","task","val"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}