ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
23.76k stars 4.74k forks source link

PosixPath Error after loading trained Best.pt file #11648

Open she5o opened 1 week ago

she5o commented 1 week ago

Search before asking

Question

I Have a ASL YOLOV5 realtime detection model, everything is working perfectly until I decide to add the Best.pt file to my model to run it with the realtime detection file, I keep getting this error :NotImplementedError: cannot instantiate 'PosixPath' on your system

I need help please

Additional

No response

github-actions[bot] commented 1 week ago

👋 Hello @she5o, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 1 week ago

It seems like you're facing a compatibility issue with PosixPath on your system. This can occur if your environment doesn't handle pathlib.Path objects correctly, which are used extensively in the model's I/O operations.

You can workaround this issue by explicitly converting Path objects to strings when loading the model. Here's a small modification in Python to use with your YOLO model:

from ultralytics import YOLO
import pathlib

# Load a model
model_path = pathlib.Path('best.pt').as_posix()  # Convert PosixPath to string
model = YOLO(model_path)  # Load using the string path

# Now proceed with your real-time detection tasks

This forces the path to be treated as a string, which should be compatible across different systems. Give this a try and see if it resolves your issue! 🚀