spa*_*del 3 amazon-s3 torch pytorch
model.pt我想从 S3 存储桶加载 pytorch 模型 ( )。我写了以下代码:
from smart_open import open as smart_open
import io
load_path = "s3://serial-no-images/yolo-models/model4/model.pt"
with smart_open(load_path) as f:
    buffer = io.BytesIO(f.read())
    model.load_state_dict(torch.load(buffer))
这会导致以下错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte
一种解决方案是在本地下载模型,但我想避免这种情况并直接从 S3 加载模型。不幸的是,我在网上找不到一个好的解决方案。有人可以帮我吗?
根据文档,以下工作:
from smart_open import open as smart_open
import io
load_path = "s3://serial-no-images/yolo-models/model4/model.pt"
with smart_open(load_path, 'rb') as f:
    buffer = io.BytesIO(f.read())
    model.load_state_dict(torch.load(buffer))
我以前尝试过这个,但没有看到我必须将“rb”设置为参数。
| 归档时间: | 
 | 
| 查看次数: | 5843 次 | 
| 最近记录: |