-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cheng Lai
authored
Jul 15, 2022
1 parent
91eabc3
commit 23543f2
Showing
6 changed files
with
145 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
onnx<=1.11.0 | ||
tensorlayerx>=0.5.1 | ||
tensorlayerx>=0.5.6 |
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,39 @@ | ||
#! /usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
os.environ["TL_BACKEND"] = 'tensorflow' | ||
import tensorlayerx as tlx | ||
from tensorlayerx.nn import Module | ||
from tensorlayerx.nn import LayerNorm | ||
from tlx2onnx.main import export | ||
import onnxruntime as rt | ||
import numpy as np | ||
|
||
|
||
class NET(Module): | ||
def __init__(self): | ||
super(NET, self).__init__() | ||
self.layernorm = LayerNorm([50, 50, 32]) | ||
|
||
def forward(self, x): | ||
x = self.layernorm(x) | ||
return x | ||
|
||
net = NET() | ||
print(type(net)) | ||
net.set_eval() | ||
input = tlx.nn.Input(shape=(10, 50, 50, 32)) | ||
onnx_model = export(net, input_spec=input, path='layernorm.onnx', enable_onnx_checker=False) | ||
print("tlx out", input) | ||
|
||
# Infer Model | ||
sess = rt.InferenceSession('layernorm.onnx') | ||
|
||
input_name = sess.get_inputs()[0].name | ||
output_name = sess.get_outputs()[0].name | ||
|
||
input_data = np.array(input, dtype=np.float32) | ||
|
||
result = sess.run([output_name], {input_name: input_data}) | ||
print("onnx out", result) |
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