Giter Club home page Giter Club logo

elegan23 / hypernets Goto Github PK

View Code? Open in Web Editor NEW
45.0 4.0 6.0 577 KB

Hypercomplex Neural Networks with PyTorch

License: MIT License

Python 50.71% Jupyter Notebook 49.29%
convolutional-neural-networks hypercomplex-neural-networks lightweight-neural-network efficient-neural-networks quaternion-neural-networks hypercomplex-algebra phc phm pytorch hypercomlpex-parameterization parameterize-neural-network lightweight-convolution hypercomplex hypercomplex-convolution parameterize-hypercomplex-layer

hypernets's Introduction

HyperNets

Hypercomplex Neural Networks with PyTorch: this repository would be a container for hypercomplex neural network modules to facilitate research in this topic.

News ๐Ÿ’ฃ

โš ๏ธ PHC layer for 3D convolutions has been released! Check it in the file layers/ph_layers.py!

โš ๏ธ PHC layer for 1D convolutions has been released! Check it in the file layers/ph_layers.py! Thanks to Christian Brignone and Gioia Mancini for this contribution.

PHNNs: Lightweight Neural Networks via Parameterized Hypercomplex Convolutions

[ArXiv preprint][IEEEXplore]

PWC

Abstract ๐Ÿ“‘

Hypercomplex neural networks have proved to reduce the overall number of parameters while ensuring valuable performances by leveraging the properties of Clifford algebras. Recently, hypercomplex linear layers have been further improved by involving efficient parameterized Kronecker products. In this paper, we define the parameterization of hypercomplex convolutional layers to develop lightweight and efficient large-scale convolutional models. Our method grasps the convolution rules and the filters organization directly from data without requiring a rigidly predefined domain structure to follow. The proposed approach is flexible to operate in any user-defined or tuned domain, from 1D to nD regardless of whether the algebra rules are preset. Such a malleability allows processing multidimensional inputs in their natural domain without annexing further dimensions, as done, instead, in quaternion neural networks for 3D inputs like color images. As a result, the proposed method operates with 1/n free parameters as regards its analog in the real domain. We demonstrate the versatility of this approach to multiple domains of application by performing experiments on various image datasets as well as audio datasets in which our method outperforms real and quaternion-valued counterparts.

Parameterized Hypercomplex Convolutional (PHC) Layer ๐ŸŽฏ

The core of the approach is the sum of Kronecker products which grasps the convolution rule and the filters organization directly from data. The higlights of our approach is defined in:

def kronecker_product1(self, A, F):
  siz1 = torch.Size(torch.tensor(A.shape[-2:]) * torch.tensor(F.shape[-4:-2]))
  siz2 = torch.Size(torch.tensor(F.shape[-2:]))
  res = A.unsqueeze(-1).unsqueeze(-3).unsqueeze(-1).unsqueeze(-1) * F.unsqueeze(-4).unsqueeze(-6)
  siz0 = res.shape[:1]
  out = res.reshape(siz0 + siz1 + siz2)
  return out
 
def forward(self, input):
  self.weight = torch.sum(self.kronecker_product1(self.A, self.F), dim=0)
  input = input.type(dtype=self.weight.type())      
  return F.conv2d(input, weight=self.weight, stride=self.stride, padding=self.padding)

Te PHC layer, by setting n=4, is able to subsume the Hamilton rule to organize filters in the convolution as:

Tutorials ๐Ÿ“ƒ

The folder tutorials contains a set of tutorials to understand the Parameterized Hypercomplex Multiplication (PHM) layer and the Parameterized Hypercomplex Convolutional (PHC) layer. We develop simple toy examples to learn the matrices A that define algebra rules in order to demonstrate the effectiveness of the proposed approach.

  • PHM tutorial.ipynb is a simple tutorial which shows how the PHM layer learns the Hamilton product between two pure quaternions.
  • PHC tutorial.ipynb is a simple tutorial which shows how the PHC layer learn the Hamilton rule to organize filters in convolution.
  • Toy regression examples with PHM.ipynb is a notebook containing some regression tasks.

Experiments on Image Classification ๐ŸŒ†

To reproduce image classification experiments, please refer to the image-classification folder.

  • pip install -r requirements.txt.
  • Choose the configurations in configs and run the experiment:

python main.py --TextArgs=config_name.txt.

The experiment will be directly tracked on Weight&Biases.

Experiments on Sound Event Detection ๐ŸŽผ

To reproduce sound event detection experiments, please refer to the sound-event-detection folder.

  • pip install -r requirements.txt.

We follow the instructions in the original repository for the L3DAS21 dataset:

  • Download the dataset:

python download_dataset.py --task Task2 --set_type train --output_path DATASETS/Task2

python download_dataset.py --task Task2 --set_type dev --output_path DATASETS/Task2

  • Preprocess the dataset:

python preprocessing.py --task 2 --input_path DATASETS/Task2 --num_mics 1 --frame_len 100

Specify num_mics=2 and output_phase=True to perform experiments up to 16-channel inputs.

  • Run the experiment:

python train_baseline_task2.py

Specify the hyperparameters options. We perform experiments with epochs=1000, batch_size=16 and input_channels=4/8/16 on a single Tesla V100-32GB GPU.

  • Run the evaluation:

python evaluate_baseline_task2.py

Specify the hyperparameters options.

More will be added ๐Ÿ“…

โš ๏ธ Work in progress...

  • PHC for transposed convolutions
  • PHC in TensorFlow

Cite

Please cite our work if you found it useful:

@article{grassucci2021PHNNs,
      title={{PHNN}s: Lightweight Neural Networks via Parameterized Hypercomplex Convolutions}, 
      author={Grassucci, E. and Zhang, A. and Comminiello, D.},
      year={2022},
      journal={IEEE Transactions on Neural Networks and Learning Systems}, 
      year={2022},
      pages={1-13},
      doi={10.1109/TNNLS.2022.3226772}}

Similar reporitories ๐Ÿ‘ฅ

Quaternion layers are borrowed from:

hypernets's People

Contributors

dcomminiello avatar elegan23 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hypernets's Issues

Any possibility for a TensorFlow implementation?

Hello. I have a few different projects that could potentially benefit from these algorithms. However, these projects and classes all use TensorFlow as their main framework. While rewriting these layers would probably not be too difficult on my end, are there any plans for a TensorFlow port? If not, would it be possible for one to be written?

Also, just to get an idea, how difficult is it generally to port PyTorch layers to TensorFlow? How much debugging and messing around would one be looking at?

Unable to run Image classification experiment

Sir, I am willing to run your experimentation on image classification but failed , can you help how to compare performance of HyperComplex Neuralnetwork with Hamiltonian product and Qronecker Product on a image dataset.

Capture

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.