栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

PyTorch数据保存和读取的学习笔记

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PyTorch数据保存和读取的学习笔记

2 数据读取:torch.load() Map_location:位置映射

Map_location用于指定读取数据的映射设备,可以是 a function, torch.device, string or a dict.
map_location可以使用函数来表示,我们来看看 torch doc 中给出的例子:

>>> torch.load('tensors.pt')
# Load all tensors onto the CPU
>>> torch.load('tensors.pt', map_location=torch.device('cpu'))
# Load all tensors onto the CPU, using a function
>>> torch.load('tensors.pt', map_location=lambda storage, loc: storage)
# Load all tensors onto GPU 1
>>> torch.load('tensors.pt', map_location=lambda storage, loc: storage.cuda(1))

当使用函数来指定映射方式时,其格式为:
map_location = lambda storage, loc: dst_storage
其中 storage:  为初始存储对象(initial deserialization of the storage, residing on the CPU),loc: str为序列化时对象的存储位置(“存档时所在的设备”)。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/976857.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号