litchi7777/harbench

3

stars

14

commits

Python

primary language

Jun 30, 2026

updated

README

HARBench

A comprehensive benchmark for evaluating foundation models in sensor-based Human Activity Recognition (HAR).

Leaderboard: https://litchi7777.github.io/harbench/

Requirements

  • Python 3.8+
  • PyTorch 1.12+
  • CUDA 11.x (recommended)

Quick Start (Docker)

# Build image
docker build -t harbench .

# Start container
docker run -dit --gpus all --name harbench harbench bash

# Enter container
docker exec -it harbench bash

# Inside container: preprocess and run benchmark
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download
python run_benchmark.py --model mtl --eval all

Quick Start (Local)

# Create virtual environment
python -m venv .env
source .env/bin/activate

# Install dependencies
pip install torch torchvision torchaudio
pip install -r requirements.txt

# Preprocess all 18 fine-tuning datasets
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download

# Run benchmark
python run_benchmark.py --model mtl --eval all

Using the Feature Extractor (Python API)

Want to turn your own IMU data into feature vectors with a HARBench model, without running the full benchmark pipeline? Install the package and call load_model / encode.

# Install directly from GitHub (bundles the mtl weights)
pip install git+https://github.com/litchi7777/harbench.git
import numpy as np
import harbench

# Load the mtl feature extractor (pretrained weights ship with the package)
model = harbench.load_model("mtl")          # device auto-selects cuda/cpu

# x: windowed IMU data shaped (num_windows, num_sensors * 3, sequence_length)
# The mtl weights were trained on 30 Hz, 5-second windows (sequence_length = 150).
x = np.random.randn(8, 3, 150).astype("float32")

feats = model.encode(x)                      # -> (8, 512) numpy array

Notes:

  • Each sensor contributes 3 channels (x, y, z). For multiple sensors, set num_sensors and stack channels accordingly: harbench.load_model("mtl", num_sensors=2) expects (N, 6, 150) and returns (N, 1024).
  • encode accepts numpy arrays or torch tensors and returns the same type. Use encode(x, batch_size=256) to process large inputs in chunks.
  • harbench.available_models() lists the models exposed through this API.

Project Structure

har-bench2/
├── finetune.py          # Fine-tuning and evaluation
├── pretrain.py          # Self-supervised pretraining
├── run_benchmark.py     # Full benchmark runner
├── src/
│   ├── data/            # Data loading utilities
│   └── models/          # Model definitions
├── pretrained/          # Pretrained weights
│   ├── mtl.pth          # (included)
│   ├── simclr.pth       # (included)
│   ├── moco.pth         # (included)
│   ├── cpc.pth          # (included)
│   ├── timemask.pth     # (included)
│   ├── timechannel.pth  # (included)
│   ├── limubert.pt.url  # (download separately)
│   ├── imumae.pth.url   # (download separately)
│   └── selfpab.ckpt.url # (download separately)
├── har-datasets/        # Dataset preprocessors
└── results/             # Experiment results

Supported Models (13 total)

ModelTypeDescriptionWeights
resnetBaseline1D ResNet (random init)-
mtlSSLMulti-Task LearningIncluded
simclrSSLSimCLRIncluded
mocoSSLMoCoIncluded
timechannelSSLMasked Resnet (time+channel)Included
timemaskSSLMasked Resnet (time only)Included
cpcSSLContrastive Predictive CodingIncluded
harnetPretrainedOxWearables HARNetAuto-download
selfpabTransformerSelfPAB (STFT + Transformer)Download required
limubertTransformerLIMU-BERTDownload required
imumaeTransformerIMU-Video-MAE (ECCV 2024)Download required
patchtstFoundationPatchTSTAuto-download
momentFoundationMOMENTAuto-download

Data Preparation

Preprocessing Datasets

# List available datasets
python preprocess.py --list

# Preprocess a single dataset with auto-download
python preprocess.py --dataset dsads --download

# Preprocess all 18 fine-tuning datasets
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download

# Preprocess all 14 pretraining datasets (excluding NHANES)
python preprocess.py --dataset adlrd chad capture24 dog har70plus hhar imsb kddi_kitchen_left kddi_kitchen_right motionsense opportunity sbrhapt tmd wisdm --download

# NHANES is very large and takes a long time to process - run separately
python preprocess.py --dataset nhanes --download

Processed data will be saved to har-datasets/data/processed/{dataset}/

Supported Datasets

Fine-tuning Datasets (18)

DatasetSensorsClassesDomain
DSADS519Exercise
PAMAP2318 (12)Daily
MHEALTH312Exercise
RealDisp933Exercise
MEX27Exercise
Forthtrace516 (11)Daily
HARTH212 (10)Daily
IMWSHA311Daily
PAAL124 (10)Daily
RealWorld78Daily
SelfBack29Daily
UCAEHAR18 (6)Daily
USC-HAD112Daily
WARD513Daily
LARa58 (6)Industry
OpenPack410 (9)Industry
Exoskeletons54Industry
VTT-ConIoT316Industry

