You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
hanjr92 9cfeccd879 add conv1d conv3d test and fix weights convert 1 hour ago
tests add conv1d conv3d test and fix weights convert 1 hour ago
tlx2onnx add conv1d conv3d test and fix weights convert 1 hour ago
.gitignore Add test and export vgg16 model 22 hours ago
LICENSE Build PyPI release 3 weeks ago
OP_LIST.md Add shape layer and README 1 week ago
README.md Added embedding 2 days ago
README_en.md Added embedding 2 days ago
requirements.txt Add shape layer and README 1 week ago
setup.py Add shape layer and README 1 week ago

README.md

TLX2ONNX

简体中文 | English

TensorLayerX模型导出为ONNX。

简介

TLX2ONNX可以将TensorLayerX模型转换为ONNX导出。

  • 支持的操作. TLX2ONNX可以稳定地将模型导出到ONNX Opset 9~11,并部分支持较低版本的Opset。详情请参考 Operator list.
  • 支持的TensorLayerX Layers. 您可以在TLX2ONNX/tests中找到正式验证的层 TLX2ONNX/test.

安装

通过pip安装

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 other