amazon-s3 - 从 S3 存储桶加载 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 加载模型。不幸的是,我在网上找不到一个好的解决方案。有人可以帮我吗?
解决方案
AFAIKtorch.load
期望文件名作为参数 - 而不是文件的内容。你buffer
的结果是否可能已经等同于torch.load
ing 文件的本地副本?
如果您尝试这样做会发生什么model.load_state_dict(buffer)
?
推荐阅读
- java - 从 Spring Boot 应用程序中排除 @Configuration
- java - 在不知道这种格式的情况下将十进制格式的字符串转换为 Double 的快速方法
- java - 编辑csv文件中的内容
- sql-server - 如何在 SQL Server 的 SELECT 查询中使用变量
- node.js - 如何获取下载 URL 列表并从 Firebase 存储中下载所有文件的 .ZIP 文件夹
- sql - 热点修复:执行 sql 语句时出现未连接错误,DPI-1010:未连接?
- ajax - 在 asp.net mvc 部分视图中看不到 Highsoft Highcharts
- r - ggplot:自定义点边距的颜色
- java - java - 如何在java中生成列表/数组的随机混乱?
- ruby-on-rails - Drop 适用于 # 的 href,但不适用于 'home/index'