Platform-agnostic AI Framework 🔥

Overview

GitHub last commit (branch) Documentation Status Build Status Downloads Downloads Docker Pulls

🇬🇧 TensorLayerX is a multi-backend AI framework, which can run on almost all operation systems and AI hardwares, and support hybrid-framework programming. layer list

🇨🇳 TensorLayerX 是一个跨平台开发框架,可以运行在各类操作系统和AI硬件上,并支持混合框架的开发。支持列表

🇷🇺 TensorLayerX

🇸🇦 TensorLayerX

TensorLayerX

Compare with TensorLayer, TensorLayerX (TLX) is a brand new seperated project for platform-agnostic purpose.

Examples

Quick Start

  • Installation
# install from pypi
pip3 install tensorlayerx 
# install from Github
pip3 install git+https://github.com/tensorlayer/tensorlayerx.git 
# install from OpenI
pip3 install
  • Tutorial

  • Discussion: Slack , [QQ-Group] , [WeChat-Group]

Contact

Citation

If you find TensorLayerX useful for your project, please cite the following papers:

@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}
}
Comments
  • load pretrained model from .pth

    load pretrained model from .pth

    I write a model using Pytorch, and save its state_dict() to .pth. Now I want to use tensorlayerx to write it, so other people (using tensorflow etc.) can use this model. My model definition is same in Pytorch and Tensorlayerx, but I can't load pretrained model of .pth in tensorlayerx. Below is my code. (simple model is used here for clarity, the actual model is more complex than this)

    """
    a_torch.py
    """
    import torch
    from torch import nn
    
    class A(nn.Module):
        def __init__(self):
            super(A, self).__init__()
            self.conv = nn.Conv2d(3, 16, kernel_size=1)
            self.bn = nn.BatchNorm2d(16)
            self.relu = nn.ReLU(inplace=True)
        
        def forward(self, x):
            return self.act(self.bn(self.conv(x)))
    
    if __name__ == '__main__':
        a = A()
        torch.save(a.state_dict(), 'a.pth')
    
    """
    a_tlx.py
    """
    import tensorlayerx as tlx
    import torch
    from tensorlayerx import nn
    
    class A(nn.Module):
        def __init__(self):
            super(A, self).__init__()
            self.conv = nn.Conv2d(16, kernel_size=1, data_format='channels_first')
            self.bn = nn.BatchNorm2d(num_features=16, data_format='channels_first')
            self.relu = nn.activation.ReLU()
        
        def forward(self, x):
            return self.act(self.bn(self.conv(x)))
    
    def pth2npz(pth_path):
        temp = torch.load(pth_path)   # type(temp) = OrderedDict
        tlx.files.save_npz_dict(temp.items(), pth_path.split('.')[0] + '.npz')
    
    if __name__ == '__main__':
        a = A()
        pth2npz('a.pth')
        tlx.files.load_and_assign_npz_dict('a.npz', a)
    

    First run a_torch.py, then run a_tlx.py. The error is below.

    Using PyTorch backend.
    Traceback (most recent call last):
      File "test/test_03.py", line 25, in <module>
        tlx.files.load_and_assign_npz_dict('test/a.npz', a)
      File "/home/mchen/anaconda3/envs/kpconv/lib/python3.8/site-packages/tensorlayerx/files/utils.py", line 2208, in load_and_assign_npz_dict
        raise RuntimeError(
    RuntimeError: Weights named 'conv.weight' not found in network. Hint: set argument skip=Ture if you want to skip redundant or mismatch weights
    

    Then I debug and look at the tlx.files.load_and_assign_npz_dict() source code. I find tensorlayerx parameter name is different from PyTorch. This results in key mismatch when loading pre-trained model. In the following two figures, the first is the parameter name of PyTorch and the second is the parameter name of TensorLayerx. 屏幕截图 2022-08-07 202607 屏幕截图 2022-08-07 202555 Now the solution I can think of is to write a key map table, but it is hard for large model. So can you give me a simple solution ? (same model definition in pytorch and tensorlayerx, load pretrained model in .pth) :grin:

    opened by HaoRan-hash 2
  • tlx.nn.Swish()与paddle.nn.Swish()的结果有细微差别

    tlx.nn.Swish()与paddle.nn.Swish()的结果有细微差别

    tlx:

    [-0.16246916, 1.40204561, 0.85213524, ..., 0.85800600, 1.10605156, 1.11549926], [-0.04873780, 0.28885114, 0.15792340, ..., 0.12375022, 0.22599602, 0.53073120], [-0.09840852, 0.40172467, 0.15602632, ..., 0.09853011, 0.29177830, 0.52241892]

    paddle:

    [-0.16246916, 1.40204573, 0.85213524, ..., 0.85800600, 1.10605145, 1.11549926], [-0.04873780, 0.28885114, 0.15792342, ..., 0.12375022, 0.22599602, 0.53073120], [-0.09840852, 0.40172467, 0.15602632, ..., 0.09853011, 0.29177833, 0.52241892]

    opened by moshizhiyin 1
  • add some functions

    add some functions

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by hanjr92 0
  • Fix docs

    Fix docs

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by Laicheng0830 0
  • add some functions

    add some functions

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by hanjr92 0
  • add paddle backend ops

    add paddle backend ops

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by hanjr92 0
  • fix swish and prelu

    fix swish and prelu

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by hanjr92 0
  • Fix requirements oneflow backend

    Fix requirements oneflow backend

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by Laicheng0830 0
  • Oneflow dev

    Oneflow dev

    Description

    oneflow backend:

    backends/ops/oneflow_nn.py
    backends/ops/oneflow_backend.py
    nn/core/core_oneflow.py
    

    tutorials: 6 MarkDown files in /home/user/pyprojects/TensorLayerX/docs/tutorials

    other: Training progressbar using rich bugs fixed

    opened by QuantumLiu 0
  • Add Training Progress Bar

    Add Training Progress Bar

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by Laicheng0830 0
  • Add loss monitoring to training

    Add loss monitoring to training

    Checklist

    • [ ] I've tested that my changes are compatible with the latest version of Tensorflow.
    • [ ] I've read the Contribution Guidelines
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by Laicheng0830 0
  • net.set_eval() seems not work well

    net.set_eval() seems not work well

    Issue Description

    When I test my pspnet model, I find if not use "with torch.no_grad()" or "gradient()", the gpu memory will be full after testing several photos. I guess set_eval() function seems to have failed. Or I used the wrong method to test? This is my code, thank you!

    In addition, I found that the batch size will affect the final test results. If net. eval() is not performed in the pytorch, it will cause similar problems. It seems that this is caused by the BatchNorm layer.

        os.environ['TL_BACKEND'] = 'torch'
        tlx.set_device(device='GPU', id=3)
        # ...
        net = models[backend]()
        net.load_weights('test.npz', format='npz_dict', skip=True)
        test_dataset = MyDataset(root_dir="test/")
        test_loader = DataLoader(test_dataset, batch_size=4, shuffle=True)
    
        train_weights = net.trainable_weights
        scheduler = tlx.optimizers.lr.StepDecay(learning_rate=0, step_size=30, gamma=0.5, last_epoch=-1)
        optimizer = tlx.optimizers.Adam(lr=scheduler)
    
        hist = np.zeros((num_classes, num_classes))
        net.set_eval()
        # with torch.no_grad():
        for x, y, y_cls in test_loader:
            _out, _out_cls = net(x)
            seg_loss = tlx.losses.softmax_cross_entropy_with_logits(_out, y)
            cls_loss = tlx.losses.sigmoid_cross_entropy(_out_cls, y_cls)
            _loss = seg_loss + 1 * cls_loss
            # grads = optimizer.gradient(_loss, train_weights)
            # optimizer.apply_gradients(zip(grads, train_weights))
            '''
                compute miou matrix
            '''
            out = tlx.convert_to_numpy(_out)
            y = tlx.convert_to_numpy(y)
            out = np.argmax(out, axis=1)
            for i in range(0, out.shape[0]):
                pred = out[i]
                gt = y[i]
                hist += fast_hist(gt.flatten(), pred.flatten(), num_classes)
                
        # compute miou then print
        mIoUs = per_class_iu(hist)
        for ind_class in range(num_classes):
            print('===>' + name_classes[ind_class] + ':\t' + str(round(mIoUs[ind_class] * 100, 2)))
        print('===> mIoU: ' + str(round(np.nanmean(mIoUs) * 100, 2)))
        print("test loss: {}".format(train_loss))
    
    
    opened by qzhiyue 0
  • tensorlayerx.ops.Pad不支持“channels_first”的data_format,后续会补充“channels_first”的格式吗?

    tensorlayerx.ops.Pad不支持“channels_first”的data_format,后续会补充“channels_first”的格式吗?

    New Issue Checklist

    Issue Description

    [INSERT DESCRIPTION OF THE PROBLEM]

    Reproducible Code

    • Which OS are you using ?
    • Please provide a reproducible code of your issue. Without any reproducible code, you will probably not receive any help.

    [INSERT CODE HERE]

    # ======================================================== #
    ###### tensorlayerx.ops.Pad源码######
    # ======================================================== #
    
    class Pad(object):
    
        def __init__(self, paddings, mode="REFLECT", constant_values=0):
            if mode not in ['CONSTANT', 'REFLECT', 'SYMMETRIC']:
                raise Exception("Unsupported mode: {}".format(mode))
            if mode == 'SYMMETRIC':
                raise NotImplementedError
            self.paddings = paddings
            self.mode = mode.lower()
            self.constant_values = constant_values
    
        def __call__(self, x):
            if len(x.shape) == 3:
                data_format = 'NLC'
                self.paddings = self.correct_paddings(len(x.shape), self.paddings, data_format)
            elif len(x.shape) == 4:
                data_format = 'NHWC'
                self.paddings = self.correct_paddings(len(x.shape), self.paddings, data_format)
            elif len(x.shape) == 5:
                data_format = 'NDHWC'
                self.paddings = self.correct_paddings(len(x.shape), self.paddings, data_format)
            else:
                raise NotImplementedError('Please check the input shape.')
            return pd.nn.functional.pad(x, self.paddings, self.mode, value=self.constant_values, data_format=data_format)
    
        def correct_paddings(self, in_shape, paddings, data_format):
            if in_shape == 3 and data_format == 'NLC':
                correct_output = [paddings[1][0], paddings[1][1]]
            elif in_shape == 4 and data_format == 'NHWC':
                correct_output = [paddings[2][0], paddings[2][1], paddings[1][0], paddings[1][1]]
            elif in_shape == 5 and data_format == 'NDHWC':
                correct_output = [
                    paddings[3][0], paddings[3][1], paddings[2][0], paddings[2][1], paddings[1][0], paddings[1][1]
                ]
            else:
                raise NotImplementedError('Does not support channels first')
            return correct_output
    
    
    opened by zhxiucui 0
  • tenorlayerx.nn没有paddle.nn.InstanceNorm2D对应的算子

    tenorlayerx.nn没有paddle.nn.InstanceNorm2D对应的算子

    paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format="NCHW", name=None) image 更多见接口文档https://www.paddlepaddle.org.cn/documentation/docs/zh/2.3/api/paddle/nn/InstanceNorm2D_cn.html#instancenorm2d

    # ======================================================== #
    ###### THIS CODE IS AN EXAMPLE, REPLACE WITH YOUR OWN ######
    # ======================================================== #
    import tensorlayerx as tlx
    
    opened by zhxiucui 0
  • tensorlayerx没有优化函数的基类,  只能使用tlx.optimizers.paddle_optimizers.Optimizer来判断

    tensorlayerx没有优化函数的基类, 只能使用tlx.optimizers.paddle_optimizers.Optimizer来判断

    New Issue Checklist

    Issue Description

    [INSERT DESCRIPTION OF THE PROBLEM]

    Reproducible Code

    • Which OS are you using ?
    • Please provide a reproducible code of your issue. Without any reproducible code, you will probably not receive any help.

    [INSERT CODE HERE]

    # ======================================================== #
    ###### THIS CODE IS AN EXAMPLE, REPLACE WITH YOUR OWN ######
    # ======================================================== #
    # paddle
    import paddle
    x = 13
    print(isinstance(x, paddle.optimizers.Optimizer))
    
    # tensorlayer
    import os
    os.environ['TL_BACKEND'] = 'paddle'
    import tensorlayer as tlx
    x = 13
    print(isinstance(x, tlx.optimizers.paddle_optimizers.Optimizer))
    # ======================================================== #
    ###### THIS CODE IS AN EXAMPLE, REPLACE WITH YOUR OWN ######
    # ======================================================== #
    
    opened by zhxiucui 0
  • tensorlayerx.nn.UpSampling2d当data_format=

    tensorlayerx.nn.UpSampling2d当data_format="channels_first"和paddle.nn.Upsample输出结果维度不一致

    New Issue Checklist

    Issue Description

    [INSERT DESCRIPTION OF THE PROBLEM]

    Reproducible Code

    • Which OS are you using ?
    • Please provide a reproducible code of your issue. Without any reproducible code, you will probably not receive any help.

    [INSERT CODE HERE]

    # ======================================================== #
    ###### THIS CODE IS AN EXAMPLE, REPLACE WITH YOUR OWN ######
    # ======================================================== #
    import os
    import paddle
    os.environ['TL_BACKEND'] = 'paddle'
    import tensorlayerx as tlx
    
    tlx_ni = tlx.nn.Input([4, 32, 50, 50], name='input')
    tlx_out = tlx.nn.UpSampling2d(scale=(2, 2), data_format="channels_first")(tlx_ni)
    print(f"tlx_out.shape={tlx_out.shape}")
    
    pd_ni = paddle.rand([4, 32, 50, 50], dtype="float32")
    pd_out = paddle.nn.Upsample(scale_factor=2, data_format="NCHW")(pd_ni)
    print(f"pd_out.shape={pd_out.shape}")
    
    # ======================================================== #
    ###### THIS CODE IS AN EXAMPLE, REPLACE WITH YOUR OWN ######
    # ======================================================== #
    

    输出结果 tlx_out.shape=[4, 32, 64, 100] pd_out.shape=[4, 32, 100, 100]

    opened by zhxiucui 0
