Skip to content

Instantly share code, notes, and snippets.

@thebyrd
Created May 4, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebyrd/542dfbc02fcd1f1bf09701a16dfa663e to your computer and use it in GitHub Desktop.
Save thebyrd/542dfbc02fcd1f1bf09701a16dfa663e to your computer and use it in GitHub Desktop.
Negate ONNX Model and PyTorch script for generating it.
pytorch1.5:b

01Neg_0"Negtorch-jit-exportZ
0




�b
1




�B
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