
## Downlaod the weights into ./pth file using the link below. 

https://mega.nz/folder/nzgGCTzI#m1wr5sm4JgR8iGlndlXfMA


## Requirements

```bash

pip install -r requirements.txt

```

## Colorcube.py - Documentation

**create_color_cube(image)**
This function converts an input RGB image to HSV and YCbCr color spaces and concatenates all channels to create a "Color Cube."

Arg: image: A NumPy array of shape (H, W, 3) representing the input RGB image.
returns: color_cube: A NumPy array of shape (H, W, 9) which contains the concatenated channels from the RGB, HSV, and YCbCr representations of the input image.

````
image = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
color_cube = create_color_cube(image)
print(color_cube.shape)  # Output: (224, 224, 9)
````

**ColorCubeTransform (Class)**

This custom transform class converts an image into the "Color Cube" format by applying conversions to HSV and YCbCr color spaces in addition to the existing RGB channels. It is designed for integration into data preprocessing pipelines, particularly for deep learning tasks using PyTorch.

## colorcubenet.py - Documentation

This module defines a custom deep learning model built on EfficientNet-B0, enhanced with a Channel Attention block and residual connections. The model supports 9-channel input from a "Color Cube" (concatenated RGB, HSV, and YCbCr channels). It also provides mechanisms for Grad-CAM analysis by storing activations and gradients.


**CustomEfficientNet (Class)**
1. This class defines a custom neural network architecture that utilizes three parallel EfficientNet-B0 models, modified to accept 9-channel inputs. It incorporates a Channel Attention block and residual connections for better feature learning.

Args:

num_classes (int): The number of output classes for classification (default is 2 for binary classification).

### Methods:

__init__(self, num_classes=2):

Initializes three parallel EfficientNet-B0 backbones, loading pre-trained weights for two of them and modifying the first convolutional layers to accept 9-channel inputs.
Includes a Channel Attention block and a residual connection layer. Adds a fully connected (FC) layer for final classification.

forward(self, x):

1. Extracts features from three EfficientNet-B0 models in parallel.
2. Applies channel attention to the fused features. 
3. Uses residual connections to refine the feature map.
4. Performs global average pooling and outputs the final classification result.

save_gradients(self, grad):

1. Stores the gradients for Grad-CAM analysis.

get_activations_gradients(self):

1. Returns the saved activations and gradients for Grad-CAM.

Example Usage: 

`
from colorcubenet import CustomEfficientNet
import torch

model = CustomEfficientNet(num_classes=2)
input_image = torch.randn(1, 9, 224, 224)
output = model(input_image)
`

## main.py - Documentation

This script is responsible for training and validating the CustomEfficientNet model on a dataset using a data pipeline with early stopping and saving the best model. It includes dataset loading, augmentation, model initialization, loss computation with class weights, and evaluation.

Usage: 

``` bash

python main.py

```

## evaluate.py - Documentation

This script is responsible for evaluating a trained CustomEfficientNet model on a test dataset. The evaluation includes calculating various performance metrics such as Equal Error Rate (EER), Accuracy, Precision, Recall, F1-score, Confusion Matrix, and BPCER (Bona Fide Presentation Classification Error Rate) at specific APCER (Attack Presentation Classification Error Rate) thresholds.

``` bash

python evaluation.py

```


## SNR.py -documentation

This is a sample code to demonstrate how to calcualate SNR using saliency maps generated from GradCam. To run this code activation and gradients from the colorcubenet must be saved and accessed. 

## ./pth Directory
Downlaod the weights into ./pth file using the link below. 

https://mega.nz/folder/nzgGCTzI#m1wr5sm4JgR8iGlndlXfMA

**colorcubenet_CelebASpoof.pth:**
This file contains the pre-trained weights of the ColorCubeNet model trained on the CelebA-Spoof dataset.

**colorcubenet_fpad_i_22.pth:**

This file holds the trained ColorCubeNet model weights from training on the FPAD-i-22

**colorcubenet_fpag_g_23.pth:**

This model represents the ColorCubeNet trained on the FPAD-g-23.

**colorcubenet_iiitd.pth:**

Contains the ColorCubeNet model trained on the IIITD dataset.

**colorcubenet_OULU_NPU.pth:**

A trained ColorCubeNet model specifically on the OULU-NPU dataset.

**colorcubenet_synthASpoof.pth:**

This model is trained on the SynthASpoof dataset.

**Effib0_hsv.pth:**

This file contains the trained EfficientNet-B0 model on HSV color space. It is used as part of the ColorCube architecture to handle color space-specific transformations.


**Effib0_ycbcr.pth:**

This file contains the trained EfficientNet-B0 model on YCbCr color space. It is used as part of the ColorCube architecture to handle color space-specific transformations.


## ./output Directory

main.py outputs are stored in the output folder.  