Pretraining Datasets (14)

DatasetSensorsDescription
NHANES1Large-scale (~13K subjects)
Capture-241Large-scale (151 subjects)
ADLRD1Daily activities
CHAD1Daily activities
Dog3Animal activity
HAR70+2Elderly activities
HHAR7Device heterogeneity
IMSB2Daily activities
KDDI-Kitchen1Kitchen activities
MotionSense1Daily activities
Opportunity7Daily activities
SBR-HAPT1Daily activities
TMD1Transportation
WISDM2Daily activities

Usage

Running Benchmark

Run comprehensive evaluation across multiple datasets:

# Run all evaluations for a model
python run_benchmark.py --model mtl --eval all

# Run specific evaluation types
python run_benchmark.py --model mtl --eval average    # Average performance
python run_benchmark.py --model mtl --eval domain     # Cross-domain evaluation
python run_benchmark.py --model mtl --eval position   # Sensor position evaluation
python run_benchmark.py --model mtl --eval fewshot    # Few-shot learning
python run_benchmark.py --model mtl --eval zeroshot   # Zero-shot evaluation

# Run on specific datasets
python run_benchmark.py --model mtl --datasets dsads pamap2 mhealth

# Multi-GPU parallel execution
python run_benchmark.py --model mtl --num_gpus 4 --parallel 2

Results will be saved to results/benchmark/.

Fine-tuning (Single Run)

python finetune.py --model mtl --dataset dsads --sensors LeftArm --epochs 50

Pretraining

Train your own SSL models:

python pretrain.py --method mtl --device cuda:0

External Model Weights

Some models require downloading weights from external sources:

ModelSourceInstructions
limubertLIMU-BERTDownload and place as pretrained/limubert.pt
imumaeIMU-Video-MAEDownload and place as pretrained/imumae.pth
selfpabSelfPABDownload and place as pretrained/selfpab.ckpt

See .url files in pretrained/ for download links.

Citation

@inproceedings{harbench2026,
  title={HARBench: A Comprehensive Benchmark for Evaluating Foundation Models in Sensor-based Human Activity Recognition},
  author={Tanigaki, Kei and Maekawa, Takuya and Hara, Takahiro},
  booktitle={2026 IEEE International Conference on Pervasive Computing and Communications (PerCom)},
  year={2026}
}

Contributors

litchi7777

14 commits

litchi7777/harbench

3

stars

14

commits

Python

primary language

Jun 30, 2026

updated

README

HARBench

A comprehensive benchmark for evaluating foundation models in sensor-based Human Activity Recognition (HAR).

Leaderboard: https://litchi7777.github.io/harbench/

Requirements

  • Python 3.8+
  • PyTorch 1.12+
  • CUDA 11.x (recommended)

Quick Start (Docker)

# Build image
docker build -t harbench .

# Start container
docker run -dit --gpus all --name harbench harbench bash

# Enter container
docker exec -it harbench bash

# Inside container: preprocess and run benchmark
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download
python run_benchmark.py --model mtl --eval all

Quick Start (Local)

# Create virtual environment
python -m venv .env
source .env/bin/activate

# Install dependencies
pip install torch torchvision torchaudio
pip install -r requirements.txt

# Preprocess all 18 fine-tuning datasets
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download

# Run benchmark
python run_benchmark.py --model mtl --eval all

Using the Feature Extractor (Python API)

Want to turn your own IMU data into feature vectors with a HARBench model, without running the full benchmark pipeline? Install the package and call load_model / encode.

# Install directly from GitHub (bundles the mtl weights)
pip install git+https://github.com/litchi7777/harbench.git
import numpy as np
import harbench

# Load the mtl feature extractor (pretrained weights ship with the package)
model = harbench.load_model("mtl")          # device auto-selects cuda/cpu

# x: windowed IMU data shaped (num_windows, num_sensors * 3, sequence_length)
# The mtl weights were trained on 30 Hz, 5-second windows (sequence_length = 150).
x = np.random.randn(8, 3, 150).astype("float32")

feats = model.encode(x)                      # -> (8, 512) numpy array

Notes:

  • Each sensor contributes 3 channels (x, y, z). For multiple sensors, set num_sensors and stack channels accordingly: harbench.load_model("mtl", num_sensors=2) expects (N, 6, 150) and returns (N, 1024).
  • encode accepts numpy arrays or torch tensors and returns the same type. Use encode(x, batch_size=256) to process large inputs in chunks.
  • harbench.available_models() lists the models exposed through this API.

Project Structure

har-bench2/
├── finetune.py          # Fine-tuning and evaluation
├── pretrain.py          # Self-supervised pretraining
├── run_benchmark.py     # Full benchmark runner
├── src/
│   ├── data/            # Data loading utilities
│   └── models/          # Model definitions
├── pretrained/          # Pretrained weights
│   ├── mtl.pth          # (included)
│   ├── simclr.pth       # (included)
│   ├── moco.pth         # (included)
│   ├── cpc.pth          # (included)
│   ├── timemask.pth     # (included)
│   ├── timechannel.pth  # (included)
│   ├── limubert.pt.url  # (download separately)
│   ├── imumae.pth.url   # (download separately)
│   └── selfpab.ckpt.url # (download separately)
├── har-datasets/        # Dataset preprocessors
└── results/             # Experiment results

