Load model from pyTorch issue
See original GitHub issueI try load trained nn in pyTorch(in pth file format) to TorchSharp but give some errors.
-
from static method
Module module = Module.Load("C:\\ir50-model.pth"); module.forward(tensor_image);
throw System.NotImplementedException: ‘forward(t)’ -
useStrict: false
var myModel = new MyModel("test");
myModel.load("C:\\ir50-model.pth", false); ;
myModel.forward(tensor_image);
public class MyModel : Module
{
public MyModel() : base("test") {}
public MyModel(string name) : base(name) {}
public override Tensor forward(Tensor input)
{
return this.forward(input);
}
}
throw System.FormatException: ‘Too many bytes in what should have been a 7-bit encoded integer.’
Does it exist worked way to load pth model from pyTorch to TorchSharp ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Saving and Loading Models
To load the models, first initialize the models and optimizers, then load the dictionary locally using torch.load() . From here, you can easily...
Read more >Pytorch issue: torch.load() does not correctly load a saved ...
To solve this, try defining a new model and loading the parameters to it via load like so: my_model = MyModelClass(parameters).to(device) ...
Read more >pytorch 1.4 can not load model saved by 1.7 · Issue #48915
Bug model trained by pytorch 1.7.0 cuda 11.0.221, but cannot load by pytorch1.4.0, cuda 10.0.130 To Reproduce Steps to reproduce the ...
Read more >Save and Load Your PyTorch Models
In this post, you will discover how to save your PyTorch models to files and load them up again to make predictions.
Read more >How to Save and Load Models in PyTorch
This article is a tutorial that covers how to correctly save and load your trained machine learning models in PyTorch using Weights &...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I’ve been out on vacation for a month. First day back…
What does the Python model that you are exporting look like? It has to have the same components as the model you’re loading the weights into.
From the code you included, it looks like:
UPDATE: I tried to reproduce the error on my own, but it didn’t fail. It would be helpful to have the source code for the Python model that you exported. I don’t need the training code, just the definition of the model class.
@anytoany
Please see a work around using the recommended save_dict codes