Pickle serialises the instances. It is supposed to provide minimal information to recover the object. Pytorch works using several modules and inheritances and I simply think the state serialised fails. Cannot tell you why without deeply stuying it.
That is why I still suggest to provide code + weights as the weights depends in an Ordered Dict and has much less dependencies that the nn.Modules.
Thanks. It’s just that the API I’m building needs Pytorch to save and load the whole thing at once.
I’m building an explanation API that takes in a model, and an image and produces a Class activation map( CAM).
I want the API to work for any model that is supplied, this works for tf models, since you can save and load them quite simply, but not for Pytorch models, because I need to instantiate the model definition “before” I fire my API up, which is very inconvenient.
Although you could do that, you still need to provide the code so that pickle can reconstruct the object. In the end (in your case) it’s a matter of just instantiating that object generically with *args and **kwargs.