Created
May 4, 2020 22:49
-
-
Save thebyrd/542dfbc02fcd1f1bf09701a16dfa663e to your computer and use it in GitHub Desktop.
Negate ONNX Model and PyTorch script for generating it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pytorch1.5:b | |
01Neg_0"Negtorch-jit-exportZ | |
0 | |
�b | |
1 | |
�B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
class TwoLayerNet(torch.nn.Module): | |
def __init__(self): | |
""" | |
constructor just calls super. | |
""" | |
super(TwoLayerNet, self).__init__() | |
def forward(self, x): | |
""" | |
In the forward function we accept a Tensor of input data and we must return | |
a Tensor of output data. We can use Modules defined in the constructor as | |
well as arbitrary operators on Tensors. | |
""" | |
return x.neg() | |
model = TwoLayerNet() | |
inp = torch.tensor([[[[-0.5]*320]]], dtype=torch.float32) | |
torch.onnx.export(model, inp, 'neg.onnx') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment