We define CQNNs, where the neurons in the convolutional layers of CNNs are replaced by quadratic neurons. CNNs in general have convolutional layers for feature extraction, followed by dense (fully connected) layers for classification. To create a CQNN, we replace the linear neurons in the convolutional layers with quadratic neurons. Note that the neurons in the fully connected layers are left intact.
As shown in the figure, in CNNs the neurons compute the linear function f(x). In CQNNs, these are replaced with quadratic neurons that compute function q(x) (quadratic form).
Please the ICPR publication CQNN: Convolutional Quadratic Neural Networks for details.
This sample code takes two well-known architectures: Alexnet and Resnet, and creates quadratic variants. The code can be to train on two datasets Cifar10 and Cifar100
- Application.py: The main file to run the training and testing
- linear: This package has the linear variants of Alexnet and ResNet architectures.
- quadratic: This package has the quadratic variants of the Alexnet and ResNet architectures.
- quadratic/qconv2d.py: This module has the implementation of the quadratic convolutional layer. It takes as input a batch of images and computes the quadratic output.
The code is tested in an Ubuntu (18.04) environment. The following software and modules are required (See requirements.txt)
- Python 2.7
- numpy 1.16.6
- opencv-python 3.4.1.15
- tensorflow-gpu 2.0.0
- keras 2.3.0
Using virtual environment.
- Create a virtual environent.
$ virtualvenv venv
- Activate environment
$ source venv/bin/activate
- Install packages
$ pip install -r requirements.txt
- To train a CNN variant (Linear convolutional layers) on the cifar100 dataset
- Alexnet
$ python Application.py -d cifar100 -m alexnet -n linear
- Resnet
$ python Application.py -d cifar100 -m resnet -n linear
- To train a CQNN variant (Quadratic convolutional layers) on the cifar100 dataset
- Alexnet
$ python Application.py -d cifar100 -m alexnet -n quadratic
- Resnet
$ python Application.py -d cifar100 -m resnet -n quadratic
