Skip to content
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

Exception: [Errno 2] No such file or directory: 'lib\\best.pt'. Cache may be out of date, try force_reload=True or see https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help. #11530

Closed
2 tasks done
developerlaborotory opened this issue May 14, 2023 · 13 comments
Labels
bug Something isn't working Stale

Comments

@developerlaborotory
Copy link

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Other

Bug

When i try and use YOLOv5, i get this.
raceback (most recent call last):
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 49, in _create
model = DetectMultiBackend(path, device=device, fuse=autoshape) # detection model
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\models\common.py", line 344, in init
model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse)
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\models\experimental.py", line 79, in attempt_load
ckpt = torch.load(attempt_download(w), map_location='cpu') # load
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 791, in load
with _open_file_like(f, 'rb') as opened_file:
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 271, in _open_file_like
return _open_file(name_or_buffer, mode)
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 252, in init
super().init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'lib\best.pt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 60, in _create
model = attempt_load(path, device=device, fuse=False) # arbitrary model
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\models\experimental.py", line 79, in attempt_load
ckpt = torch.load(attempt_download(w), map_location='cpu') # load
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 791, in load
with _open_file_like(f, 'rb') as opened_file:
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 271, in _open_file_like
return _open_file(name_or_buffer, mode)
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\serialization.py", line 252, in init
super().init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'lib\best.pt'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "c:\Users\ismae\Desktop\lunar-main\lunarbot v2.py", line 97, in
main()
File "c:\Users\ismae\Desktop\lunar-main\lunarbot v2.py", line 44, in main
lunar = Aimbot(collect_data = "collect_data" in sys.argv)
File "c:\Users\ismae\Desktop\lunar-main\lib\aimbot.py", line 65, in init
self.model = torch.hub.load('ultralytics/yolov5', 'custom', path='lib/best.pt', force_reload = True)
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\hub.py", line 558, in load
File "C:\Users\ismae\anaconda3\lib\site-packages\torch\hub.py", line 587, in _load_local
model = entry(*args, **kwargs)
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 83, in custom
return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
File "C:\Users\ismae/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py", line 78, in _create
raise Exception(s) from e
Exception: [Errno 2] No such file or directory: 'lib\best.pt'. 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 uninstalled modules, re installed modules and downloaded and redownloaded the requirements.txt so many times. How on earth do i fix this?

Environment

  • OS: Windows 10
  • Anaconda Python ver 3.10.9

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@developerlaborotory developerlaborotory added the bug Something isn't working label May 14, 2023
@github-actions
Copy link
Contributor

👋 Hello @curiousdarko, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

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.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

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

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@curiousdarko hello! Thank you for reporting this issue. The error message you received suggests that the YOLOv5 cache may be out of date, and recommends trying force_reload=True.

If you have already tried uninstalling and re-installing the required modules and downloading the requirements.txt multiple times, then you could try using force_reload=True as suggested in the error message. This will force the cache to be reloaded.

If that still doesn't work, you can refer to our documentation on PyTorch Hub Model Loading or submit a PR to help improve YOLOv5.

Hope this helps!

@developerlaborotory
Copy link
Author

@glenn-jocher how do i use force_reload=True?

@glenn-jocher
Copy link
Member

You can try using force_reload=True in the following way to force the cache to be reloaded:

import torch

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)

force_reload=True will ensure that the cache is updated and any outdated files are removed before attempting to load the model. This may take a little bit longer as the model will need to be re-downloading from the source, but it should help resolve any issues caused by outdated cache files.

@developerlaborotory
Copy link
Author

i have tried, but still get the same error, can I give you my code?

@glenn-jocher
Copy link
Member

@curiousdarko thanks for trying force_reload=True. It's possible that the error is occurring for a different reason. We'll be happy to help you figure it out.

Sharing your code will definitely help us understand what might be going wrong. Could you please provide us with the code or a minimal reproducible example, along with any error messages you're getting? This will enable us to provide you with a more specific and accurate solution to your problem.

Looking forward to hearing back from you!

@developerlaborotory
Copy link
Author

@glenn-jocher https://github.com/curiousdarko/aicheat all my code is in this repo, main issue is in darko.py

@glenn-jocher
Copy link
Member

@curiousdarko, thank you for sharing your code. We understand that you're encountering issues in your darko.py script, and we're here to help.

Upon reviewing your file, we see that there are several errors occurring. Here are some potential solutions for you to consider:

  1. In Darko class, you have commented out self.weights in load_model function. Uncommenting that should fix the error on that line.

  2. You may also want to add device argument to the load_model function so the loaded model is sent to the correct device. For example:

def load_model(self, input_size, device='cpu'):
    ...
    self.model.to(device)
    ...
  1. In predict function you should change cpu_device() to torch.device('cpu'). This will fix the error on that line.

  2. You can also change the line model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) in models.py to model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, force_reload=True). The force_reload=True flag may help if you're encountering issues with the model.

We hope these suggestions help you resolve the issues in your code. Please let us know if you have any further questions or if you're encountering additional issues.

Best regards.

@developerlaborotory
Copy link
Author

where is there a models.py? could you help me fix the code on this?

@glenn-jocher
Copy link
Member

@curiousdarko thank you for reaching out to us. We apologize for the confusion caused. We understand that models.py was not included in your repo.

Regarding your code, as mentioned earlier, you may try uncommenting self.weights in the load_model function of the Darko class and adding device argument to the load_model function so the loaded model is sent to the correct device, for example:

def load_model(self, input_size, device='cpu'):
    ...
    self.model.to(device)
    ...

You can change the cpu_device() function in the predict method to torch.device('cpu').

In addition, you can try using force_reload=True in the torch.hub.load function in your code, which may fix the issues you're encountering.

We hope that these suggestions help in fixing the issues you're having. Please feel free to let us know if these changes work or if you require any further assistance.

Thank you.

@developerlaborotory
Copy link
Author

i dont see what code you are referring to.

@glenn-jocher
Copy link
Member

Hello, @curiousdarko, we apologize for any confusion. We were referring to the darko.py file in your repository. We noticed that you commented out self.weights in the load_model function of the Darko class. Uncommenting this code block may help resolve the error you're encountering.

Additionally, you should also add a device argument to the load_model function so that the loaded model is sent to the correct device. Here is an example:

def load_model(self, input_size, device='cpu'):
    ...
    self.model.to(device)
    ...

You may also want to change the cpu_device() function in the predict method to torch.device('cpu').

Finally, adding force_reload=True to the torch.hub.load function in the models.py file may help with the errors you're encountering while loading the model.

We hope these suggestions help resolve the issues you're encountering. Please don't hesitate to let us know if you require any further assistance. Thank you.

@github-actions
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 16, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants