megengine.load

load(f, map_location=None, pickle_module=pickle)[源代码]

Load an object saved with :func:~.megengine.save` from a file.

参数
  • f – 文件名字符串或一个需要加载的文件对象。

  • map_location – 默认值:None

  • pickle_module – 默认值: pickle

注解

  • map_location defines device mapping. See examples for usage.

  • If you will call set_default_device, please do it before 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')