Human Activity Recognition from Wearable Sensor Data Using Self-Attention

Saif Mahmud, M Tanjid Hasan Tonmoy, Kishor Kumar Bhaumik, A K M Mahbubur Rahman, M Ashraful Amin, Mohammad Shoyaib, Muhammad Asif Hossain Khan, Amin Ahsan AliarXiv 2020

TL;DR

This paper introduces a purely attention-based, non-recurrent neural network architecture for Human Activity Recognition (HAR) using wearable sensor data. By replacing traditional recurrent layers with multi-headed self-attention and sensor modality attention, the model achieves state-of-the-art performance across multiple benchmarks while offering highly interpretable attention maps that reveal which sensors matter most for specific activities.

What Problem Does This Paper Address?

Human Activity Recognition (HAR) relies on time-series data from body-worn sensors (like accelerometers and gyroscopes) to automatically classify actions such as walking, cycling, or ironing. Capturing both spatial context (which sensor on which body part is moving) and temporal context (how the signal evolves over time) is notoriously difficult due to noisy signals, sensor displacement, and variations in how different individuals perform the same task.

While deep learning models like Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs, such as LSTMs) have improved HAR, they have distinct limitations. CNNs struggle with long-range temporal dependencies, while RNNs are constrained by sequential processing bottlenecks and struggle to capture complex context from all possible feature combinations. The authors address this gap by adapting the Transformer architecture—originally designed for natural language processing—to handle multi-modal time-series sensor data without relying on any recurrent layers.

Methods

The authors propose an end-to-end neural network architecture that treats sensor data samples analogously to words, and time windows analogously to sentences.

The pipeline consists of the following key stages:

  1. Sensor Modality Attention: The raw multi-channel sensor input is first processed using 2D convolutions and a sensor-wise softmax function. This layer learns to weight the relative importance of each sensor modality and body placement before any temporal processing occurs.
  2. Sensor Feature Transformation & Positional Encoding: A 1D convolution maps the weighted sensor values into a $d$-dimensional feature space. Since the model lacks recurrence, sine and cosine-based positional encodings are added to preserve the temporal order of the sequence.
  3. Multi-Headed Self-Attention Blocks: The core of the model consists of stacked self-attention layers. These layers compute query, key, and value vectors to determine the relative correlation between different timesteps in the window, allowing the model to capture global context in parallel.
  4. Global Temporal Attention: This layer ranks the timesteps based on their relevance to the final classification task, creating a weighted average representation of the entire activity window.
  5. Classification: A final fully connected layer with a softmax activation outputs the activity class labels.
Figure 1: Attention based model incorporating self-attention and global temporal attention

Datasets

The model was evaluated on four popular, publicly available HAR benchmark datasets:

  • PAMAP2: Contains data from 9 subjects wearing 3 Inertial Measurement Units (IMUs) on the wrist, chest, and ankle performing 18 activities.
  • OPPORTUNITY: A highly imbalanced dataset featuring body-worn and ambient sensors capturing mid-level gestures and modes of locomotion.
  • USC-HAD: Features 14 subjects performing 12 daily activities with a single motion node attached to the right hip.
  • Skoda: Focuses on car manufacturing assembly-line scenarios, tracking workers using 10 accelerometers placed along their arms.

Key Insights and Ideas

  • Recurrence is Unnecessary for HAR: The paper demonstrates that self-attention mechanisms alone can capture spatio-temporal dependencies in time-series data more effectively than recurrent architectures like LSTMs or GRUs.
  • Built-in Interpretability: The sensor modality attention layer acts as an intuitive feature-selection mechanism. By plotting the learned attention weights, the authors show that the model naturally focuses on the correct body parts for specific tasks—for instance, heavily prioritizing hand sensors for "ironing" or "vacuum cleaning," and chest/ankle sensors for "ascending stairs."
  • Resilience to Window Size: Traditional recurrent models are highly sensitive to the choice of sliding window size. The self-attention mechanism proves much more robust, maintaining stable performance even as the time window scales up to several seconds.

Key Results

The proposed model was evaluated using the Macro F1-score to account for class imbalances and compared against standard baselines like DeepConvLSTM and Convolutional Autoencoders (ConvAE).

  • Benchmark Test Subjects: The model achieved significant performance gains in window-wise classification, scoring 0.96 on PAMAP2 (vs. 0.70 for DeepConvLSTM), 0.67 on Opportunity (vs. 0.58), and 0.55 on USC-HAD (vs. 0.38).
  • Leave-One-Subject-Out Cross-Validation (LOSO-CV): To test generalization, the authors evaluated the model on unseen subjects. The proposed model consistently outperformed baselines, showing particular strength on underrepresented demographics in the training data (e.g., achieving an F1-score of 0.98 on a female subject where DeepConvLSTM scored just 0.33).
Performance measure against different window sizes across datasets

Limitations and Future Work

The authors note a few limitations in their current evaluation framework. Specifically, while they compared their model against older baselines using both sample-wise and window-wise metrics, they were only able to compare against recently published attention-based models (like AttnSense) using sample-wise metrics due to data availability in prior literature.

For future work, the authors plan to extend this architecture by introducing a decoder network to explore sequence-to-sequence generation tasks within wearable computing and conduct broader comparative studies.

Summary updated

BibTeX
@misc{mahmud2020human,
  author = {Saif Mahmud and M Tanjid Hasan Tonmoy and Kishor Kumar Bhaumik and A K M Mahbubur Rahman and M Ashraful Amin and Mohammad Shoyaib and Muhammad Asif Hossain Khan and Amin Ahsan Ali},
  title = {{Human Activity Recognition from Wearable Sensor Data Using Self-Attention}},
  year = {2020},
  eprint = {2003.09018},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.09018},
}
Figure