Skip to content

Homework 8

In this homework, we will implement a 1D CNN and train it on sensor data.

Preprocess Dataset and Train Baseline MLP

  1. The Human Activity Recognition Using Smartphones dataset [1] is "built from the recordings of 30 subjects performing activities of daily living (ADL) while carrying a waist-mounted smartphone with embedded inertial sensors." Following the reference, you can download the dataset.
  2. Having unpacked it, you'll see a train directory, in which you can access the train labels as y_train.txt. There is 1 label per row. You can follow the following pattern to read the data from the text file:
    with open(file_path) as f:
        for line in f:
            do_something(line)
    
    Read the labels into a label tensor. Please note that the labels in the text file are 1-indexed and we prefer 0-indexed labels.
  3. You can find body acceleration and rotation sensor data in the train/Inertial Signals subdirectory. These give us 6 feature dimensions. Read the features from the files and stack them into a feature tensor. Following torch convolution convention, stack features so that you end up with a tensor of shape (split_size, feature_dim, timesteps) == (7352, 6, 128).
  4. Perform a train-validation split on the official train split you loaded.
  5. To get a baseline, create an MLP and train it on the flattened dataset with \(6\cdot128\) feature dimensions, using the train_supervised function you wrote in Notebook 0715.

Implement and Train a 1D CNN

  1. Adapt the classes Conv2D and Pool2D you wrote in Notebook 0715 to classes Conv1D and Pool1D that handle data with 1 spatial dimension.
  2. Create a CNN. Use at least 2 convolution layers with "same" padding and an activation function in between. You can use a small model as the dataset is small.
  3. Train your CNN on the original, unflattened dataset, using the train_supervised function.

Dataset Reference

[1] Reyes-Ortiz, Jorge, Davide Anguita, Alessandro Ghio, Luca Oneto, and Xavier Parra. 2013. Human Activity Recognition Using Smartphones. UCI Machine Learning Repository. doi.