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"
)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.