Skip to content

hirdeshkumar2407/PirateNet-Time-Series-Pain-Classification-with-CNN-BiGRU-and-Attention

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

PirateNet: Time-Series Pain Classification with CNN–BiGRU and Attention

University Course F1 Score

This repository contains the implementation and technical report for PirateNet, a compact hybrid deep learning architecture designed for multivariate time-series classification.

This project was developed by team AI: Accidentally Intelligent for the first challenge of the Artificial Neural Networks and Deep Learning (AN2DL) course at Politecnico di Milano (November 2025).


🚀 Project Overview

The objective of this challenge is to assign multivariate time-series sequences of sensor data into three pain categories: high_pain, low_pain, or no_pain.

The Challenge Data

  • Multivariate Sequences: Each sample is a sequence of 160 time steps with several dynamic sensor channels.
  • Static Attributes: Three categorical features (n_legs, n_hands, n_eyes).
  • Main Difficulties:
    • Strong class imbalance dominated by the no_pain class.
    • Temporal locality (pain patterns appear as short events within longer neutral segments).
    • High scale and sign variability across channels.

🧠 Model Architecture: PirateNet

PirateNet is a compact CNN→BiGRU model enhanced with temporal attention and a hybrid pooling strategy. It balances high accuracy with computational simplicity.

Key Components:

  1. Conv1D Stem: Extracts local temporal patterns from the raw sequence.
  2. Residual Blocks + SE Units: Dilated residual blocks with Squeeze-and-Excite (SE) units for adaptive multi-scale channel weighting.
  3. Bidirectional GRU (BiGRU): Captures long-range temporal dependencies.
  4. Temporal Attention Layer: Improves temporal credit assignment for short-duration pain bursts.
  5. GRU-Hidden Pooling: A custom mechanism that concatenates mean-pooled sequence features with the final GRU hidden state to capture both global statistics and end-state dynamics.

🛠️ Methodology

1. Feature Engineering & Preprocessing

  • Standardization: Normalization of dynamic sensor channels.
  • Signed-Log Transform: Stabilizes long-tailed sensor values without losing sign information.
  • First-Order Derivatives: Captures the rate of change across time without inflating dimensionality.
  • One-Hot Encoding: Applied to the static categorical variables.

2. Training Strategy

  • Loss Function: Focal Loss ($\gamma = 1.5$) to improve minority-class recall without over-suppressing easy samples.
  • Optimizer: AdamW with a cosine learning-rate schedule and warmup.
  • Regularization: Light jitter, channel-wise scaling, and 5-fold stratified cross-validation. Test-Time Augmentation (TTA=3) was used during inference.

📊 Results

The model was evaluated using the Macro F1 Score to account for the highly imbalanced dataset. PirateNet achieved the following validation metrics:

Metric Score
Accuracy 0.935
Macro F1 0.869
Log Loss 0.267

Per-Class Performance

Class Precision Recall F1-Score
high_pain 0.786 0.786 0.786
low_pain 0.885 0.819 0.851
no_pain 0.959 0.973 0.966

👥 Team: AI: Accidentally Intelligent

About

This repository contains the implementation and technical report for PirateNet, a compact hybrid deep learning architecture designed for multivariate time-series classification.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors