super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer)) RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted
时间: 2024-04-26 18:22:59 浏览: 192
这个错误通常是由于 PyTorch 文件读取器无法读取损坏的 zip 归档文件或者文件格式不正确导致的。建议检查文件是否完整或者重新下载文件,确保文件格式正确。如果问题仍然存在,可以尝试使用其他工具打开文件,比如 WinRAR 或 7-Zip 等。如果问题仍然存在,可以考虑咨询 PyTorch 社区或者寻求专业技术支持。
相关问题
Traceback (most recent call last): File "DT_001_X01_P01.py", line 150, in DT_001_X01_P01.Module.load_model File "/home/kejia/Server/tf/Bin_x64/DeepLearning/DL_Lib_02/mmdet/apis/inference.py", line 42, in init_detector checkpoint = load_checkpoint(model, checkpoint, map_location=map_loc) File "/home/kejia/Server/tf/Bin_x64/DeepLearning/DL_Lib_02/mmcv/runner/checkpoint.py", line 529, in load_checkpoint checkpoint = _load_checkpoint(filename, map_location, logger) File "/home/kejia/Server/tf/Bin_x64/DeepLearning/DL_Lib_02/mmcv/runner/checkpoint.py", line 467, in _load_checkpoint return CheckpointLoader.load_checkpoint(filename, map_location, logger) File "/home/kejia/Server/tf/Bin_x64/DeepLearning/DL_Lib_02/mmcv/runner/checkpoint.py", line 244, in load_checkpoint return checkpoint_loader(filename, map_location) File "/home/kejia/Server/tf/Bin_x64/DeepLearning/DL_Lib_02/mmcv/runner/checkpoint.py", line 261, in load_from_local checkpoint = torch.load(filename, map_location=map_location) File "torch/serialization.py", line 594, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "torch/serialization.py", line 853, in _load result = unpickler.load() File "torch/serialization.py", line 845, in persistent_load load_tensor(data_type, size, key, _maybe_decode_ascii(location)) File "torch/serialization.py", line 834, in load_tensor loaded_storages[key] = restore_location(storage, location) File "torch/serialization.py", line 175, in default_restore_location result = fn(storage, location) File "torch/serialization.py", line 157, in _cuda_deserialize return obj.cuda(device) File "torch/_utils.py", line 71, in _cuda with torch.cuda.device(device): File "torch/cuda/__init__.py", line 225, in __enter__ self.prev_idx = torch._C._cuda_getDevice() File "torch/cuda/__init__.py", line 164, in _lazy_init "Cannot re-initialize CUDA in forked subprocess. " + msg) RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method ('异常抛出', None) DT_001_X01_P01 load_model ret=1, version=V1.0.0.0
根据你提供的错误信息,看起来是在使用多进程时遇到了 CUDA 初始化错误。错误信息中指出,无法在 fork 的子进程中重新初始化 CUDA。为了在多进程中使用 CUDA,你需要使用 'spawn' 启动方法。
你可以尝试在主模块中添加以下代码来设置 'spawn' 启动方法:
```python
import multiprocessing as mp
if __name__ == '__main__':
mp.set_start_method('spawn')
# 在这里编写你的主程序逻辑
```
将你的主程序逻辑放在 `if __name__ == '__main__':` 块中,并在该块中调用 `mp.set_start_method('spawn')` 来设置 'spawn' 启动方法。
在上述代码中,`mp.set_start_method('spawn')` 将设置 'spawn' 启动方法为当前进程的默认启动方法。这样,在创建子进程时就会使用 'spawn' 启动方法,避免 CUDA 初始化错误。
希望这个解决方案对你有所帮助。如果你还有其他问题,请随时提问。
ERROR: Exception: Traceback (most recent call last): File "E:\Python\phthon397\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main status = self.run(options, args) File "E:\Python\phthon397\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper return func(self, options, args) File "E:\Python\phthon397\lib\site-packages\pip\_internal\commands\install.py", line 315, in run requirement_set = resolver.resolve( File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 75, in resolve collected = self.factory.collect_root_requirements(root_reqs) File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 471, in collect_root_requirements req = self._make_requirement_from_install_req( File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 433, in _make_requirement_from_install_req cand = self._make_candidate_from_link( File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 204, in _make_candidate_from_link self._link_candidate_cache[link] = LinkCandidate( File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 295, in __init__ super().__init__( File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 156, in __init__ self.dist = self._prepare() File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 227, in _prepare dist = self._prepare_distribution() File "E:\Python\phthon397\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 305, in _prepare_distribution return self._factory.preparer.prepare_linked_requirement( File "E:\Python\phthon397\lib\site-packages\pip\_internal\operations\prepare.py", line 508, in prepare_linked_requirement return self._prepare_linked_requirement(req, parallel_builds) File "E:\Python\phthon397\lib\site-packages\pip\_internal\operations\prepare.py", line 570, in _prepare_linked_requirement dist = _get_prepared_distribution( File "E:\Python\phthon397\lib\site-packages\pip\_internal\operations\prepare.py", line 61, in _get_prepared_distribution return abstract_dist.get_pkg_resources_distribution() File "E:\Python\phthon397\lib\site-packages\pip\_internal\distributions\wheel.py", line 26, in get_pkg_resources_distribution with ZipFile(self.req.local_file_path, allowZip64=True) as z: File "E:\Python\phthon397\lib\zipfile.py", line 1257, in __init__ self._RealGetContents() File "E:\Python\phthon397\lib\zipfile.py", line 1324, in _RealGetContents raise BadZipFile("File is not a zip file") zipfile.BadZipFile: File is not a zip file WARNING: You are using pip version 21.2.3; however, version 23.1.2 is available. You should consider upgrading via the 'E:\Python\phthon397\python.exe -m pip install --upgrade pip' command.
看起来你在使用pip安装一个包时出现了错误,可能是由于下载的文件不是一个有效的zip文件导致的。建议先尝试更新pip到最新版本,使用命令“E:\Python\phthon397\python.exe -m pip install --upgrade pip”,然后再尝试安装包。如果问题仍然存在,可以尝试使用其他途径安装该包,或者联系该包的开发者获取更多帮助。
阅读全文