728x90 AdSpace

Saturday, September 2, 2017

[Machine Learning] My first convolutional neural network in python


Recently I was following a machine learning Tutorial and even that ML requires a strong background in math, I am still fascinated with this domain and I want to advance more in this field. Yesterday I was following the part of Deep learning and how to make an Artificial Neural Networks (ANN) or Convolutional Neural Networks (CNN) and in one word deep learning is awesome!
It was the first time I was up late trying to finish this tutorial part.

Today, I implemented the CNN and I spent the whole day trying to make TensorFlow work on the GPU.

What I did was a basic script, I made a model that trains using images of cats and dogs and afterward in the test set it will tell you if the image has a cat or a dog.

So the machine learning model is to make a distinction between dogs and cats, this could be used with any other images like birds or cars or anything I just have to change the data set.

Ok mostly I followed the tutorial, it's not something I did on my own and I am not going to say I understood what the script does 100%.

Few things are still complicated for me, but I am planning to understand them more, and after I finish the whole tutorial I am planning to focus more in the deep learning, it looks like a fascinated domain.

Deep learning need more Compute power, and it's better to use the GPU over the CPU, for my case after I spent the whole day trying to make Tensorflow work over the GPU I even made a post about it: Make Tensorflow use the GPU, I find out that my graphics card is old 😞. so for the moment, I am going to keep working with the CPU.

Let's talk a little about the script :

convolutional neural network

To make the CNN I used Keras lib that uses Tensorflow in the backend, the reason for using keras and not Tensorflow directly is that Keras make things easy and I will have to write less code. By the way, Keras was made by a Google developer member.
The tutorial I followed was a little old and by old, I mean less than a year old but the deep learning is a new field that it libs and packages get new updates frequently. So to apply the tutorial I had to change few things and thanks to google and the documentation I was able to see the new changes...



I got 0.9958 accuracies from the train set and 0.7705 from the test set (difference 22%)  which is kinda good, the accuracy of the training set is a little suspicious but it means from 4 images the script is able to identify 3 correct images and this could be improved by adding the other layer, adding more images to the train set keras website has 25k images of dogs and cats 500mo, to apply this tutorial I only used 10k, also there are few parameters that could be changed to improve the result but this will need more computing power. but in general people were able to get 0.98914 accuracies using other lib and this was achieved 4 years ago so yeah deep learning is awesome!

In the tutorial, he got 0.8452 accuracy for the train set and 0.7510 for the test set (difference 10%) and when he added a new layer in the CNN to improve the result he got 0.8516 accuracy from the train set and 0.8180 from the test set (difference 3%)

I left the pc open for 9 hours to get the result xD the CPU was working to the full performance for the whole night.



so I am not going to add another layer and wait another  9 hours to compare the result x)


Anyway, I uploaded the script in GitHub, it includes the data set, 10000 images of cats and dogs about 230mo.

The link: https://github.com/HosniMansour/machine-learning-cnn-cat-or-dog

0 comments:

Post a Comment

Item Reviewed: [Machine Learning] My first convolutional neural network in python Rating: 5 Reviewed By: Hosni
Scroll to Top