Releases(v0.5.7)
  • v0.5.7(Sep 19, 2022)

    TensorLayerX 0.5.7 is a maintenance release . In this release , we have the following changes.

    • Fix PyTorch back-end depthtospace operator.
    • Fix where the training API could not accept multiple inputs.
    • Add the example of importing trained models from PyTorch or Paddle to TensorLayerX.
    • Add roll and logsoftmax operators.
    • Update the model trained by any backend of TensorLayerX can be imported to any backend of TensorLayerX.

    Feel free to use it and make suggestions!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.6(Jul 15, 2022)

    TensorLayerX 0.5.6 is a maintenance release . In this release , we have the following changes .

    • Fixed Sequential mode ONNX node collection .
    • Fixed bug with RNN LSTM GRU training parameters .
    • Fixed the inconsistency of different backends parameters of DepthWiseConv2d.
    • Fixed the bug of saving parameters to npz.
    • Updated padding layers.

    Feel free to use it and make suggestions!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.5(Jun 27, 2022)

    TensorLayerX 0.5.5 is a maintenance release.In this release, we have the following changes.

    • Added get_device, to_device operator.
    • Changed the parameter name of the average pooling layer to (AvgPool1d, GlobalAvgPool1d, AdaptiveAvgPool1d, AvgPool2d, GlobalAvgPool2d Etc.)
    • Fixed LSTM RNN GRU.
    • Fixed a bug where ParameterList and ParameterDict training parameters on the TensorFlow backend were not collected.
    • Fixed support for MindSpore1.7.0 version.

    Feel free to use it and make suggestions!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.4(May 31, 2022)

    TensorLayerX 0.5.4 is a maintenance release.In this release, we have the following changes.

    • Added documentation for metric functions
    • Add Einsum
    • Fixed PyTorch back-end optimizers
    • Fixed preprocessing when activation functions are used as parameters

    Feel free to use it and make suggestions!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.3(May 16, 2022)

    TensorLayerX 0.5.3 is a maintenance release.In this release, we have the following changes.

    • Added kernel_size, stride, dilation parameters can be int or tuple.
    • Added padding mode can be int, tuple, or str. str is "SAME" or "VALID".
    • Added TensorLayerX model topology for ONNX model export, can generate topology by model.build_graph(inputs).
    • Fix the problem of slow training speed due to MindSpore optimizer wrapping.

    Feel free to use it and make suggestions!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.1(Apr 14, 2022)

  • v0.5.0(Mar 7, 2022)

    TensorLayerX 0.5.0 is a maintenance release,it supports TensorFlow、MindSpore and PaddlePaddle backends, and supports some PyTorch operator backends, allowing users to run the code on different hardware like Nvidia-GPU and Huawei-Ascend. Feel free to use it and make suggestions.

    Source code(tar.gz)
    Source code(zip)
