Hi,
I rencently tried to load a trained Pytorch model which could do “Image Style transfer” to a C++ model.
The style transfer needs the gradient of loss w.r.t the input tensor, but it seems that the jit::script::Module can’t pass the gradients to the input tensor.
So I’d like to know is there any way to convert a jit::script::Module to nn::Moudle conveniently?
Hi @eellison , could you please help me understand why jit::script::Module is needed at all in libtorch? In other words, why isn’t it a simple thing for libtorch to read a model file saved in Python and build a nn::Module directly from it? I’ve struggled with this issue for years now, and never found a good answer.
For example, I have a libtorch-based application for which I have written code to load HDF5 models from Keras. Since the HDF5 contains both the network graph (as a json string) and the weights, I can programmatically construct the nn::Module from it and populate its trainable parameters. All without going through any format conversion! And, ironically, I cannot do the same with a model saved from Pytorch in python!! Any insights would be appreciated. Thanks.