Skip to content

Commit

Permalink
Merge pull request #842 from l-bat:lb/onnx_normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Feb 3, 2021
2 parents 61ea2e2 + 00d6a27 commit 960de6c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Binary file added testdata/dnn/onnx/data/input_normalize_fusion.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/output_normalize_fusion.npy
Binary file not shown.
13 changes: 13 additions & 0 deletions testdata/dnn/onnx/generate_onnx_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,3 +1245,16 @@ def forward(self, x):
x = Variable(torch.randn([1, 1, 3, 4]))
model = PadCalculation()
save_data_and_model("calc_pads", x, model, version=11)

class NormalizeFusion(nn.Module):
def forward(self, x):
mul = x * x
sum = torch.sum(mul, dim=(1), keepdim=True)
maximum = torch.clamp(sum, min=1e-8)
sqrt = torch.sqrt(maximum)
reciprocal = torch.reciprocal(sqrt)
return x * reciprocal

x = Variable(torch.randn([2, 3]))
model = NormalizeFusion()
save_data_and_model("normalize_fusion", x, model)
Binary file added testdata/dnn/onnx/models/normalize_fusion.onnx
Binary file not shown.

0 comments on commit 960de6c

Please sign in to comment.