yolov5/tutorials/pytorch_hub_model_loading/ #8255
Replies: 8 comments 14 replies
-
python run.py Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): The above exception was the direct cause of the following exception: Traceback (most recent call last): kakul@Teddy MINGW64 ~/OneDrive/Desktop/Collected_Image can someone help me to rectify this error |
Beta Was this translation helpful? Give feedback.
-
Hi @LikhithaKakuluri, I see you are using Windows. Why don't you follow this tutorial? There you have a nice step by step tutorial on how to prepare your environment and run yolov5 on Windows. |
Beta Was this translation helpful? Give feedback.
-
Nothing seems to work I have already done everything I could and I keep getting the same error over and over again can someone help me with this. Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): The above exception was the direct cause of the following exception: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
-
YOLOv5 v7.0-294-gdb125a20 Python-3.12.2 torch-2.2.1+cu121 CUDA:0 (NVIDIA
GeForce RTX 3070, 8192MiB)
Traceback (most recent call last):
File "C:\Users\anony\Desktop\cheats\yolov5\hubconf.py", line 50, in
_create
model = DetectMultiBackend(path, device=device, fuse=autoshape) #
detection model
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anony\Desktop\cheats\yolov5\models\common.py", line 467,
in __init__
model = attempt_load(weights if isinstance(weights, list) else w,
device=device, inplace=True, fuse=fuse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anony\Desktop\cheats\yolov5\models\experimental.py", line
98, in attempt_load
ckpt = torch.load(attempt_download(w), map_location="cpu") # load
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\serialization.py",
line 1026, in load
return _load(opened_zipfile,
^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\serialization.py",
line 1438, in _load
result = unpickler.load()
^^^^^^^^^^^^^^^^
File
"C:\Users\anony\AppData\Local\Programs\Python\Python312\Lib\pathlib.py",
line 1422, in __new__
raise NotImplementedError(
NotImplementedError: cannot instantiate 'PosixPath' on your system
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\anony\Desktop\cheats\yolov5\hubconf.py", line 65, in
_create
model = attempt_load(path, device=device, fuse=False) # arbitrary model
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anony\Desktop\cheats\yolov5\models\experimental.py", line
98, in attempt_load
ckpt = torch.load(attempt_download(w), map_location="cpu") # load
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\serialization.py",
line 1026, in load
return _load(opened_zipfile,
^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\serialization.py",
line 1438, in _load
result = unpickler.load()
^^^^^^^^^^^^^^^^
File
"C:\Users\anony\AppData\Local\Programs\Python\Python312\Lib\pathlib.py",
line 1422, in __new__
raise NotImplementedError(
NotImplementedError: cannot instantiate 'PosixPath' on your system
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\anony\Desktop\cheats\scripts\detections.py", line 16, in
<module>
model =
torch.hub.load(str(Path(r'C:\Users\anony\Desktop\cheats\yolov5')),
'custom', path=model_path, source='local')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\hub.py",
line 566, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"C:\Users\anony\Desktop\cheats\cheats-env\Lib\site-packages\torch\hub.py",
line 595, in _load_local
model = entry(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anony\Desktop\cheats\yolov5\hubconf.py", line 88, in custom
return _create(path, autoshape=autoshape, verbose=_verbose,
device=device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anony\Desktop\cheats\yolov5\hubconf.py", line 83, in
_create
raise Exception(s) from e
Exception: cannot instantiate 'PosixPath' on your system. Cache may be out
of date, try `force_reload=True` or see
https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for
help.
I have done as you said and I still ran into the same error here is my code
from pathlib import Path
from mss import mss
import torch
import cv2
import numpy as np
MONITOR_WIDTH = 1920#game res
MONITOR_HEIGHT = 1080#game res
MONITOR_SCALE = 5#how much the screen shot is downsized by eg. 5 would be
one fifth of the monitor dimensions
region = (int(MONITOR_WIDTH/2-MONITOR_WIDTH/MONITOR_SCALE/2),int(
MONITOR_HEIGHT/2-MONITOR_HEIGHT/MONITOR_SCALE/2),int(MONITOR_WIDTH/2+
MONITOR_WIDTH/MONITOR_SCALE/2),int(MONITOR_HEIGHT/2+MONITOR_HEIGHT/
MONITOR_SCALE/2))
model_path = Path(r'C:\Users\anony\Desktop\cheats\best.pt')
model = torch.hub.load(str(Path(r'C:\Users\anony\Desktop\cheats\yolov5')),
'custom', path=model_path, source='local')
model.conf = 0.40
model.maxdet = 10
model.apm = True
with mss() as stc:
while True:
screenshot = np.array(stc.grab(region))
df = model(screenshot, size=736).pandas().xyxy[0]
for i in range(0,10):
try:
xmin = int(df.iloc[i,0])
ymin = int(df.iloc[i,1])
xmax = int(df.iloc[i,2])
ymax = int(df.iloc[i,3])
cv2.rectangle(screenshot,(xmin,ymin),(xmax,ymax), (255,0,0),
3)
except:
print("",end="")
cv2.imshow("frame",screenshot)
if(cv2.waitKey(1) == ord('l')):
cv2.destroyAllWindows()
break
…On Sat, Mar 16, 2024 at 4:33 AM Glenn Jocher ***@***.***> wrote:
@OFFT3ST <https://github.com/OFFT3ST> hey there! 👋 It looks like you're
running into a NotImplementedError related to PosixPath on Windows. This
usually happens because of the path handling difference between Unix-based
systems and Windows. Here's a quick fix you could try! 🛠️
Instead of using raw string paths like r'C:\path\to\your\model', you
might want to use Python's Path object from the pathlib library, which is
designed to handle system-dependent path formats gracefully. Here's how you
could update the script:
from pathlib import Pathimport torch
# Define model path using Path objectmodel_path = Path(r'C:\Users\anony\Desktop\cheats\best.pt')
# Load the modelmodel = torch.hub.load(str(Path(r'C:\Users\anony\Desktop\cheats\yolov5')), 'custom', path=model_path, source='local')
Converting the paths to strings when passing them to torch.hub.load might
help avoid the NotImplementedError related to PosixPath. The Path object
from pathlib should automatically handle the conversion to the correct
path string format for your operating system.
Give this a try and let us know how it goes! If you run into any more
issues, we're here to help. Happy coding! 🚀
—
Reply to this email directly, view it on GitHub
<#8255 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFZPNKBMVY2WALBSERYCGULYYP7V3AVCNFSM6AAAAABDMQT4FWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQMJQGIZDM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I encountered the error cannot instantiate 'WindowsPath' on your system, and none of the suggested solutions helped. For context, I was trying to run a custom YOLOv5 model on CVAT or simply run the model on my WSL, but each time I attempted it, I got the same error. I tried various solutions, but none worked. What I eventually realized was that I had trained my model on a Windows system using Windows CMD. So, when I tried to run the model on Linux, Ubuntu, or WSL on Windows, the error persisted. What I ended up doing was retraining the model, this time using an Ubuntu system. I used Google Colab for training, then tested the model on Ubuntu and CVAT, and it worked fine. I hope this helps anyone else encountering a similar problem, or maybe it could fix the 'PosixPath' error. |
Beta Was this translation helpful? Give feedback.
-
Hi. I have trained a custom model of YOLOv5s and have the 'best.pt' file saved on my local machine. I am trying to load the model using torch.hub to use it for inference. I am encountering the following error. Using cache found in /home/kvothe/.cache/torch/hub/ultralytics_yolov5_master Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): The above exception was the direct cause of the following exception: Traceback (most recent call last): Can anyone please help rectify this error. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am running a food detection project using pretrained yolov8s and yolov5. Yolov8s doesn't have issues, where it detected food accurately. However, yolov5 doesn't seem to work at all, I got the following error message. I loaded yolov5 using Pytorch. [2024-05-16 16:44:50,769] ERROR in app: Exception on /analyze [POST] It keeps showing this error, I guess it has something to do with theseus? |
Beta Was this translation helpful? Give feedback.
-
hi i keep getting this error again and again, and I tried the solutions here. this is my loading line: model = torch.hub.load("ultralytics/yolov5", 'custom', |
Beta Was this translation helpful? Give feedback.
-
yolov5/tutorials/pytorch_hub_model_loading/
Detailed guide on loading YOLOv5 from PyTorch Hub. Includes examples & tips on inference settings, multi-GPU inference, training and more.
https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading/
Beta Was this translation helpful? Give feedback.
All reactions