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

Cache may be out of date even after: force_reload = True #5923

Closed
1 of 2 tasks
niclastrelle opened this issue Dec 8, 2021 · 5 comments
Closed
1 of 2 tasks

Cache may be out of date even after: force_reload = True #5923

niclastrelle opened this issue Dec 8, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@niclastrelle
Copy link

niclastrelle commented Dec 8, 2021

Search before asking

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

YOLOv5 Component

PyTorch Hub

Bug

Following exception:

Exception: Cache may be out of date, try force_reload=True. See https://github.com/ultralytics/yolov5/issues/36 for help.

tried the trick with:

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

but still wont work.

Full error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/.cache/torch/hub/ultralytics_yolov5_master/utils/downloads.py in safe_download(file, url, url2, min_bytes, error_msg)
     29         print(f'Downloading {url} to {file}...')
---> 30         torch.hub.download_url_to_file(url, str(file))
     31         assert file.exists() and file.stat().st_size > min_bytes, assert_msg  # check

/usr/local/lib/python3.6/dist-packages/torch/hub.py in download_url_to_file(url, dst, hash_prefix, progress)
    471         with tqdm(total=file_size, disable=not progress,
--> 472                   unit='B', unit_scale=True, unit_divisor=1024) as pbar:
    473             while True:

/usr/local/lib/python3.6/dist-packages/tqdm/notebook.py in __init__(self, *args, **kwargs)
    241         total = self.total * unit_scale if self.total else self.total
--> 242         self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
    243         self.container.pbar = proxy(self)

/usr/local/lib/python3.6/dist-packages/tqdm/notebook.py in status_printer(_, total, desc, ncols)
    115             raise ImportError(
--> 116                 "IProgress not found. Please update jupyter and ipywidgets."
    117                 " See https://ipywidgets.readthedocs.io/en/stable"

ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/.cache/torch/hub/ultralytics_yolov5_master/utils/downloads.py in safe_download(file, url, url2, min_bytes, error_msg)
     32     except Exception as e:  # url2
---> 33         file.unlink(missing_ok=True)  # remove partial downloads
     34         print(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...')

TypeError: unlink() got an unexpected keyword argument 'missing_ok'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py in _create(name, pretrained, channels, classes, autoshape, verbose, device)
     45         if pretrained and channels == 3 and classes == 80:
---> 46             model = DetectMultiBackend(path, device=device)  # download/load FP32 model
     47             # model = models.experimental.attempt_load(path, map_location=device)  # download/load FP32 model

~/.cache/torch/hub/ultralytics_yolov5_master/models/common.py in __init__(self, weights, device, dnn)
    298         stride, names = 64, [f'class{i}' for i in range(1000)]  # assign defaults
--> 299         attempt_download(w)  # download if not local
    300 

~/.cache/torch/hub/ultralytics_yolov5_master/utils/downloads.py in attempt_download(file, repo)
     74                           min_bytes=1E5,
---> 75                           error_msg=f'{file} missing, try downloading from https://github.com/{repo}/releases/')
     76 

~/.cache/torch/hub/ultralytics_yolov5_master/utils/downloads.py in safe_download(file, url, url2, min_bytes, error_msg)
     37         if not file.exists() or file.stat().st_size < min_bytes:  # check
---> 38             file.unlink(missing_ok=True)  # remove partial downloads
     39             print(f"ERROR: {assert_msg}\n{error_msg}")

TypeError: unlink() got an unexpected keyword argument 'missing_ok'

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

Exception                                 Traceback (most recent call last)
<ipython-input-18-feae0d81b081> in <module>
      3 from tqdm import tqdm
      4 # Model
----> 5 model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, force_reload=True)
      6 
      7 # Images

/usr/local/lib/python3.6/dist-packages/torch/hub.py in load(repo_or_dir, model, source, force_reload, verbose, skip_validation, *args, **kwargs)
    397         repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation)
    398 
--> 399     model = _load_local(repo_or_dir, model, *args, **kwargs)
    400     return model
    401 

/usr/local/lib/python3.6/dist-packages/torch/hub.py in _load_local(hubconf_dir, model, *args, **kwargs)
    426 
    427     entry = _load_entry_from_hubconf(hub_module, model)
--> 428     model = entry(*args, **kwargs)
    429 
    430     sys.path.remove(hubconf_dir)

~/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py in yolov5s(pretrained, channels, classes, autoshape, verbose, device)
     78 def yolov5s(pretrained=True, channels=3, classes=80, autoshape=True, verbose=True, device=None):
     79     # YOLOv5-small model https://github.com/ultralytics/yolov5
---> 80     return _create('yolov5s', pretrained, channels, classes, autoshape, verbose, device)
     81 
     82 

