{"record":{"id":"ba4d1ec31c8c4471","repo":"ultralytics/yolov5","slug":"task-opt-task-not-in-train-val-test","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":"segment/val.py","lineNumber":461,"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":443,"sourceCodeEnd":467,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/segment/val.py#L443-L467","documentation":"segment/val.py's main() raises NotImplementedError when opt.task is not one of the five accepted strings ('train', 'val', 'test', 'speed', 'study'). The task value selects which branch of the validation/study driver runs; an unrecognized value falls through to the else. Because parse_opt does not restrict --task to choices, any string is accepted at argparse level and only rejected here at runtime.","triggerScenarios":"Running segment/val.py --task valid or --task validation (common synonyms); a typo like --task tes; passing an empty string via a wrapper script or wandb sweep that leaves the field blank.","commonSituations":"Sweep/hyperparameter frameworks injecting arbitrary strings; scripts copied from detect/val.py where tasks differ; non-native-English synonyms for 'validation'.","solutions":["Use exactly one of: --task train, --task val, --task test, --task speed, --task study.","Check the value in your wrapper script before invoking val.py.","Note that plain validation is 'val', not 'valid'."],"exampleFix":"# before\npython segment/val.py --task valid --weights yolov5s-seg.pt --data coco.yaml\n\n# after\npython segment/val.py --task val --weights yolov5s-seg.pt --data coco.yaml","handlingStrategy":"validation","validationCode":"VALID_TASKS = ('train', 'val', 'test', 'speed', 'study')\n\ndef task_valid(task: str) -> bool:\n    return task in VALID_TASKS","typeGuard":"VALID_TASKS = (\"train\", \"val\", \"test\", \"speed\", \"study\")\n\ndef is_valid_task(task: str) -> bool:\n    \"\"\"True if segment/val.py accepts this --task value.\"\"\"\n    return task in VALID_TASKS","tryCatchPattern":null,"preventionTips":["Constrain the value in wrappers: argparse choices=VALID_TASKS fails at parse time with a clearer message.","Validate sweep configs' task fields before launch."],"tags":["segmentation","validation","cli","arguments"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}