forked from tracel-ai/burn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Onnx tests and bug fixes - BatchNorm, Identity, Relu, Sigmoid and Tra…
…nspose (tracel-ai#661)
- Loading branch information
Showing
25 changed files
with
869 additions
and
74 deletions.
There are no files selected for viewing
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
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: onnx-tests/tests/add/add.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
|
||
# TODO enable this after https://github.com/burn-rs/burn/issues/665 is fixed | ||
# Declare a constant int tensor with ones | ||
# self.a = torch.ones(1, 1, 1, 4, dtype=torch.int32) | ||
|
||
# Declare a scalar | ||
self.b = 5 | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x, k): | ||
|
||
# Add tensor inputs | ||
x = x + x | ||
|
||
# Add a scalar constant and a scalar input | ||
d = self.b + k | ||
|
||
# Add a tensor and a scalar | ||
x = x + d | ||
|
||
return x | ||
|
||
|
||
def main(): | ||
|
||
# set seed for reproducibility | ||
torch.manual_seed(0) | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
onnx_name = "add_int.onnx" | ||
# Output some test data for use in the test | ||
test_input = torch.tensor([[[[1, 2, 3, 4]]]], dtype=torch.int32) | ||
|
||
scalar = 2 | ||
|
||
torch.onnx.export(model, (test_input, scalar), onnx_name, | ||
verbose=False, opset_version=16) | ||
|
||
print("Finished exporting model to {}".format(onnx_name)) | ||
|
||
print("Test input data: {}, {}".format(test_input, scalar)) | ||
output = model.forward(test_input, scalar) | ||
print("Test output data: {}".format(output)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: batch_norm.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
super(Model, self).__init__() | ||
self.batch_norm1d = nn.BatchNorm1d(20) | ||
self.batch_norm2d = nn.BatchNorm2d(5) | ||
|
||
def forward(self, x): | ||
x = self.batch_norm1d(x) | ||
x = x.reshape(1, 5, 2, 2) | ||
x = self.batch_norm2d(x) | ||
return x | ||
|
||
|
||
def main(): | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
|
||
# reproducibility | ||
torch.manual_seed(0) | ||
|
||
file_name = "batch_norm.onnx" | ||
test_input = torch.ones(1, 20, 1, device=device) | ||
torch.onnx.export(model, test_input, file_name, | ||
# do_constant_folding=False, | ||
verbose=False, opset_version=16) | ||
|
||
print("Finished exporting model to {}".format(file_name)) | ||
|
||
# Output some test data for use in the test | ||
print("Test input data shape of ones: {}".format(test_input.shape)) | ||
output = model.forward(test_input) | ||
print("Test output data shape: {}".format(output.shape)) | ||
|
||
sum = output.sum().item() | ||
|
||
print("Test output sum: {}".format(sum)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: equal.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
# Declare a constant float tensor with ones | ||
self.a = torch.ones(1, 1, 1, 4) | ||
|
||
# Declare a scalar | ||
self.b = 5.0 | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x, k): | ||
|
||
x = x == self.a | ||
|
||
k = k == self.b | ||
|
||
return x, k | ||
|
||
|
||
def main(): | ||
|
||
# Set seed for reproducibility | ||
torch.manual_seed(42) | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
onnx_name = "equal.onnx" | ||
input = torch.ones(1, 1, 1, 4, device=device) | ||
|
||
scalar = 2.0 | ||
|
||
torch.onnx.export(model, (input, scalar), onnx_name, | ||
verbose=False, opset_version=16) | ||
|
||
print("Finished exporting model to {}".format(onnx_name)) | ||
|
||
print("Test input data: {}, {}".format(input, scalar)) | ||
output = model.forward(input, scalar) | ||
print("Test output data: {}".format(output)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pytorch2.0.1:X | ||
input1/relu1/Relu"Relu torch_jitZ | ||
input | ||
b | ||
1 | ||
B |
Oops, something went wrong.