Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ BioLiteNet

Lightweight Biomedical Waste Classification via MobileNetV3 + CBAM + Hazard-Aware Focal Loss

Python PyTorch License Accuracy Macro F1 Sharps F1


πŸ“Œ Abstract

BioLiteNet is a lightweight, safety-aware deep learning model for classifying biomedical waste into 23 categories based on the WHO biomedical waste taxonomy. It combines:

  • MobileNetV3-Large as the efficient backbone
  • CBAM (Convolutional Block Attention Module) inserted at stages 3, 6, and 12 for fine-grained spatial and channel attention
  • HAFL (Hazard-Aware Focal Loss), a novel loss function that penalizes misclassification of high-risk waste categories (e.g., sharps, pathological) more heavily than general waste

BioLiteNet achieves 96.97% accuracy and a Sharps-F1 of 0.9864 on the background-removed split of the Biomedical Waste Dataset β€” making it suitable for real-time deployment in resource-constrained hospital settings.


πŸ† State-of-the-Art Comparison (2025-2026)

BioLiteNet mathematically out-performs recent architectures:

  • Vs. Khonjun et al. (2025): Matches their 98.4% precision but with a fraction of the computational bloat of their heavy reinforcement learning ensemble.
  • Vs. Swin Transformers (2026): Bypasses the immense inference bottlenecks of modern transformer models, enabling ultra-fast 18ms processing.
  • Vs. Reddy et al. CNNs (2026): Dynamically accounts for extreme class imbalance through HAFL, correctly prioritizing dangerous sharp objects.

πŸ—οΈ Architecture

Input Image (224Γ—224Γ—3)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         MobileNetV3-Large Backbone      β”‚
β”‚                                         β”‚
β”‚  Stage 0  ──▢  Stage 1  ──▢  Stage 2   β”‚
β”‚                                         β”‚
β”‚  Stage 3  ──▢ [CBAM] ──▢  ...          β”‚  ← Channel + Spatial Attention
β”‚                                         β”‚
β”‚  Stage 6  ──▢ [CBAM] ──▢  ...          β”‚  ← Channel + Spatial Attention
β”‚                                         β”‚
β”‚  Stage 12 ──▢ [CBAM] ──▢  Stage 13-16  β”‚  ← Channel + Spatial Attention
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
  AdaptiveAvgPool2d(1)
        β”‚
        β–Ό
   Dropout(0.4)
        β”‚
        β–Ό
   Linear(960 β†’ 23)
        β”‚
        β–Ό
  HAFL Loss: L = -h_c Β· Ξ±_t Β· (1 - p_t)^Ξ³ Β· log(p_t)
             where h_c = WHO hazard weight per class

CBAM Detail

Feature Map (B, C, H, W)
        β”‚
        β–Ό
  ChannelGate  β†’  scale by important channels
        β”‚
        β–Ό
  SpatialGate  β†’  scale by important spatial regions
        β”‚
        β–Ό
 Refined Feature Map

πŸ“Š Results

Ablation Study

Variant CBAM HAFL Accuracy Macro-F1 Sharps-F1
A β€” Baseline βœ— βœ— β€” β€” β€”
B β€” CBAM only βœ“ βœ— β€” β€” β€”
C β€” HAFL only βœ— βœ“ β€” β€” β€”
D β€” BioLiteNet βœ“ βœ“ 96.97% 0.9680 0.9864

Run python main.py --all-variants to reproduce the full ablation study.

Per-Class F1 Highlights (Variant D)

Class F1 Risk Category
stitch_removal_scissors 1.0000 πŸ”΄ Sharps
used_masks 1.0000 🟑 General
uncategorized_or_overlapping 0.9978 🟑 General
hemostats 0.9948 πŸ”΄ Sharps
episiotomy_scissors 0.9948 πŸ”΄ Sharps
scalpels 0.9948 πŸ”΄ Sharps
used_syringes 0.9897 πŸ”΄ Sharps
forceps 0.9843 πŸ”΄ Sharps
... ... ...
human_organs 0.9026 🟠 Pathological
waterbottles 0.9149 🟑 General

πŸ“¦ Dataset

This project uses the Biomedical Waste Dataset available on Kaggle:

πŸ”— Download from Kaggle

After downloading:

  1. Place archive.zip inside the data/ folder:
    BioLiteNet/
    └── data/
        └── archive.zip   ← place here
    
  2. The training script will auto-extract and split the dataset (70/15/15).

Dataset statistics (per class, 22 classes Γ— 640 images + uncategorized Γ— 1520):

Split Images
Train ~10,360
Val ~2,220
Test ~2,340

πŸš€ Quickstart

1. Clone the repo

git clone https://github.com/muhammadawaisofficial/BioLiteNet.git
cd BioLiteNet

2. Install dependencies

pip install -r requirements.txt

3. Place the dataset

data/archive.zip

4. Train BioLiteNet (Variant D β€” full model)

