How I used CNNs to clean my WhatsApp Images folder

Rishabh Agrahari
2 min readMay 20, 2018

I’m an engineering student. At the end of each semester my WhatsApp image folder looks like this:

The red circled ones are study notes and the blue circled ones are important images. I end up with hundreds of study notes images at the end of each semester, selecting them from all and then deleting them is a tedious process.

I’m good at Machine Learning. I thought why not build a model to detect and extract these study notes from the WhatsApp Images folder. :)

Firstly I prepared the data by manually seperating the study notes from regular images in the whatsapp folder. I used Keras to build my model, in case you don’t know, Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.

I built a Convolutional Neural Network with three [Conv -> Relu -> MaxPool] blocks and two fully connected layers [64 nodes -> Relu -> Dropout (0.5) -> 1 node -> Sigmoid]

I had about a thousand images in my dataset, I used Keras's ImageDataGenerator for Data augmentation for managing the issue of less data and for better generalization, used binary crossentropy as loss function, Adam as optimization function, trained the model on my dataset, the model got a validation accuracy of 85%. I’m working on to improve model perfomance.

I wrote a Python script which takes your WhatsApp folder path, loads the trained model, picks images from your WhatsApp images folder one at a time, if the model predicts it to be a study notes image, then it moves the image to a new folder named ‘notes’. So, at the end I ended up with this:

I’ve open sourced the Python script, the trained model weights, model training and testing code. You can find the code here.

So, now all you need to do is connect your smartphone with your laptop with a usb cable and run the Python script. :)

I’ve written code to automate many boring stuffs, all of them are open sourced and can be found here.

If you liked the story, let me know by 👏 :)

Peace.

--

--

Rishabh Agrahari

I teach machines what to do with their lives. Head of AI Delivery @ Tvarit GmbH