Supported Models (13 total)

ModelTypeDescriptionWeights
resnetBaseline1D ResNet (random init)-
mtlSSLMulti-Task LearningIncluded
simclrSSLSimCLRIncluded
mocoSSLMoCoIncluded
timechannelSSLMasked Resnet (time+channel)Included
timemaskSSLMasked Resnet (time only)Included
cpcSSLContrastive Predictive CodingIncluded
harnetPretrainedOxWearables HARNetAuto-download
selfpabTransformerSelfPAB (STFT + Transformer)Download required
limubertTransformerLIMU-BERTDownload required
imumaeTransformerIMU-Video-MAE (ECCV 2024)Download required
patchtstFoundationPatchTSTAuto-download
momentFoundationMOMENTAuto-download

Data Preparation

Preprocessing Datasets

# List available datasets
python preprocess.py --list

# Preprocess a single dataset with auto-download
python preprocess.py --dataset dsads --download

# Preprocess all 18 fine-tuning datasets
python preprocess.py --dataset dsads pamap2 mhealth realdisp mex forthtrace harth imwsha paal realworld selfback ucaehar uschad ward lara openpack exoskeletons vtt_coniot --download

# Preprocess all 14 pretraining datasets (excluding NHANES)
python preprocess.py --dataset adlrd chad capture24 dog har70plus hhar imsb kddi_kitchen_left kddi_kitchen_right motionsense opportunity sbrhapt tmd wisdm --download

# NHANES is very large and takes a long time to process - run separately
python preprocess.py --dataset nhanes --download

Processed data will be saved to har-datasets/data/processed/{dataset}/

Supported Datasets

Fine-tuning Datasets (18)

DatasetSensorsClassesDomain
DSADS519Exercise
PAMAP2318 (12)Daily
MHEALTH312Exercise
RealDisp933Exercise
MEX27Exercise
Forthtrace516 (11)Daily
HARTH212 (10)Daily
IMWSHA311Daily
PAAL124 (10)Daily
RealWorld78Daily
SelfBack29Daily
UCAEHAR18 (6)Daily
USC-HAD112Daily
WARD513Daily
LARa58 (6)Industry
OpenPack410 (9)Industry
Exoskeletons54Industry
VTT-ConIoT316Industry

Pretraining Datasets (14)

DatasetSensorsDescription
NHANES1Large-scale (~13K subjects)
Capture-241Large-scale (151 subjects)
ADLRD1Daily activities
CHAD1Daily activities
Dog3Animal activity
HAR70+2Elderly activities
HHAR7Device heterogeneity
IMSB2Daily activities
KDDI-Kitchen1Kitchen activities
MotionSense1Daily activities
Opportunity7Daily activities
SBR-HAPT1Daily activities
TMD1Transportation
WISDM2Daily activities

Usage

Running Benchmark

Run comprehensive evaluation across multiple datasets:

# Run all evaluations for a model
python run_benchmark.py --model mtl --eval all

# Run specific evaluation types
python run_benchmark.py --model mtl --eval average    # Average performance
python run_benchmark.py --model mtl --eval domain     # Cross-domain evaluation
python run_benchmark.py --model mtl --eval position   # Sensor position evaluation
python run_benchmark.py --model mtl --eval fewshot    # Few-shot learning
python run_benchmark.py --model mtl --eval zeroshot   # Zero-shot evaluation

# Run on specific datasets
python run_benchmark.py --model mtl --datasets dsads pamap2 mhealth

# Multi-GPU parallel execution
python run_benchmark.py --model mtl --num_gpus 4 --parallel 2

Results will be saved to results/benchmark/.

Fine-tuning (Single Run)

python finetune.py --model mtl --dataset dsads --sensors LeftArm --epochs 50

Pretraining

Train your own SSL models:

python pretrain.py --method mtl --device cuda:0

External Model Weights

Some models require downloading weights from external sources:

ModelSourceInstructions
limubertLIMU-BERTDownload and place as pretrained/limubert.pt
imumaeIMU-Video-MAEDownload and place as pretrained/imumae.pth
selfpabSelfPABDownload and place as pretrained/selfpab.ckpt

See .url files in pretrained/ for download links.

Citation

@inproceedings{harbench2026,
  title={HARBench: A Comprehensive Benchmark for Evaluating Foundation Models in Sensor-based Human Activity Recognition},
  author={Tanigaki, Kei and Maekawa, Takuya and Hara, Takahiro},
  booktitle={2026 IEEE International Conference on Pervasive Computing and Communications (PerCom)},
  year={2026}
}

Contributors

litchi7777

14 commits

Languages

Python

99.9%