Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
Eric_lai c27535f0e0 | 1 year ago | |
---|---|---|
tests | 1 year ago | |
tlx2onnx | 1 year ago | |
.gitignore | 1 year ago | |
LICENSE | 1 year ago | |
OP_LIST.md | 1 year ago | |
README.md | 1 year ago | |
README_en.md | 1 year ago | |
requirements.txt | 1 year ago | |
setup.py | 1 year ago |
简体中文 | English
TensorLayerX模型导出为ONNX。
TLX2ONNX可以将TensorLayerX模型转换为ONNX导出。
pip install tlx2onnx
git clone https://github.com/tensorlayer/TLX2ONNX.git
cd TLX2ONNX
python setup.py install
TLX2ONNX可以转换使用TensorLayerX模块子类和层构建的模型,层支持列表可以在Operator list找到.
#! /usr/bin/python
# -*- coding: utf-8 -*-
import tensorlayerx as tlx
from tensorlayerx.nn import Module
from tensorlayerx.nn import Linear, Dropout, Flatten, ReLU6
from tlx2onnx import export
import onnxruntime as rt
import numpy as np
class MLP(Module):
def __init__(self):
super(MLP, self).__init__()
# weights init
self.flatten = Flatten()
self.line1 = Linear(in_features=32, out_features=64, act=tlx.nn.LeakyReLU(0.3))
self.d1 = Dropout()
self.line2 = Linear(in_features=64, out_features=128, b_init=None, act=tlx.nn.ReLU)
self.relu6 = ReLU6()
self.line3 = Linear(in_features=128, out_features=10, act=tlx.nn.ReLU)
def forward(self, x):
x = self.flatten(x)
z = self.line1(x)
z = self.d1(z)
z = self.line2(z)
z = self.relu6(z)
z = self.line3(z)
return z
net = MLP()
net.eval()
input = tlx.nn.Input(shape=(3, 2, 2, 8))
onnx_model = export(net, input_spec=input, path='linear_model.onnx')
# Infer Model
sess = rt.InferenceSession('linear_model.onnx')
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
input_data = tlx.nn.Input(shape=(3, 2, 2, 8))
input_data = np.array(input_data, dtype=np.float32)
result = sess.run([output_name], {input_name: input_data})
print(result)
如果你发现TLX2ONNX对你的项目有用,请引用以下论文:
@article{tensorlayer2017,
author = {Dong, Hao and Supratak, Akara and Mai, Luo and Liu, Fangde and Oehmichen, Axel and Yu, Simiao and Guo, Yike},
journal = {ACM Multimedia},
title = {{TensorLayer: A Versatile Library for Efficient Deep Learning Development}},
url = {http://tensorlayer.org},
year = {2017}
}
@inproceedings{tensorlayer2021,
title={TensorLayer 3.0: A Deep Learning Library Compatible With Multiple Backends},
author={Lai, Cheng and Han, Jiarong and Dong, Hao},
booktitle={2021 IEEE International Conference on Multimedia \& Expo Workshops (ICMEW)},
pages={1--3},
year={2021},
organization={IEEE}
}
TensorLayerX模型导出为ONNX模型
Python Markdown
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》