megengine.load¶
- load(f, map_location=None, pickle_module=pickle)[源代码]¶
从文件中加载一个用 :func:~.megengine.save 保存的对象
- 参数
f – 文件名字符串或一个需要加载的文件对象。
map_location – 默认值:None
pickle_module – 默认值:
pickle
注解
map_location
定义设备间的映射。参见用法示例。如果你要调用
set_default_device
, 请在load
. 之前调用它
实际案例
import megengine as mge # Load tensors to the same device as defined in model.pkl mge.load('model.pkl') # Load all tensors to gpu0. mge.load('model.pkl', map_location='gpu0') # Load all tensors originally on gpu0 to cpu0 mge.load('model.pkl', map_location={'gpu0':'cpu0'}) # Load all tensors to cpu0 mge.load('model.pkl', map_location=lambda dev: 'cpu0')