<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Temporal Convolutional Networks | Sina Mehdizadeh, PhD</title><link>https://sinamehdiz.com/tag/temporal-convolutional-networks/</link><atom:link href="https://sinamehdiz.com/tag/temporal-convolutional-networks/index.xml" rel="self" type="application/rss+xml"/><description>Temporal Convolutional Networks</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Sat, 13 Sep 2025 00:00:00 +0000</lastBuildDate><image><url>https://sinamehdiz.com/images/icon_hu0b7a4cb9992c9ac0e91bd28ffd38dd00_9727_512x512_fill_lanczos_center_3.png</url><title>Temporal Convolutional Networks</title><link>https://sinamehdiz.com/tag/temporal-convolutional-networks/</link></image><item><title>Causal Temporal Convolutions for Human Activity Classification</title><link>https://sinamehdiz.com/project/imu-tcn/</link><pubDate>Sat, 13 Sep 2025 00:00:00 +0000</pubDate><guid>https://sinamehdiz.com/project/imu-tcn/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>Wearable inertial sensors provide continuous signals that can distinguish movement, but robust activity recognition requires models to capture temporal structure across multiple channels. This study explores a two-stage transfer-learning pipeline: first learn from unlabeled sensor sequences through next-sample prediction, then reuse the temporal representation to classify human activities. The experiments compare a frozen-feature linear probe with end-to-end fine-tuning on the UCI Human Activity Recognition (HAR) dataset.&lt;/p>
&lt;h2 id="methods">Methods&lt;/h2>
&lt;p>The data contain six channels: three body-gyroscope axes and three body-acceleration axes. Each UCI HAR window has 128 readings sampled at 50 Hz, spans 2.56 seconds, and overlaps adjacent windows by 50%. Channels are standardized using training-set statistics. For pretraining, each window is shifted by one sample: the first 127 readings predict the following 127 targets. The causal temporal convolutional network (TCN) uses two residual blocks with kernel size 3, dilations 1 and 2, eight hidden channels, and dropout. Its encoder has a 13-sample receptive field; a pointwise prediction head maps features back to the six sensor channels. The predictor is trained with mean squared error and Adam.&lt;/p>
&lt;p>For classification, the pretrained encoder processes the first 127 readings. Mean pooling aggregates its temporal features, and a linear head predicts one of six activities: walking, walking upstairs, walking downstairs, sitting, standing, or laying. In probe mode, encoder weights are frozen; in fine-tuning mode, the encoder and head are optimized with separate learning rates. Both reported runs used 20 epochs, with a head learning rate of 0.01 and, for fine-tuning, an encoder learning rate of 0.001. Evaluation uses subject-separated training and validation partitions and the official test set. Macro-F1 is reported alongside accuracy.&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Transfer mode&lt;/th>
&lt;th style="text-align:right">Test accuracy&lt;/th>
&lt;th style="text-align:right">Test macro-F1&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Frozen encoder + linear probe&lt;/td>
&lt;td style="text-align:right">46.1%&lt;/td>
&lt;td style="text-align:right">0.3968&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Fine-tuned encoder + linear head&lt;/td>
&lt;td style="text-align:right">&lt;strong>77.5%&lt;/strong>&lt;/td>
&lt;td style="text-align:right">&lt;strong>0.7801&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The fine-tuned run scored higher than the frozen probe on both metrics in this comparison. Its strongest class F1 scores were for walking (0.981), walking downstairs (0.949), and walking upstairs (0.943); sitting remained more difficult (0.457). Scores are from the final epoch on 2,947 test windows. With one recorded run per mode and no matched randomly initialized baseline, these outcomes are preliminary and do not isolate the benefit of pretraining.&lt;/p>
&lt;p>Figures 1 and 2 show the frozen-probe training curves and test confusion matrix. Figures 3 and 4 show the corresponding fine-tuned results.&lt;/p>
&lt;p>&lt;img src="./tcn_probe_history.png" alt="Training and validation cross-entropy loss and macro-F1 for the frozen-encoder TCN probe.">
&lt;em>Figure 1. Training and validation cross-entropy loss and macro-F1 over 20 epochs for the frozen-encoder probe.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_probe_confusion.png" alt="Test confusion matrix for the frozen-encoder TCN probe.">
&lt;em>Figure 2. Test confusion matrix for the frozen-encoder probe.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_finetune_history.png" alt="Training and validation cross-entropy loss and macro-F1 for the fine-tuned TCN.">
&lt;em>Figure 3. Training and validation cross-entropy loss and macro-F1 over 20 epochs for the fine-tuned model.&lt;/em>&lt;/p>
&lt;p>&lt;img src="./tcn_finetune_confusion.png" alt="Test confusion matrix for the fine-tuned TCN.">
&lt;em>Figure 4. Test confusion matrix for the fine-tuned model.&lt;/em>&lt;/p>
&lt;h2 id="conclusions">Conclusions&lt;/h2>
&lt;p>This TCN pipeline demonstrates how causal convolutions can learn local temporal features from multichannel inertial data and how those features can be transferred to activity classification. In the two recorded runs, fine-tuning substantially outperformed using the pretrained encoder as a frozen feature extractor. The per-class results also show that strong recognition of locomotor activities does not guarantee equally strong recognition of static postures.&lt;/p>
&lt;h2 id="limitations-and-future-directions">Limitations and Future Directions&lt;/h2>
&lt;p>The comparison contains one run per transfer mode, reports the final epoch rather than a validation-selected checkpoint, and has no fully supervised from-scratch baseline. The encoder&amp;rsquo;s 13-sample receptive field is short relative to a full activity window, and mean pooling does not explicitly preserve global temporal order. In addition, validation subjects' unlabeled signals contributed to pretraining and scaler fitting. The predictor was evaluated on the official test split during pretraining; if those scores influenced model choices, the test set is not an untouched benchmark.&lt;/p>
&lt;p>Next steps are to repeat experiments across controlled random seeds, select checkpoints using validation data, compare against a matched model trained from random initialization, and hold validation subjects out before pretraining and normalization. Expanding the receptive field and comparing pooling strategies could test how longer-term temporal context affects static and transitional activities. Final claims should use a test set that has not informed model or hyperparameter decisions.&lt;/p>
&lt;h2 id="references">References&lt;/h2>
&lt;ol>
&lt;li>Anguita, D., Ghio, A., Oneto, L., Parra, X., and Reyes-Ortiz, J. L. (2013). “A Public Domain Dataset for Human Activity Recognition Using Smartphones.” &lt;em>ESANN 2013&lt;/em>.&lt;/li>
&lt;li>Bai, S., Kolter, J. Z., and Koltun, V. (2018). “An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling.”&lt;/li>
&lt;li>Project materials: &lt;a href="tcn_imu_classification_description.md">TCN study description&lt;/a>, &lt;a href="TCN_IMU.py">TCN implementation&lt;/a>, &lt;a href="tcn_classification.py">classification implementation&lt;/a>, and &lt;a href="../tcn_classification_results/comparison.md">recorded classification results&lt;/a>.&lt;/li>
&lt;/ol></description></item></channel></rss>