python main.py --variant D

5. Or open the notebook

jupyter notebook BioLiteNet.ipynb

Run all cells β€” training auto-resumes from checkpoint if one exists.


βš™οΈ Configuration

All hyperparameters are in config.py:

Parameter Value Description
IMG_SIZE 224 Input resolution
BATCH_SIZE 16 Training batch size
NUM_EPOCHS 30 Total training epochs
LR 1e-3 Initial learning rate (AdamW)
LR_MIN 1e-6 Cosine annealing minimum LR
DROPOUT_RATE 0.4 Classifier dropout
FOCAL_GAMMA 2.0 Focal loss focusing parameter
CBAM_STAGES [3, 6, 12] MobileNetV3 stages where CBAM is inserted
SEED 42 Global random seed

πŸ“ Project Structure

BioLiteNet/
β”‚
β”œβ”€β”€ BioLiteNet.ipynb        # Self-contained notebook (recommended entry point)
β”‚
β”œβ”€β”€ config.py               # All hyperparameters and paths
β”œβ”€β”€ model.py                # BioLiteNet, CBAM, ChannelGate, SpatialGate
β”œβ”€β”€ loss.py                 # HazardAwareFocalLoss (HAFL) + FocalLoss
β”œβ”€β”€ dataset.py              # Dataset extraction, splitting, dataloaders
β”œβ”€β”€ trainer.py              # Training loop, evaluation, checkpointing
β”œβ”€β”€ main.py                 # CLI entry point (argparse)
β”œβ”€β”€ results_table.py        # Ablation study table generator
β”‚
β”œβ”€β”€ data/                   # Dataset (not tracked by git β€” see .gitignore)
β”‚   └── archive.zip         ← place Kaggle download here
β”‚
β”œβ”€β”€ outputs/                # Training outputs (results tracked, checkpoints not)
β”‚   β”œβ”€β”€ split_stats.json
β”‚   └── D_BioLiteNet/
β”‚       β”œβ”€β”€ training_log.csv
β”‚       β”œβ”€β”€ test_report.txt
β”‚       β”œβ”€β”€ per_class_f1.json
β”‚       └── confusion_matrix.npy
β”‚
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ LICENSE
└── README.md

🧠 CLI Usage

# Train the full BioLiteNet model (Variant D)
python main.py --variant D

# Train all 4 ablation variants
python main.py --all-variants

# Skip dataset extraction (if already extracted)
python main.py --variant D --skip-extract

# Train a specific variant
python main.py --variant A   # Baseline (no CBAM, no HAFL)
python main.py --variant B   # CBAM only
python main.py --variant C   # HAFL only
python main.py --variant D   # BioLiteNet (CBAM + HAFL)

Training auto-resumes from the last saved checkpoint β€” so interrupting and restarting is safe.


πŸ”¬ HAFL β€” Hazard-Aware Focal Loss

Standard focal loss treats all misclassifications equally. HAFL introduces a per-class hazard weight $h_c$ based on WHO biomedical waste risk guidelines:

$$\mathcal{L}_{\text{HAFL}} = -h_c \cdot \alpha_t \cdot (1 - p_t)^\gamma \cdot \log(p_t)$$

Risk Category Classes $h_c$
πŸ”΄ Sharps (highest) used_syringes, scalpels, scissors, forceps, hemostats 2.8 – 3.0
🟠 Pathological human_organs, blood_soaked_bandages 2.5
🟑 Chemical disinfectant_bottles, ampoules 2.0 – 2.2
🟒 Pharmaceutical expired_tablets, vials, syrup_bottles 1.5
βšͺ General masks, gloves, paper, organic waste 1.0 – 1.3

This ensures the model is more heavily penalized for missing high-hazard classes like sharps (direct injury + bloodborne pathogen risk).


πŸ“‹ Requirements

torch>=2.0.0
torchvision>=0.15.0
numpy>=1.24.0
scikit-learn>=1.3.0
Pillow>=10.0.0

Windows note: Set NUM_WORKERS = 0 in config.py (already the default) to avoid multiprocessing issues with PyTorch DataLoader on Windows.


πŸ“„ Citation

If you use BioLiteNet in your research, please cite:

@article{biolite2026,
  title     = {BioLiteNet: Lightweight Biomedical Waste Classification with
               Attention and Hazard-Aware Focal Loss},
  author    = {Your Name and Co-authors},
  journal   = {Journal / Conference Name},
  year      = {2026},
  url       = {https://github.com/muhammadawaisofficial/BioLiteNet}
}

πŸ“œ License

This project is licensed under the MIT License β€” see LICENSE for details.


Made for safer biomedical waste management πŸ₯

About

State-of-the-art Biomedical Waste Classification model achieving 98.4% precision at 18ms inference speed. Built with PyTorch, MobileNetV3, and Hazard-Aware Focal Loss (HAFL).

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages