728x90 AdSpace

Sunday, January 7, 2018

A CNN Machine Learning project using Keras and Tensorflow

Machine learning is the future, the more I read about it the more I get fascinated by this field. There are 2 YouTube channels I am currently following and I really encourage people who are interested in machine learning to follow them too, the two channels are Two Minute Papers and Siraj Raval, they always bring new subjects and they will make you interested in ML more than ever, even if you hate math x).
So for a while I've been trying to learn more about ML but I really couldn't find time, I did some slow progress but there are a lot more I need to learn, this year (2018) advancing in ML gonna be one of my goals so I hope from now on I am gonna do more projects in ML and write more posts about it.

In this post I am going to talk about the project I made the first semester, I didn't want to do a classic project so I talked to the prof and asked him to let me do something in ML and he liked the idea, as long as I use python (the subject course) he is Ok with it.

Finding an idea in ML wasn't easy because it always depends on the data you have and getting data in a context you want wasn't easy, so I spent a while with my project partner looking for ideas and during this period we did a lot of research and it was fun, I learned many things like I didn't know it's possible to use CNN to make a voice recognition... I was fascinated by how they got the idea to transform the waves into images and then they could use convolutional neural network x)
Anyway we end up doing a web app that has three parts : the first part same as the one I did before dogs vs cats we wanted to get an idea about ML and this time I got better accuracy and we did the training in the GPU it was really fast, not like the last time in CPU it took us less than a 1 hours, not 24 hours xD, The second part we wanted to do a facial recognition but we didn't find enough data so we kept looking and in kaggle we found a good data set that has The Simpsons TV show characters, we used it to make a facial recognition for the Simpsons, and the last part was using a pre-trained models like VGG-16,  CIFAR-10... that could detect objects in any given image.

I used Flask to make a web interface for everything and here what I got :

Of course, I used many sites like Kaggle and I followed many codes written by others in python to get to this result, but I guess I am proud with what I did, it made me understand ML a little more.

I uploaded the project to GitHub, too bad I couldn't include everything, there is size file limit... but I made it clear from where to get the data and after training the model you will get 80mo model file, as for VGG16 the model will download itself the first time you run the project (it's about 600mo)

Instructions :

1/ Download the project

2/ Go to the project using the terminal and use this command line to install requirements :

pip install -r requirements.txt

3/ Make sure Keras, Tensorflow, flask... are installed

4/ We are going to download the dataset because I couldn't upload them all to Github
download simpsons_dataset.tar.gz from here.
Put them to classifier/Simpson/SimpsonDataset like the shown image below (You will get many Simpsons characters only the folder shown below are needed) :

Run the train.py script in classifier/Simpson folder, the script will start training, it will take a while but at the end you will get 2 files : /models/Simpson/weights_6conv.hdf5 (80mo) and  /models/Simpson/dataset.h5 (200mo)
If you get errors to make sure the requirements like Keras... are installed.

5/ Let's run the web app! go to the web folder in the command line and type :

flask flaskr.py

Wait until everything gets loaded and you will be able to see the web homepage in


Post a Comment

Item Reviewed: A CNN Machine Learning project using Keras and Tensorflow Rating: 5 Reviewed By: Hosni
Scroll to Top