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

[Load Seg model][RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted] #2

Open
tomguluson92 opened this issue Sep 5, 2022 · 2 comments

Comments

@tomguluson92
Copy link

Dear author,
I have encountered an error when I try to call the segmentation network. I sincerely need your help, thank you!

import sys
sys.path.insert(0,'/mnt/workspace/project/2022AW/09/HDR/')
import numpy as np
import cv2
from utils.preprocessing import process_bbox, generate_patch_image
from PIL import Image
from mmseg.apis import inference_segmentor, init_segmentor
import matplotlib.pyplot as plt
%matplotlib inline


# segmentor
seg_cfg_file = "./configs/segformer/segformer_mit-b5_256x256_interhand_1101.py"
seg_model = init_segmentor(
    config=seg_cfg_file,
    checkpoint='./demo_work_dirs/Interhand_seg/iter_237500.pth',
)

Error

/mnt/workspace/project/2022AW/09/HDR/mmseg/models/backbones/mit.py:311: UserWarning: DeprecationWarning: pretrained is a deprecated, please use "init_cfg" instead
  warnings.warn('DeprecationWarning: pretrained is a deprecated, '
Use load_from_local loader
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-db1a521dfe39> in <module>
      3 seg_model = init_segmentor(
      4     config=seg_cfg_file,
----> 5     checkpoint='./demo_work_dirs/Interhand_seg/iter_237500.pth',
      6 )

/mnt/workspace/project/2022AW/09/HDR/mmseg/apis/inference.py in init_segmentor(config, checkpoint, device)
     33     model = build_segmentor(config.model, test_cfg=config.get('test_cfg'))
     34     if checkpoint is not None:
---> 35         checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
     36         model.CLASSES = checkpoint['meta']['CLASSES']
     37         model.PALETTE = checkpoint['meta']['PALETTE']

/home/pai/lib/python3.6/site-packages/mmcv/runner/checkpoint.py in load_checkpoint(model, filename, map_location, strict, logger, revise_keys)
    525         dict or OrderedDict: The loaded checkpoint.
    526     """
--> 527     checkpoint = _load_checkpoint(filename, map_location, logger)
    528     # OrderedDict is a subclass of dict
    529     if not isinstance(checkpoint, dict):

/home/pai/lib/python3.6/site-packages/mmcv/runner/checkpoint.py in _load_checkpoint(filename, map_location, logger)
    464            information, which depends on the checkpoint.
    465     """
--> 466     return CheckpointLoader.load_checkpoint(filename, map_location, logger)
    467 
    468 

/home/pai/lib/python3.6/site-packages/mmcv/runner/checkpoint.py in load_checkpoint(cls, filename, map_location, logger)
    242         class_name = checkpoint_loader.__name__
    243         mmcv.print_log(f'Use {class_name} loader', logger)
--> 244         return checkpoint_loader(filename, map_location)
    245 
    246 

/home/pai/lib/python3.6/site-packages/mmcv/runner/checkpoint.py in load_from_local(filename, map_location)
    259     if not osp.isfile(filename):
    260         raise IOError(f'{filename} is not a checkpoint file')
--> 261     checkpoint = torch.load(filename, map_location=map_location)
    262     return checkpoint
    263 

/home/pai/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    598             # reset back to the original position.
    599             orig_position = opened_file.tell()
--> 600             with _open_zipfile_reader(opened_file) as opened_zipfile:
    601                 if _is_torchscript_zip(opened_zipfile):
    602                     warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive"

/home/pai/lib/python3.6/site-packages/torch/serialization.py in __init__(self, name_or_buffer)
    240 class _open_zipfile_reader(_opener):
    241     def __init__(self, name_or_buffer) -> None:
--> 242         super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
    243 
    244 

RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted
@jin-s13
Copy link
Collaborator

jin-s13 commented Sep 6, 2022

Could you check if the ckpt file ./demo_work_dirs/Interhand_seg/iter_237500.pth is corrupted?

@tomguluson92
Copy link
Author

Could you check if the ckpt file ./demo_work_dirs/Interhand_seg/iter_237500.pth is corrupted?

Thanks for response! So how to check the ckpt file? I download it from the link provided in the README.md and unzip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants