Rational Activation Functions - Replacing Padé Activation Units

Overview

ArXiv Badge PWC

Logo

Rational Activations - Learnable Rational Activation Functions

First introduce as PAU in Padé Activation Units: End-to-end Learning of Activation Functions in Deep Neural Network.

1. About Rational Activation Functions

Rational Activations are a novel learnable activation functions. Rationals encode activation functions as rational functions, trainable in an end-to-end fashion using backpropagation and can be seemingless integrated into any neural network in the same way as common activation functions (e.g. ReLU).

Rationals: Beyond known Activation Functions

Rational can approximate any known activation function arbitrarily well (cf. Padé Activation Units: End-to-end Learning of Flexible Activation Functions in Deep Networks): rational_approx (*the dashed lines represent the rational approximation of every function)

Rational are made to be optimized by the gradient descent, and can discover good properties of activation functions after learning (cf Recurrent Rational Networks): rational_properties

Rationals evaluation on different tasks

Rational matches or outperforms common activations in terms of predictive performance and training time. And, therefore relieves the network designer of having to commit to a potentially underperforming choice.

  • Recurrent Rational Functions have then been introduced in Recurrent Rational Networks, and both Rational and Recurrent Rational Networks are evaluated on RL Tasks. rl_scores :octocat: See rational_rl github repo

2. Dependencies

We support MxNet, Keras, and PyTorch. Instructions for MxNet can be found here. Instructions for Keras here. The following README instructions assume that you want to use rational activations in PyTorch.

PyTorch>=1.4.0
CUDA>=10.2

3. Installation

To install the rational_activations module, you can use pip, but:

‼️ rational_activations is currently compatible with torch==1.9.0 by default ‼️

For non TensorFlow and MXNet users, or if the command bellow don't work the package listed bellow don't work on your machine:

TensorFlow or MXNet (and torch==1.9.0)

 pip3 install -U pip wheel
 pip3 install torch rational_activations

Other CUDA/Pytorch

For any other torch version, please install from source: Modify requirements.txt to your corresponding torch version

 pip3 install airspeed  # to compile the CUDA templates
 git clone https://github.com/ml-research/rational_activations.git
 cd rational_activations
 pip3 install -r requirements.txt --user
 python3 setup.py install --user

If you encounter any trouble installing rational, please contact this person.

4. Using Rational in Neural Networks

Rational can be integrated in the same way as any other common activation function.

import torch
from rational.torch import Rational

model = torch.nn.Sequential(
    torch.nn.Linear(D_in, H),
    Rational(), # e.g. instead of torch.nn.ReLU()
    torch.nn.Linear(H, D_out),
)

Please also check the documentation 📔

5. Cite Us in your paper

@inproceedings{molina2019pade,
  title={Pad{\'e} Activation Units: End-to-end Learning of Flexible Activation Functions in Deep Networks},
  author={Molina, Alejandro and Schramowski, Patrick and Kersting, Kristian},
  booktitle={International Conference on Learning Representations},
  year={2019}
}

@article{delfosse2021recurrent,
  title={Recurrent Rational Networks},
  author={Delfosse, Quentin and Schramowski, Patrick and Molina, Alejandro and Kersting, Kristian},
  journal={arXiv preprint arXiv:2102.09407},
  year={2021}
}

@misc{delfosse2020rationals,
  author = {Delfosse, Quentin and Schramowski, Patrick and Molina, Alejandro and Beck, Nils and Hsu, Ting-Yu and Kashef, Yasien and Rüling-Cachay, Salva and Zimmermann, Julius},
  title = {Rational Activation functions},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished={\url{https://github.com/ml-research/rational_activations}}
}
Comments
  • setup.py returns TypeError: module() takes at most 2 arguments (3 given)

    setup.py returns TypeError: module() takes at most 2 arguments (3 given)

    Hi,

    when running the command

    python3 setup.py install --user,

    I receive the error described above at line 137 in the setup.py file. I wasn't able to fix this problem on my own. Maybe you guys can help me out.

    opened by AliKalsen 8
  • Can't Install with Cuda 11.2 & PyTorch 1.7.1

    Can't Install with Cuda 11.2 & PyTorch 1.7.1

    Hello,

    I have seen that Cuda 11 compatible version is already among planned tasks.

    I just wanted to let you know that it has been failed with following configuration.

    Cuda compilation tools, release 11.2, V11.2.67
    Build cuda_11.2.r11.2/compiler.29373293_0
    My installed PyTorch library version is 1.7.1
    
    opened by kayuksel 8
  • TypeError when initializing a rational activation function in Keras

    TypeError when initializing a rational activation function in Keras

    Hi,

    when initializing a rational activation function in Keras as described in the README file, I receive the following error:

    TypeError: __init__() missing 1 required positional argument: 'name'

    This error leads to line 60 of the file rational_base.py, whose __init() method expects an additional argument, which is never provided in the inheriting class Rational(). However, when adding an argument to super().__init(name) in the rational.py file, I receive another error:

    AttributeError: Can't set the attribute "name", likely because it conflicts with an existing read-only @property of the object. Please choose a different name.

    I don't know how to to fix it yet. Interestingly, when using pytorch, everything just works fine. Maybe you guys can help me.

    opened by AliKalsen 3
  • Encoding issue file read

    Encoding issue file read

    The following code will result in an ascii encoding error when trying to execute in container: https://github.com/ml-research/rational_activations/blob/8efb850a49f5feaea669794aa9ef977fed8b7df5/setup.py#L115-L119

    opened by PaVim96 2
  • Add option to force cuda compilation via env flag

    Add option to force cuda compilation via env flag

    Add a wrapper for torch cuda availability check (torch.cuda.is_available) that takes an environment variable 'FORCE_CUDA' into account and returns also true iff FORCE_CUDA=1.

    This is necessary when building rational in a Dockerfile script since the docker build pass doesn't have access to cuda and thus torch.cuda.is_available always returns false, even when the docker image which is to be built in fact does have cuda.

    opened by braun-steven 0
  • About training on ImageNet

    About training on ImageNet

    I am happy to find your innovative work!

    But when I tried to apply the Rational activation on ResNets for ImageNet training, I consistently got failed training (i.e., NaN). I guess it requires different parameter settings when implementing Rational activation on ImageNet. May I know what specific changes should I give to the Rational activation when training on ImageNet (if you have that experience)?

    Thank you so much!

    opened by SudongCAI 0
  • Installation commands in PyPi page are not working for with CUDA cases

    Installation commands in PyPi page are not working for with CUDA cases

    I have all the requirements installed along with Python 3.6 and PyTorch 1.7.1 with CUDA 11.0. Now when I run pip3 install rational_activations it installs properly but while importing it gives a warning saying that it is not CUDA optimized version and doesn't use cuda. After a bit of search I got to see the command for CUDA version at PyPi page (https://pypi.org/project/rational-activations/). But when I run that pip3 install rational_activations_cu110 it says :

    ERROR: Could not find a version that satisfies the requirement rational_activations_cu110 (from versions: none) ERROR: No matching distribution found for rational_activations_cu110

    Infact for other CUDA versions too the whl files are not found and those existing links in PyPi page are all broken. So, humble request is to provide at least a few different versions (cuda / non-CUDA) as it is supposed to be as per the PyPi page, without just asking us to build from the source (which is anyways not so clean either due to several low level architectural dependencies).

    opened by tatban 1
  • Readme says by default PyTorch==1.9.0 supported, but internally it requires PyTorch==1.7.1

    Readme says by default PyTorch==1.9.0 supported, but internally it requires PyTorch==1.7.1

    I have created an environment with python 3.9 and installed all the requirements ( numpy scipy matplotlib torch==1.9.0 tqdm termcolor) separately with cuda 11.1. But then when I am trying to only install rational activation function (pip3 install rational_activations) it starts installing PyTorch 1.7.1 and messing up with already prepared environment. So, please clarify the confusion. Whether it needs PyTorch 1.7.1 or 1.9.0? And fix it accordingly. PS: I was not building from source, I just wanted to install it from the binary which is supposed to support PyTorch 1.9.0 by default as per the readme. Architecture: Windows 10 64bit Environment: conda

    opened by tatban 3
Owner
ml-research@TUDarmstadt
Machine Learning Group at TU Darmstadt
ml-research@TUDarmstadt
Official codes for the paper "Learning Hierarchical Discrete Linguistic Units from Visually-Grounded Speech"

ResDAVEnet-VQ Official PyTorch implementation of Learning Hierarchical Discrete Linguistic Units from Visually-Grounded Speech What is in this repo? M

Wei-Ning Hsu 21 Aug 23, 2022
A PyTorch Implementation of "Neural Arithmetic Logic Units"

Neural Arithmetic Logic Units [WIP] This is a PyTorch implementation of Neural Arithmetic Logic Units by Andrew Trask, Felix Hill, Scott Reed, Jack Ra

Kevin Zakka 181 Nov 18, 2022
A real-time motion capture system that estimates poses and global translations using only 6 inertial measurement units

TransPose Code for our SIGGRAPH 2021 paper "TransPose: Real-time 3D Human Translation and Pose Estimation with Six Inertial Sensors". This repository

Xinyu Yi 261 Dec 31, 2022
Conversion between units used in magnetism

convmag Conversion between various units used in magnetism The conversions between base units available are: T <-> G : 1e4

null 0 Jul 15, 2021
Python-based Informatics Kit for Analysing Chemical Units

INSTALLATION Python-based Informatics Kit for the Analysis of Chemical Units Step 1: Make a conda environment: conda create -n pikachu python=3.9 cond

null 47 Dec 23, 2022
Official Repsoitory for "Activate or Not: Learning Customized Activation." [CVPR 2021]

CVPR 2021 | Activate or Not: Learning Customized Activation. This repository contains the official Pytorch implementation of the paper Activate or Not

null 184 Dec 27, 2022
ActNN: Reducing Training Memory Footprint via 2-Bit Activation Compressed Training

ActNN : Activation Compressed Training This is the official project repository for ActNN: Reducing Training Memory Footprint via 2-Bit Activation Comp

UC Berkeley RISE 178 Jan 5, 2023
FactSeg: Foreground Activation Driven Small Object Semantic Segmentation in Large-Scale Remote Sensing Imagery (TGRS)

FactSeg: Foreground Activation Driven Small Object Semantic Segmentation in Large-Scale Remote Sensing Imagery by Ailong Ma, Junjue Wang*, Yanfei Zhon

Kingdrone 43 Jan 5, 2023
Many Class Activation Map methods implemented in Pytorch for CNNs and Vision Transformers. Including Grad-CAM, Grad-CAM++, Score-CAM, Ablation-CAM and XGrad-CAM

Class Activation Map methods implemented in Pytorch pip install grad-cam ⭐ Tested on many Common CNN Networks and Vision Transformers. ⭐ Includes smoo

Jacob Gildenblat 6.6k Jan 6, 2023
With this package, you can generate mixed-integer linear programming (MIP) models of trained artificial neural networks (ANNs) using the rectified linear unit (ReLU) activation function

With this package, you can generate mixed-integer linear programming (MIP) models of trained artificial neural networks (ANNs) using the rectified linear unit (ReLU) activation function. At the moment, only TensorFlow sequential models are supported. Interfaces to either the Pyomo or Gurobi modeling environments are offered.

ChemEngAI 40 Dec 27, 2022
Tensorflow Implementation of SMU: SMOOTH ACTIVATION FUNCTION FOR DEEP NETWORKS USING SMOOTHING MAXIMUM TECHNIQUE

SMU A Tensorflow Implementation of SMU: SMOOTH ACTIVATION FUNCTION FOR DEEP NETWORKS USING SMOOTHING MAXIMUM TECHNIQUE arXiv https://arxiv.org/abs/211

Fuhang 5 Jan 18, 2022
Source for the paper "Universal Activation Function for machine learning"

Universal Activation Function Tensorflow and Pytorch source code for the paper Yuen, Brosnan, Minh Tu Hoang, Xiaodai Dong, and Tao Lu. "Universal acti

null 4 Dec 3, 2022
PyTorch implementation of ''Background Activation Suppression for Weakly Supervised Object Localization''.

Background Activation Suppression for Weakly Supervised Object Localization PyTorch implementation of ''Background Activation Suppression for Weakly S

null 35 Jan 6, 2023
Implementation of parameterized soft-exponential activation function.

Soft-Exponential-Activation-Function: Implementation of parameterized soft-exponential activation function. In this implementation, the parameters are

Shuvrajeet Das 1 Feb 23, 2022
NeuroGen: activation optimized image synthesis for discovery neuroscience

NeuroGen: activation optimized image synthesis for discovery neuroscience NeuroGen is a framework for synthesizing images that control brain activatio

null 3 Aug 17, 2022
PyTorch reimplementation of the Smooth ReLU activation function proposed in the paper "Real World Large Scale Recommendation Systems Reproducibility and Smooth Activations" [arXiv 2022].

Smooth ReLU in PyTorch Unofficial PyTorch reimplementation of the Smooth ReLU (SmeLU) activation function proposed in the paper Real World Large Scale

Christoph Reich 10 Jan 2, 2023
Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and Semantic Segmentation (CVPR 2022)

CCAM (Unsupervised) Code repository for our paper "CCAM: Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localizati

Computer Vision Insitute, SZU 113 Dec 27, 2022
A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.

imutils A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displ

Adrian Rosebrock 4.3k Jan 8, 2023
A compendium of useful, interesting, inspirational usage of pandas functions, each example will be an ipynb file

Pandas_by_examples A compendium of useful/interesting/inspirational usage of pandas functions, each example will be an ipynb file What is this reposit

Guangyuan(Frank) Li 32 Nov 20, 2022