-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NotImplementedError: cannot instantiate 'PosixPath' on your system #10240
Comments
@totoadel 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. We've created a few short guidelines below to help users provide what we need in order to start investigating a possible problem. How to create a Minimal, Reproducible ExampleWhen asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
For Ultralytics to provide assistance your code should also be:
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem. Thank you! 😃 |
Suddenly, I run into exact the same situation. No idea how to get fore or backward with it. Did you get out of this situation? ` Traceback (most recent call last): |
@V4A001 @glenn-jocher im also facing same issue with classification, on my local system using on cpu |
me too. |
I got the same problem. |
I just added: import pathlib ...in my Jupyter Notebook and it works now. This error ocurred when I wanted to load classification model with torch.hub.load. |
@ljubanradisin @V4A001 Thank you for bringing this issue to our attention and sharing your experience. It seems that the issue you are facing is related to the Based on your feedback, it appears that substituting We appreciate you sharing the workaround you found. This information will be helpful to other users encountering the same problem when working with classification models and using Thank you for your contributions, and please don't hesitate to reach out if you have any further questions or issues. Best regards, |
permission to add for those who are new to the world of coding like me, don't forget to add the import path if the code like the one above given by ljubantomic01 if you has a problem say "NameError: name 'Path' is not defined." import pathlib |
@falahfin Absolutely, thank you for pointing that out! It's important to ensure that all necessary modules and classes are imported when modifying code to prevent For anyone else encountering similar issues, make sure to include the appropriate import statements in your code: import pathlib
from pathlib import Path
pathlib.PosixPath = pathlib.WindowsPath This will help ensure that your code runs smoothly on Windows systems when dealing with file paths. If you have any more questions or need further assistance, feel free to ask. Happy coding! 😊 |
The above solutions are not working for me in Windows |
@devendew i'm sorry to hear that the workaround isn't working for you. This issue typically arises when a model trained on a Unix-like system (such as Linux or macOS) is loaded on a Windows system. The Here's a step-by-step approach to try and resolve the issue:
If you've tried all of the above and the issue persists, it might be helpful to provide more details about the error and your environment. This would include the exact error message, the code snippet where the error occurs, and details about your Python and PyTorch versions. With more information, the community may be able to offer more targeted assistance. |
@devendew
at the beginning of the detect.py file. |
@devendew thanks adding
to detect.py helped |
@glenn-jocher ljubantomic01 Hi, thank you for solving this problem. However, I run some problem. Btw, I am doing multiprocessing for yolvo5. My code is running already when I added the import pathlib pathlib.PosixPath = pathlib.WindowsPath |
@rochellemadulara, it's great to hear that the initial issue with A few quick suggestions:
This minimal change in debugging approach could provide insights into whether the issue is with the detection process itself or with the display of the detections. |
Thanks a lot, works for me! Just for future references: If you have a windows to solve use: If you have linux (or deploying for linux) use: |
@floresdwm i'm glad to hear that the workaround resolved your issue! Your contribution in sharing the solution for both Windows and Linux users is greatly appreciated by the community. 😊 Just a quick addition:
from pathlib import Path
import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
from pathlib import Path
import pathlib
temp = pathlib.WindowsPath
pathlib.WindowsPath = pathlib.PosixPath Happy coding and don't hesitate to reach out if you face any more issues! |
This didn't work for me |
I'm sorry to hear that the solution didn't work for you. Could you please ensure that the snippet is placed correctly at the beginning of your script, and check if any other imports might interfere with this workaround? If the issue persists, feel free to provide more details about your environment and error outputs for further assistance. 😊 |
This solution worked for me! |
import pathlib This solution worked for me |
Great to hear that the solution worked for you! If you encounter any more issues or have further questions, feel free to reach out. |
I was having the same issue on windows. did not work. I had to change the pathlib.py file in the lib. `
` I commented out |
Thank you for sharing your experience. Modifying library files can lead to unexpected behavior, so it's generally recommended to avoid such changes. Instead, ensure you're using the latest version of YOLOv5 and Python, and try using forward slashes in paths on Windows. If the issue persists, please provide more details about your setup. |
Search before asking
YOLOv5 Component
No response
Bug
i train classification and when i test it i got this error
raise NotImplementedError("cannot instantiate %r on your system" NotImplementedError: cannot instantiate 'PosixPath' on your system
but when i use yolov5n-cls.pt no error happened
Environment
No response
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: