Fall Detection using CNN architecture

Photo by Julien Laureau on Dribbble

Introduction

Fall detection is major problem in healthcare. Old people fall often and there should be immediate aid for them as injury can be series, even lead to the death. In this project, we will use Convolutional Neural Network architecture to detect whether a person has fallen or not in given image. For this purpose, we use public dataset that contains videos of falling people. Each frame has been given as a picture, and we use 2 videos that makes a total of 240 images. Images can be labelled manually starting by the frame where the fall starts.

Preprocessing

  • Importing necessary libraries

https://gist.github.com/kananmahammadli/b7520274aede2d6fe6daf591976ca343

  • Downloading the train images, unzipping, and deleting zip file

https://gist.github.com/kananmahammadli/146665b3fbc59f5ae0f3842f8db028b1

  • Reading the train labels

https://gist.github.com/kananmahammadli/83871d6566719404343683cb920b0659

Output:

  • Reading the test labels

https://gist.github.com/kananmahammadli/964d6ebef591e43360f381c040233205

Output:

  • Now we will read train and test images from the created folder , read them with cv2 library. Then we will add current train and test images image to train_images and test_images lists and access corresponding label using image name and add it to train_labels and test_labels lists respectively

https://gist.github.com/kananmahammadli/197d3d5eaceb340bd4819deaed98314f

Output:

  • We have 240 RGB images with size (96×96), let’s visualize some images that represents fallen and not fallen person

https://gist.github.com/kananmahammadli/b474cdc94f8860f1fd5e27477d5e19db

Output:

Splitting the train data into train and validation sets

https://gist.github.com/kananmahammadli/17523cbbd084c728a31024c116133112

Creating our CNN architecture and fit on train data

  • Importing necessary functions from Tensorflow library

https://gist.github.com/kananmahammadli/55f723a0ddf4f779c3f451ce8a6901b9

  • Creating a custom function for convolution operation that will help to avoid unnecessary repetition

https://gist.github.com/kananmahammadli/e1455673a082a6531b903a45c4afd9be

  • For our CNN architecture we build 6 blocks that contains convolution layer, ReLU activation which is followed by max pooling layer, then flatten our result, add one dense layer and use sigmoid function for the final result

https://gist.github.com/kananmahammadli/da99a4110eb2c9e3ea0588a726485852

Output:

  • To train our model we use Adam optimizer with learning rate= 0.0001 and Binary Crossentropy as loss function. Let’s visualize accuracy and loss plots after running our model for 5 epochs and save our model

https://gist.github.com/kananmahammadli/5bb5e47208ff4b8ebedbc05af3e23930

Output:

Testing our model

  • Now, it is time to test our model on new images. For this purpose we use 12 images.

Predicting on test images and check the results visually.

https://gist.github.com/kananmahammadli/db7343f9e0634e408abcc14dcc3ff8aa

Output:

Conclusion

In conclusion, we built and trained a deep learning model on public dataset and reached a reasonable accuracy on our performance.

Notebook link: Here

Credit: Kanan Mahammadli