FileNotFoundError with invalid path

I have getting this error:-
FileNotFoundError: [Errno 2] No such file or directory: ‘C:/Users/HP/Repositories/Projects/candy_images/models/runs/detect/train/weights\weights/best.pt’

But my code is this:-

import roboflow

rf = roboflow.Roboflow(api_key=" : }( ")

workspace = rf.workspace(" : }( “)
project = workspace.project(” : }( ")

workspace.deploy_model(
model_type=“yolov8”,
model_path=“C:/Users/HP/Repositories/Projects/candy_images/models/runs/detect/train/weights”,
project_ids=[" : }( "],
model_name=“yolov8-my_model”
)

Why getting this kind of invalid error on another path?

Project type is : Object Detection
OS is : Windows 11

I build my model on Roboflow ui and downloaded that into my local as zip.

My structure is:

-/
├── main.py
├── data.yaml
├── README.dataset.txt
├── README.roboflow.txt
├── train/
│ ├── images/
│ └── labels/
├── valid/
│ ├── images/
│ └── labels/
└── test/
├── images/
└── labels/

I hope you will assist me :slight_smile:

workspace.deploy_model() builds the full path to your weights like this:

full_path = Path(model_path) / "weights" / "best.pt"   # default `filename`

So if you pass a directory that already ends with weights, the code will try to open
…/weights/weights/best.pt, which of course does not exist. (docs.roboflow.com)

Option 1 – point one level higher

workspace.deploy_model(
    model_type="yolov8",
    # directory that *contains* the `weights/` folder
    model_path=r"C:\Users\HP\Repositories\Projects\candy_images\models\runs\detect\train",
    project_ids=["<your-project-id>"],
    model_name="yolov8-my_model"
)

Option 2 – keep the same folder but override the filename

workspace.deploy_model(
    model_type="yolov8",
    model_path=r"C:\Users\HP\Repositories\Projects\candy_images\models\runs\detect\train\weights",
    filename="best.pt",                 # no extra `weights/` added
    project_ids=["<your-project-id>"],
    model_name="yolov8-my_model"
)