Owner
TensorLayer Community
A neutral open community to promote AI technology.
TensorLayer Community
Capsule endoscopy detection DACON challenge

capsule_endoscopy_detection (DACON Challenge) Overview Yolov5, Yolor, mmdetection기반의 모델을 사용 (총 11개 모델 앙상블) 모든 모델은 학습 시 Pretrained Weight을 yolov5, yolo

MAILAB 11 Nov 25, 2022
Modeling Category-Selective Cortical Regions with Topographic Variational Autoencoders

Modeling Category-Selective Cortical Regions with Topographic Variational Autoencoders

1 Oct 11, 2021
Pytorch implementation for "Open Compound Domain Adaptation" (CVPR 2020 ORAL)

Open Compound Domain Adaptation [Project] [Paper] [Demo] [Blog] Overview Open Compound Domain Adaptation (OCDA) is the author's re-implementation of t

Zhongqi Miao 137 Dec 15, 2022
A generalist algorithm for cell and nucleus segmentation.

Cellpose | A generalist algorithm for cell and nucleus segmentation. Cellpose was written by Carsen Stringer and Marius Pachitariu. To learn about Cel

MouseLand 733 Dec 29, 2022
Weakly-supervised semantic image segmentation with CNNs using point supervision

Code for our ECCV paper What's the Point: Semantic Segmentation with Point Supervision. Summary This library is a custom build of Caffe for semantic i

