Human Activity Recognition Using Convolutional Neural Network in Keras
Branch: master
Clone or download
Shahnawax Update
Spelling mistakes corrected
Latest commit 481c5b5 Jan 15, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information. Minor changes Oct 10, 2017 Update Jan 15, 2019
confusion_matrix.png ** Oct 9, 2017
dataset-distribution.png Minor changes Oct 10, 2017
groundTruth.npy Confusion Matrix, TestData and Ground Truth data are added. Oct 5, 2017
model.h5 Simplified network with lesser number of the connections in fully con… Oct 3, 2017

Human Activity Recognition using CNN in Keras

This repository contains the code for a small project. The aim of this project is to create a simple Convolutional Neural Network (CNN) based Human Activity Recognition (HAR) system. This system uses the sensor data from a 3D accelerometer for x, y and z axis and recognize the activity of the user e.g. Walking, Jogging, going Upstairs or Downstairs, etc.


The repository contains following files.

  •, Python script file, containing the Keras implementation of the CNN based Human Activity Recognition (HAR) model,
  • actitracker_raw.txt, Text file containing the dataset used in this experiment,
  • model.h5, A pretrained model, trained on the training data,
  •, Python script file, containing the evaluation script. This script evaluates the performance of the pretrained netowrk on the provided testData,
  • testData.npy, Python data file, containing the testing data used for the evaluation of the available pretrained model,
  • groundTruth.npy, Python data file, containing the ground truth values for the corresponding outputs for for the test data and

Tools Required

The code in this repository is created using Python 3.6. Furthermore, following libraries are required to run the code provided in this repository:

  • Keras 2.*
  • Numpy
  • Matplotlib
  • Pandas
  • sklearn


In these experiments we used the Actitracker dataset, released by Wireless Sensor Data Mining (WISDM) lab and can be found at this [link]. The data provide in this database is collected from 36 users using a smartphone in there pocket at a sample rate of 20 Samples per second. The data contains values for acceleration for x,y and z axes, while user performs six different activities in a controlled envoirnment. These activities include

  • Downstairs,
  • Jogging,
  • Sitting,
  • Standing,
  • Upstairs, and
  • Walking.

The dataset is not balanced and the distribution of the dataset with respect to the performed activities (class labels) is shown in the figure below.


A simple CNN based neural network is created using the topology in The dataset is splitted into two subgroups, trainData and testData with the ratio of 80 and 20% respectively. The training data is further split into training and validation data with the same distribution. The HAR model created in is then trained on the training data and validated on the validataion data. To evaluate the performance of this network, we write a script "". This script uses the 20% of random samples in the dataset and tests the pretrained CNN model model.h5. Furhtermore, this script reports the percentage of the wrong predictions as error and creates a confusion matrix. The results show that the network has an average accuracy of 92.1 %. For further details, the confusion matrix for the HAR on the testData is shown in the figure below:

Related Problems

The HAR model provided in this work can be further extended to perform the user identification from walking activity. Accelerometer dataset from 22 indivduals can be downloaded from the following [link]