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
Understanding the Properties of Minimum Bayes Risk Decoding in Neural Machine Translation.

Understanding Minimum Bayes Risk Decoding This repo provides code and documentation for the following paper: Müller and Sennrich (2021): Understanding

ZurichNLP 13 May 01, 2022
An implementation of MobileFormer

MobileFormer An implementation of MobileFormer proposed by Yinpeng Chen, Xiyang Dai et al. Including [1] Mobile-Former proposed in:

slwang9353 62 Dec 28, 2022
A 3D Dense mapping backend library of SLAM based on taichi-Lang designed for the aerial swarm.

TaichiSLAM This project is a 3D Dense mapping backend library of SLAM based Taichi-Lang, designed for the aerial swarm. Intro Taichi is an efficient d

XuHao 230 Dec 19, 2022
Multi-Task Learning as a Bargaining Game

Nash-MTL Official implementation of "Multi-Task Learning as a Bargaining Game". Setup environment conda create -n nashmtl python=3.9.7 conda activate

Aviv Navon 87 Dec 26, 2022
A fast implementation of bss_eval metrics for blind source separation

fast_bss_eval Do you have a zillion BSS audio files to process and it is taking days ? Is your simulation never ending ? Fear no more! fast_bss_eval i

Robin Scheibler 99 Dec 13, 2022
Official Pytorch Implementation for Splicing ViT Features for Semantic Appearance Transfer presenting Splice

Splicing ViT Features for Semantic Appearance Transfer [Project Page] Splice is a method for semantic appearance transfer, as described in Splicing Vi

Omer Bar Tal 253 Jan 06, 2023
PyTorch implementation of "PatchGame: Learning to Signal Mid-level Patches in Referential Games" to appear in NeurIPS 2021

PatchGame: Learning to Signal Mid-level Patches in Referential Games This repository is the official implementation of the paper - "PatchGame: Learnin

Kamal Gupta 22 Mar 16, 2022
Predicting Semantic Map Representations from Images with Pyramid Occupancy Networks

This is the code associated with the paper Predicting Semantic Map Representations from Images with Pyramid Occupancy Networks, published at CVPR 2020.

Thomas Roddick 219 Dec 20, 2022
Implementation of Change-Based Exploration Transfer (C-BET)

Implementation of Change-Based Exploration Transfer (C-BET), as presented in Interesting Object, Curious Agent: Learning Task-Agnostic Exploration.

Simone Parisi 29 Dec 04, 2022
Easy and Efficient Object Detector

EOD Easy and Efficient Object Detector EOD (Easy and Efficient Object Detection) is a general object detection model production framework. It aim on p

381 Jan 01, 2023
PyTorch implementation of the paper Ultra Fast Structure-aware Deep Lane Detection

PyTorch implementation of the paper Ultra Fast Structure-aware Deep Lane Detection

1.4k Jan 06, 2023
Generate images from texts. In Russian

ruDALL-E Generate images from texts pip install rudalle==1.1.0rc0 🤗 HF Models: ruDALL-E Malevich (XL) ruDALL-E Emojich (XL) (readme here) ruDALL-E S

AI Forever 1.6k Dec 31, 2022
Parris, the automated infrastructure setup tool for machine learning algorithms.

README Parris, the automated infrastructure setup tool for machine learning algorithms. What Is This Tool? Parris is a tool for automating the trainin

Joseph Greene 319 Aug 02, 2022
Parametric Contrastive Learning (ICCV2021)

Parametric-Contrastive-Learning This repository contains the implementation code for ICCV2021 paper: Parametric Contrastive Learning (https://arxiv.or

DV Lab 156 Dec 21, 2022
Towards Rolling Shutter Correction and Deblurring in Dynamic Scenes (CVPR2021)

RSCD (BS-RSCD & JCD) Towards Rolling Shutter Correction and Deblurring in Dynamic Scenes (CVPR2021) by Zhihang Zhong, Yinqiang Zheng, Imari Sato We co

81 Dec 15, 2022
iris - Open Source Photos Platform Powered by PyTorch

Open Source Photos Platform Powered by PyTorch. Submission for PyTorch Annual Hackathon 2021.

Omkar Prabhu 137 Sep 10, 2022
The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"

Swin-Unet The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"(https://arxiv.org/abs/2105.05537). A validatio

869 Jan 07, 2023
Towards Interpretable Deep Metric Learning with Structural Matching

DIML Created by Wenliang Zhao*, Yongming Rao*, Ziyi Wang, Jiwen Lu, Jie Zhou This repository contains PyTorch implementation for paper Towards Interpr

Wenliang Zhao 75 Nov 11, 2022
Joint learning of images and text via maximization of mutual information

mutual_info_img_txt Joint learning of images and text via maximization of mutual information. This repository incorporates the algorithms presented in

Ruizhi Liao 10 Dec 22, 2022
Resources related to our paper "CLIN-X: pre-trained language models and a study on cross-task transfer for concept extraction in the clinical domain"

CLIN-X (CLIN-X-ES) & (CLIN-X-EN) This repository holds the companion code for the system reported in the paper: "CLIN-X: pre-trained language models a

Bosch Research 4 Dec 05, 2022