Homework 8
In this homework, we will implement a 1D CNN and train it on sensor data.
Preprocess Dataset and Train Baseline MLP
- 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.
- Having unpacked it, you'll see a
traindirectory, in which you can access the train labels asy_train.txt. There is 1 label per row. You can follow the following pattern to read the data from the text file: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.with open(file_path) as f: for line in f: do_something(line) - You can find body acceleration and rotation sensor data in the
train/Inertial Signalssubdirectory. These give us 6 feature dimensions. Read the features from the files and stack them into a feature tensor. Followingtorchconvolution convention, stack features so that you end up with a tensor of shape(split_size, feature_dim, timesteps) == (7352, 6, 128). - Perform a train-validation split on the official train split you loaded.
- To get a baseline, create an MLP and train it on the flattened dataset with \(6\cdot128\) feature dimensions, using the
train_supervisedfunction you wrote in Notebook 0715.
Implement and Train a 1D CNN
- Adapt the classes
Conv2DandPool2Dyou wrote in Notebook 0715 to classesConv1DandPool1Dthat handle data with 1 spatial dimension. - 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. - Train your CNN on the original, unflattened dataset, using the
train_supervisedfunction.
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.