PyTorch serialization uses a different format than Lua torch. You can load .t7 files with load_lua, but the ones saved with torch.save in Python are only readable in Python.
Oh, do you have any suggestions then on how I can best load/save this custom model in python? Should I just do my best to just write my model as a nn module (eg. using Sequential) and load/save with torch.save() and load_lua respectively?
I have a model called vae.py and I am trying to save it, but I don’t understand what is the required argument " "f = model.pth" mean? Also, how can I use state_dicts? Thanks a lot.
I’m sorry, but I don’t understand the first part of you question. You can obtain a state_dict using a state_dict() method of any module. Once you resume the training from a checkpoint, you should still create a new model with random weights, and call load_state_dict(serialized_dict) on it. This will replace the random values with serialized weights.
Do you mean if pickle can save the model in python and load it in lua?
I think not because pickle is python specific package. I don’t know lua though, so maybe there exists some
workaround or a specific lua package that can read pickle serializations.
Yes , pickle does not load in lua .
I was trying saving weights in hdf5 file and then loading in lua , but it was not working out because I am making error somewhere .
But this is the error which I get .
Any workaround ?
File “scripts/run_model.py”, line 387, in
main(args)
File “scripts/run_model.py”, line 115, in main
fout.create_dataset(‘pgparams’,data=pgparams)
File “/usr/local/lib/python2.7/dist-packages/h5py/_hl/group.py”, line 105, in create_dataset
dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
File “/usr/local/lib/python2.7/dist-packages/h5py/_hl/dataset.py”, line 93, in make_new_dset
tid = h5t.py_create(dtype, logical=1)
File “h5py/h5t.pyx”, line 1450, in h5py.h5t.py_create (/tmp/pip-4rPeHA-build/h5py/h5t.c:16078)
File “h5py/h5t.pyx”, line 1470, in h5py.h5t.py_create (/tmp/pip-4rPeHA-build/h5py/h5t.c:15912)
File “h5py/h5t.pyx”, line 1525, in h5py.h5t.py_create (/tmp/pip-4rPeHA-build/h5py/h5t.c:15813)
TypeError: Object dtype dtype(‘O’) has no native HDF5 equivalent