{"record":{"id":"240aca7fdee902f2","repo":"ultralytics/yolov5","slug":"model-opt-model-not-found-available-models-ar","errorCode":null,"errorMessage":"--model {opt.model} not found. Available models are: \\n","messagePattern":"--model (.+?) not found\\. Available models are: \\\\n","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"classify/train.py","lineNumber":149,"sourceCode":"        testloader = create_classification_dataloader(\n            path=test_dir,\n            imgsz=imgsz,\n            batch_size=bs // WORLD_SIZE * 2,\n            augment=False,\n            cache=opt.cache,\n            rank=-1,\n            workers=nw,\n        )\n\n    # Model\n    with torch_distributed_zero_first(LOCAL_RANK), WorkingDirectory(ROOT):\n        if Path(opt.model).is_file() or opt.model.endswith(\".pt\"):\n            model = attempt_load(opt.model, device=\"cpu\", fuse=False)\n        elif opt.model in torchvision.models.__dict__:  # TorchVision models i.e. resnet50, efficientnet_b0\n            model = torchvision.models.__dict__[opt.model](weights=\"IMAGENET1K_V1\" if pretrained else None)\n        else:\n            m = hub.list(\"ultralytics/yolov5\")  # + hub.list('pytorch/vision')  # models\n            raise ModuleNotFoundError(f\"--model {opt.model} not found. Available models are: \\n\" + \"\\n\".join(m))\n        if isinstance(model, DetectionModel):\n            LOGGER.warning(\"pass YOLOv5 classifier model with '-cls' suffix, i.e. '--model yolov5s-cls.pt'\")\n            model = ClassificationModel(model=model, nc=nc, cutoff=opt.cutoff or 10)  # convert to classification model\n        reshape_classifier_output(model, nc)  # update class count\n    for m in model.modules():\n        if not pretrained and hasattr(m, \"reset_parameters\"):\n            m.reset_parameters()\n        if isinstance(m, torch.nn.Dropout) and opt.dropout is not None:\n            m.p = opt.dropout  # set dropout\n    for p in model.parameters():\n        p.requires_grad = True  # for training\n    model = model.to(device)\n\n    # Info\n    if RANK in {-1, 0}:\n        model.names = trainloader.dataset.classes  # attach class names\n        model.transforms = testloader.dataset.torch_transforms  # attach inference transforms\n        model_info(model)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/classify/train.py#L131-L167","documentation":"classify/train.py raises ModuleNotFoundError when the --model value is neither an existing file, nor a string ending in .pt, nor a key in torchvision.models.__dict__. The message lists the models available from the ultralytics/yolov5 GitHub hub so the user can pick a valid name. It fires in the classify training entrypoint after dataset setup, right before the model is constructed.","triggerScenarios":"Running classify/train.py with a misspelled or nonexistent --model (e.g. --model yolov5s-clss or --model foo) where the file does not exist on disk; passing a torchvision architecture name that is invalid for the installed torchvision version; passing a bare name like 'resnet50' when torchvision was not imported correctly or the name was removed.","commonSituations":"Typos in shell scripts or wandb sweeps; using a custom checkpoint path that has not been downloaded yet; assuming any torchvision name works on an old torchvision pinned by YOLOv5 CI; forgetting the '-cls' suffix convention so users type arbitrary names.","solutions":["Use a shipped classifier checkpoint name, e.g. --model yolov5n-cls.pt (the .pt suffix routes to attempt_download).","If pointing at a local checkpoint, verify the path exists: python -c \"from pathlib import Path; print(Path('my.pt').is_file())\" before training.","For torchvision backbones, confirm the name is valid for your installed version: python -c \"import torchvision; print('resnet50' in torchvision.models.__dict__)\".","Re-run and pick a name from the model list printed in the error message itself."],"exampleFix":"# before\npython classify/train.py --model yolov5s-clss --data imagenet ...\n\n# after\npython classify/train.py --model yolov5s-cls.pt --data imagenet ...","handlingStrategy":"validation","validationCode":"from pathlib import Path\nimport torchvision\n\ndef valid_classify_model(name: str) -> bool:\n    return Path(name).is_file() or name.endswith('.pt') or name in torchvision.models.__dict__\n\nassert valid_classify_model(opt.model), f\"--model {opt.model} is not a file, .pt, or torchvision model\"","typeGuard":"def is_loadable_model_name(name: str) -> bool:\n    \"\"\"True if classify/train.py will accept this --model value.\"\"\"\n    return Path(name).is_file() or name.endswith(\".pt\") or name in torchvision.models.__dict__","tryCatchPattern":null,"preventionTips":["Standardize on official '-cls.pt' checkpoint names in scripts and sweeps.","Assert the model path exists before launching long training jobs.","Treat the model list in the error message as the source of valid names."],"tags":["classification","model-loading","cli","typo"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}