- save(obj, f, pickle_module=pickle, pickle_protocol=pickle.DEFAULT_PROTOCOL)¶
obj – object to be saved.
f – 文件名字符串或一个需要保存的文件对象。
pickle_module – the module to use for pickling.
pickle_protocol – the protocol to use for pickling.
If you are using MegEngine with different Python versions
Different Python version may use different DEFAULT/HIGHEST pickle protocol. If you want to
loadthe saved object in another Python version, please make sure you have used the same protocol.
You can select to use
If you want to save object in a higher protocol version which current version Python not support, you can install other pickle module instead of the build-in one. Take
pickle5as an example:
>>> import pickle5 as pickle
It’s a backport of the pickle 5 protocol (PEP 574) and other pickle changes. So you can use it to save object in pickle 5 protocol and load it in Python 3.8+.
Or you can use
pickle5in this way (only used with this interface)：
import pickle5 import megengine megengine.save(obj, f, pickle_module=pickle5, pickle_protocol=5)