27 Sep 14, 2022
Quantization library for PyTorch. Support low-precision and mixed-precision quantization, with hardware implementation through TVM.

HAWQ: Hessian AWare Quantization HAWQ is an advanced quantization library written for PyTorch. HAWQ enables low-precision and mixed-precision uniform

Zhen Dong 293 Dec 30, 2022
tensorflow code for inverse face rendering

InverseFaceRender This is tensorflow code for our project: Learning Inverse Rendering of Faces from Real-world Videos. (https://arxiv.org/abs/2003.120

Yuda Qiu 18 Nov 16, 2022
Multi-Glimpse Network With Python

Multi-Glimpse Network Our code requires Python ≥ 3.8 Installation For example, venv + pip: $ python3 -m venv env $ source env/bin/activate (env) $ pyt

9 May 10, 2022
render sprites into your desktop environment as shaped windows using GTK

spritegtk render static or animated sprites into your desktop environment as dynamic shaped windows using GTK requires pycairo and PYGobject: pip inst

hermit 20 Oct 27, 2022
TLoL (Python Module) - League of Legends Deep Learning AI (Research and Development)

TLoL-py - League of Legends Deep Learning Library TLoL-py is the Python component of the TLoL League of Legends deep learning library. It provides a s

7 Nov 29, 2022
Facilitating Database Tuning with Hyper-ParameterOptimization: A Comprehensive Experimental Evaluation

A Comprehensive Experimental Evaluation for Database Configuration Tuning This is the source code to the paper "Facilitating Database Tuning with Hype

DAIR Lab 9 Oct 29, 2022
The Official TensorFlow Implementation for SPatchGAN (ICCV2021)

SPatchGAN: Official TensorFlow Implementation Paper "SPatchGAN: A Statistical Feature Based Discriminator for Unsupervised Image-to-Image Translation"

39 Dec 30, 2022
Official PyTorch implementation of the paper "Graph-based Generative Face Anonymisation with Pose Preservation" in ICIAP 2021

Contents AnonyGAN Installation Dataset Preparation Generating Images Using Pretrained Model Train and Test New Models Evaluation Acknowledgments Citat

Nicola Dall'Asen 10 May 24, 2022
Real-time object detection on Android using the YOLO network with TensorFlow

TensorFlow YOLO object detection on Android Source project android-yolo is the first implementation of YOLO for TensorFlow on an Android device. It is

Nataniel Ruiz 624 Jan 03, 2023
A curated list of Generative Deep Art projects, tools, artworks, and models

Generative Deep Art A curated list of Generative Deep Art projects, tools, artworks, and models Inbox Get started with making AI art in 2022 – deeplea

Filipe Calegario 251 Jan 03, 2023
The repo of Feedback Networks, CVPR17

Feedback Networks http://feedbacknet.stanford.edu/ Paper: Feedback Networks, CVPR 2017. Amir R. Zamir*,Te-Lin Wu*, Lin Sun, William B. Shen, Bertram E

Stanford Vision and Learning Lab 87 Nov 19, 2022
Pose estimation for iOS and android using TensorFlow 2.0

💃 Mobile 2D Single Person (Or Your Own Object) Pose Estimation for TensorFlow 2.0 This repository is forked from edvardHua/PoseEstimationForMobile wh

tucan9389 165 Nov 16, 2022
Codebase for Diffusion Models Beat GANS on Image Synthesis.

Codebase for Diffusion Models Beat GANS on Image Synthesis.

Katherine Crowson 128 Dec 02, 2022
Deep Reinforcement Learning for Keras.

Deep Reinforcement Learning for Keras What is it? keras-rl implements some state-of-the art deep reinforcement learning algorithms in Python and seaml

Keras-RL 0 Dec 15, 2022
Keras-1D-NN-Classifier

Keras-1D-NN-Classifier This code is based on the reference codes linked below. reference 1, reference 2 This code is for 1-D array data classification

Jae-Hoon Shim 6 May 18, 2021