Human Activity Recognition App using deepC and cAInvas

Photo by Irfan Ahmed Khan on Hackernoon

Humans are bound to perform certain activities like walking, sleeping, running, sitting, etc. in their daily life. What if I say, humans can now perform as well as keep a track of what activities they are performing in real-time!

Interesting??

Well, in this article I will show how to build your own Human Activity Recognition App that detects 6 activities namely walking, walking_downstairs, walking_upstairs, laying, standing, and sitting using deepC and cAInvas.

Getting Started

In this notebook, the human activity recognition dataset having records of acceleration and angular velocity measurements from different physical aspects in all three spatial dimensions (X, Y, Z) is used to train a machine and predict the activity from one of the six activities performed.

The train dataset contains 7352 records and 563 variables, whereas the test dataset has 2947 records and 563 variables.

https://gist.github.com/Sanlap1997/f72162fdbbd4af03e6c1e8cb150f70ce

To start with, let’s do some exploratory analysis in hope of understanding various measures and their effect on the activities.

Exploratory Analysis

The Dataset to be used is available here!

The data has 7352 observations with 563 variables with the first few columns representing the mean and standard deviations of body accelerations in 3 spatial dimensions (X, Y, Z). The last two columns are “subject” and “Activity” which represent the subject that the observation is taken from and the corresponding activity respectively. Let’s see what activities have been recorded in this data.

https://gist.github.com/Sanlap1997/06ca1d17dcf88a88ae4772e91abf1a73

Each observation in the dataset represents one of the six activities whose features are recorded in the 561 variables. Our goal would be to train a machine to predict one of the six activities given a feature set of these 561 variables.

Building the model

We have used two fully connected layers with relu activation and softmax activation respectively, of which one layer consists of 30 neurons, whereas the other one has 6 neurons only.

https://gist.github.com/Sanlap1997/575ce74af25ff0874a4140ca39d7635d

Testing the model

At this stage, we would train the Neural network for 25 Epochs with early stopping, monitoring the validation loss with the patience of 10.

https://gist.github.com/Sanlap1997/1b42a1bf0735eaf9d47e0c4f2a8e95be

The loss function specially used in this model is ‘categorical_crossentropy’ with an Adam optimizer having a learning rate = 0.001

Model Summary

Finally, the validation accuracy obtained after testing our model is 94.27% approx.

https://gist.github.com/Sanlap1997/fd73ee1edf1de14457c6ec32d3279d0d

Loss graph of the model

Accuracy graph of the model

Compiling with deepC:

To bring the saved model on MCU, install deepC— an open-source, vendor-independent deep learning library cum compiler and inference framework, for microcomputers and micro-controllers.

https://gist.github.com/Sanlap1997/993215e22f36881115ae852c2a00cdff

Here’s the link to the complete notebook: https://cainvas.ai-tech.systems/use-cases/human-activity-recognition-app/

Credits: Pradeep Babburi

Written by: Sanlap Dutta