`to_onehot` can't be torchscripted
See original GitHub issue🐛 Bug description
I need to do one hot conversion and I use ignite.utils.to_onehot
, but when I try to torchscript the model, it occurs a RuntimeError
. Stacktrace:
RuntimeError:
cannot statically infer the expected size of a list in this context:
File "/usr/local/lib/python3.6/dist-packages/ignite/utils.py", line 59
input's device`.
"""
onehot = torch.zeros(indices.shape[0], num_classes, *indices.shape[1:], dtype=torch.uint8, device=indices.device)
~~~~~~~~~~~~~~~~~ <--- HERE
return onehot.scatter_(1, indices.unsqueeze(1), 1)
'to_onehot' is being compiled since it was called from 'SLP.forward'
File "<ipython-input-3-0f76d1651906>", line 12
def forward(self, x):
x = to_onehot(x, 10)
~~~~~~~~~~~~~~~~~~~ <--- HERE
return self.l1(x)
Environment
Colab
Reproducible Link
https://colab.research.google.com/drive/13mWdz9sGXvAHgKd3vtp5I6Y-gZDRlNAd?usp=sharing
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Unable to call super method with TorchScript #42885 - GitHub
When I try to compile the code to TorchScript, I get: Tried to access nonexistent attribute or method 'forward' of type 'Tensor'.
Read more >Unable to convert the pytorch model to the TorchScript format
torch.jit.script create a ScriptFunction(a Function with Graph) by parsing the python source code from module.forward().
Read more >How to Create PyTorch One Hot Encoding? - eduCBA
A one-hot encoding permits the portrayal of downright information to be more expressive. Many AI calculations can't work with downright information ...
Read more >TorchScript — PyTorch 1.13 documentation
TorchScript is a way to create serializable and optimizable models from PyTorch code. Any TorchScript program can be saved from a Python process...
Read more >Internals: TMVA PyTorch Interface | GSoC - Anirudh Dagar
Can't See? ... then, convert class number to one-hot vectors. ... Load PyTorch (torchscript) model from checkpoint .tar file or .pt/.pth ...
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 Free
Top 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
Here is how it can be implemented.
@ydcjeff if you’d like to fix it, please send a PR (and if with a test it would be awesome) 😃
I would love to, I will go through your conversion in a little more detail (have gone through once). I think I will be able to work on it