Pretraining a vanilla transformer for Human Movement activity classification from Wearable IMU Signals
Inertial sensor signals classified into everyday human activities
Introduction
Recognizing movement from wearable sensors can support human movement research and context-aware applications, but useful models must interpret noisy, multichannel time series and distinguish activities with similar postures. This project investigates whether transformer representations learned from inertial measurement unit (IMU) signals can be transferred to six-class human activity recognition (HAR). Using the UCI Human Activity Recognition dataset, I compared accelerometer (ACC), gyroscope (GYR), and combined ACC+GYR inputs, and evaluated both frozen-feature transfer and encoder fine-tuning.
Methods
The forecasting model learns next-step sensor prediction from fixed-length UCI HAR windows. Each 128-sample window is shifted by one step to form inputs and targets; causal attention masks prevent access to future samples. The documented transformer uses a learned input projection, a six-layer encoder-decoder, eight attention heads, and mean squared error for prediction; it does not add explicit positional encodings.
For movement classification, I transferred the pretrained encoder, retained causal attention, mean-pooled its time-step representations, and attached a linear six-class head. The three modality configurations used matching subject-level train/validation partitions and the official test set. I compared a frozen encoder with a fine-tuned encoder; runs used seed 0, batch size 32, and up to 50 epochs. Macro-F1 was the primary comparison metric to give each activity equal weight.
Results
| Sensor input | Frozen encoder macro-F1 | Fine-tuned encoder macro-F1 |
|---|---|---|
| ACC | 0.5984 | 0.8374 |
| GYR | 0.5090 | 0.6617 |
| ACC + GYR | 0.6361 | 0.8775 |
Fine-tuning improved macro-F1 across all three input configurations in this run. The combined accelerometer and gyroscope model achieved the strongest result, while the gyroscope-only model was lowest. The best run reached 0.8741 accuracy and 0.8775 macro-F1 across 2,947 test windows. These results demonstrate a working, controlled modality comparison and an end-to-end transfer-learning pipeline; without a matched model trained from scratch, they do not establish that pretraining caused the improvement.
The selected run’s learning curves are shown in Figure 1. Figure 2 shows the test confusion matrix, with most remaining errors among sitting, standing, and laying.
Figure 1. Training and validation cross-entropy loss and macro-F1 over 50 epochs for the fine-tuned ACC+GYR model.
Figure 2. Test confusion matrix for the fine-tuned ACC+GYR model.
For comparison, Figures 3 and 4 show the corresponding frozen-encoder linear-probe run.
Figure 3. Training and validation cross-entropy loss and macro-F1 over 50 epochs for the ACC+GYR linear probe with a frozen encoder.
Figure 4. Test confusion matrix for the ACC+GYR linear probe with a frozen encoder.
Figures 5-12 show the ACC-only and GYR-only plots for both transfer modes.
Figure 5. Training history for the ACC-only linear probe with a frozen encoder.
Figure 6. Test confusion matrix for the ACC-only linear probe with a frozen encoder.
Figure 7. Training history for the fine-tuned ACC-only model.
Figure 8. Test confusion matrix for the fine-tuned ACC-only model.
Figure 9. Training history for the GYR-only linear probe with a frozen encoder.
Figure 10. Test confusion matrix for the GYR-only linear probe with a frozen encoder.
Figure 11. Training history for the fine-tuned GYR-only model.
Figure 12. Test confusion matrix for the fine-tuned GYR-only model.
Conclusions
On this UCI HAR experiment, combining acceleration and rotation signals and fine-tuning the pretrained encoder produced the strongest activity-classification result. The work applies sequence modeling, sensor-fusion comparisons, subject-aware evaluation, and transfer learning to a human movement problem. It also shows why aggregate accuracy alone is insufficient: macro-F1 helps expose uneven performance across locomotor and static activities.
Limitations and Future Directions
These are single-seed results on one dataset, not evidence of generalization to new devices, populations, or movement settings. The pretrained models were evaluated on the official test split during pretraining; if those evaluations influenced model or checkpoint choices, the reported test scores are not an untouched final benchmark. Validation subjects' unlabeled sensor signals may also have appeared during pretraining. Most importantly, no matched from-scratch baseline is included, so the contribution of pretraining cannot be isolated.
Next steps are to add a from-scratch baseline under identical splits and optimization settings, repeat runs across seeds, and reserve an untouched test set for final evaluation. Further experiments could compare positional encoding choices, causal versus bidirectional attention for whole-window classification, and performance across independent datasets or participant groups.
References
- Anguita, D., Ghio, A., Oneto, L., Parra, X., and Reyes-Ortiz, J. L. (2013). “A Public Domain Dataset for Human Activity Recognition Using Smartphones.” ESANN 2013.
- Vaswani, A., et al. (2017). “Attention Is All You Need.” Advances in Neural Information Processing Systems.