将 pytorch .ckpt 文件转换为 .bin 文件

问题描述 投票:0回答:0

我有一个 pytorch

.ckpt
文件,我需要将其转换为
.bin
文件。

我尝试在 Python 3.10.11 中执行该代码:

import torch

# Load the checkpoint file
checkpoint = torch.load("checkpoint.ckpt")

# Extract the model parameters
params = checkpoint["model_state_dict"]

# Save the parameters to a .bin file
torch.save(params, "model.bin")

我得到了这个错误:

File "D:\Model\trial_ckpt converter.py", line 4, in <module>
    checkpoint = torch.load("checkpoint.ckpt")
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py", line 797, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py", line 283, in __init__
    super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

有人知道这方面的解决方案吗?

deep-learning pytorch file-type bin ckpt
© www.soinside.com 2019 - 2024. All rights reserved.