~/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py in _create(name, pretrained, channels, classes, autoshape, verbose, device)
     63         help_url = 'https://github.com/ultralytics/yolov5/issues/36'
     64         s = 'Cache may be out of date, try `force_reload=True`. See %s for help.' % help_url
---> 65         raise Exception(s) from e
     66 
     67 

Exception: Cache may be out of date, try `force_reload=True`. See https://github.com/ultralytics/yolov5/issues/36 for help.

Environment

No response

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!
@niclastrelle niclastrelle added the bug Something isn't working label Dec 8, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2021

👋 Hello @niclastrelle, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at [email protected].

Requirements

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

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

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

CI CPU testing

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

@glenn-jocher
Copy link
Member

glenn-jocher commented Dec 8, 2021

@niclastrelle your environment does not meet the requirements. Root error is:

TypeError: unlink() got an unexpected keyword argument 'missing_ok'

Please ensure you meet all dependency requirements if you are attempting to run YOLOv5 locally. If in doubt, create a new virtual Python 3.8 environment, clone the latest repo (code changes daily), and pip install -r requirements.txt again. We also highly recommend using one of our verified environments below.

Requirements

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

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

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

CI CPU testing

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

@midiya
Copy link

midiya commented Jan 18, 2022

your problem will be fixed after you fix this error : ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

you should use this command if using pip : pip install ipywidgets or : conda install -c conda-forge ipywidgets with conda.

@RANA-ATI
Copy link

RANA-ATI commented Mar 20, 2023

Same Error

File ~/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py:49, in _create(name, pretrained, channels, classes, autoshape, verbose, device)
48 try:
---> 49 model = DetectMultiBackend(path, device=device, fuse=autoshape) # detection model
50 if autoshape:

File ~/.cache\torch\hub\ultralytics_yolov5_master\models\common.py:344, in DetectMultiBackend.init(self, weights, device, dnn, data, fp16, fuse)
343 if pt: # PyTorch
--> 344 model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse)
345 stride = max(int(model.stride.max()), 32) # model stride

File ~/.cache\torch\hub\ultralytics_yolov5_master\models\experimental.py:80, in attempt_load(weights, device, inplace, fuse)
79 ckpt = torch.load(attempt_download(w), map_location='cpu') # load
---> 80 ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model
82 # Model compatibility updates

KeyError: 'model'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
File ~/.cache\torch\hub\ultralytics_yolov5_master\hubconf.py:60, in _create(name, pretrained, channels, classes, autoshape, verbose, device)
59 except Exception:
---> 60 model = attempt_load(path, device=device, fuse=False) # arbitrary model
...
76 help_url = 'https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading'
77 s = f'{e}. Cache may be out of date, try force_reload=True or see {help_url} for help.'
---> 78 raise Exception(s) from e

Exception: 'model'. 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 trained the yolov5 model on custom dataset over colab and saved the model to use it for prediction over my local PC. But after trying everything, even making new env cant able to do that

CODE IS:

import torch
import cv2

from utils.plots import plot_one_box

def countTree(img):
# Load the trained model from the checkpoint file
# model = torch.hub.load('ultralytics/yolov5', 'custom',
# path='weights/yolov5_model.pt', force_reload=True)
device = torch.device('cpu')
model = torch.hub.load('ultralytics/yolov5', 'custom',
path='weights/yolov5_model.pt', force_reload=True, device=device)

results = model(img)

# for result in results.xyxy[0]:
#     plot_one_box(result[:4], image, label=f'{result[5]} {result[4]:.2f}')

# cv2.imshow('Image', image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

num_bboxes = len(results.xyxy[0])
return num_bboxes

@glenn-jocher
Copy link
Member

@RANA-ATI the error KeyError: 'model' thrown by the code, indicates a problem during the model loading process which may be due to a variety of reasons. I recommend the following actions:

  1. Ensure the path to the model weights file 'weights/yolov5_model.pt' is correct and the file is accessible.

  2. Verify that the YOLOv5 model was trained using the same version of the YOLOv5 code as you're using for inference. Inconsistent versions can cause compatibility issues.

  3. Confirm that the custom model checkpoint file 'yolov5_model.pt' is not corrupted and can be loaded independently.

Additionally, I see that you are specifying device=cpu in your torch.hub.load call. Ensure this is appropriate for your local PC setup and that there are no conflicting settings causing issues.

Please double-check these points, and if the issue persists, I recommend retraining the model in the same environment where you intend to use it for inference, to ensure compatibility and prevent any issues related to environment mismatch.

If you run into further issues, feel free to visit our documentation, or if you encounter a bug, please submit a new issue for assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants