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

Torch RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted #11414

Closed
1 task done
vanshreddy opened this issue Apr 22, 2023 · 7 comments
Labels
question Further information is requested Stale

Comments

@vanshreddy
Copy link

vanshreddy commented Apr 22, 2023

Search before asking

  • I have searched the YOLOv5 issues and discussions and found no similar questions. Any leads is much appreciated

Question

Hey have this error from torch. I load the yolov5 with model = torch.hub.load( "ultralytics/yolov5", "custom", path=f"/app/weights/{model_file}" ) . I am running the code in a container

YOLOv5 🚀 2023-4-22 Python-3.8.0 torch-1.11.0a0+gitbc2c6ed CUDA:0 (NVIDIA Tegra X1, 3964MiB)

Traceback (most recent call last):
  File "/root/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 49, in _create
    model = DetectMultiBackend(path, device=device, fuse=autoshape)  # detection model
  File "/root/.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 "/root/.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 "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 60, in _create
    model = attempt_load(path, device=device, fuse=False)  # arbitrary model
  File "/root/.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 "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted

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

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/app/src/petra/petra_camera_publisher/publisher_main.py", line 63, in <module>
    yolov5_model = load_yolov5_model_on_gpu()
  File "/app/src/petra/petra_camera_publisher/yolov5_utils/helper.py", line 70, in load_yolov5_model_on_gpu
    model = torch.hub.load(
  File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 404, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 433, in _load_local
    model = entry(*args, **kwargs)
  File "/root/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 83, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "/root/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 78, in _create
    raise Exception(s) from e
Exception: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted. Cache may be out of date, try `force_reload=True` or see https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help.

Additional

@vanshreddy vanshreddy added the question Further information is requested label Apr 22, 2023
@github-actions
Copy link
Contributor

👋 Hello @vanshreddy, 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

@vanshreddy it seems like PyTorch is having trouble reading the zip archive containing the model weights. As suggested in the error message, you can try to force_reload=True (e.g. torch.hub.load("ultralytics/yolov5", "custom", path="path/to/weights", force_reload=True)) to help reload your cache.

Alternatively, you could try to download the weights manually and then load the model from the local path (e.g. torch.hub.load("ultralytics/yolov5", "custom", path="path/to/local/weights.pt")). If you have already downloaded the weights, make sure to double-check that the archived zip file is not corrupted.

If these steps do not help, please let me know and provide more information on your environment setup, the dataset used, and the distribution of images and classes.

@vanshreddy
Copy link
Author

So i have tried force_reload but it gives me the same error. I will try loading the model manually let you know if that works.

@glenn-jocher
Copy link
Member

@vanshreddy okay, feel free to let me know if loading the model manually works or not. If not, please provide more information on your environment setup, the dataset used, and the distribution of images and classes, so I can help you better.

@ake020675
Copy link

loading the model manually works for me.

@glenn-jocher
Copy link
Member

@ake020675 thank you for letting us know, we're glad to hear that loading the model manually worked for you. If you have any further issues or questions, feel free to ask.

@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
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants