Deep Learning / More Website

General CS

June 5, 2019

My Introduction to Deep Learning

Machine and Deep Learning have always been phrases that I’ve heard and loosely understood, but I decided it was time to take the next step and witness my machine learning. YouTuber SentDex has a great tutorial series on getting started with ML using python, TensorFlow, and Keras. I am following this tutorial while also making adjustments along the way.

To start, I tackled the “Hello World” of Machine Learning. Using a data set consisting of images of digits 0-9, train your machine to be able to accurately identify a random digit. We set up our sequential neural network to map the input data (essentially an array of pixel values) through two inner neuron layers and finally to an output neuron layer of 10 outcomes. These ten outcomes represent the digits 0-9.

Luckily for us, TensorFlow and Keras provide us with the dataset and many tools to make this neural network, and these tools will scale as our networks increase in size.

Sentdex led me through this tutorial using jupyter notebook.

It was a very straightforward tutorial and I ended up finishing with a network that yielded around 96% accuracy.

Main takeaways from this tutorial:

It's Training Cats and Dogs

Next I continued the tutorial onto a dataset consisting of dogs and cats. Our network will try to classify if an image contains a dog or a cat. We are importing a dataset rather than using one contained in the framework. We do this by reading in pictures and classifying one folder as index 0 for dog and the other as 1 for cat. We convert each image into an array of grayscale values. We use grayscale because we assume coloration won’t have much to do with differences between cats and dogs. grayscale also makes array one dimensional rather than 3 dimensional. Color image would have RGB values which is a 3 dimensional array, each pixel containing a R, G, and B value.

We obtain a grayscale array for each image in our dataset. We now must normalize the grayscale data so we divide each value by 255.0.

These pixel values are the feature, and the label of this feature is 0 for dog or 1 for cat.

We now must create a sequential neural network. We specify rectified linear activation for this layer and each following layer. In our first two layers, we use max pooling of a (2,2) size. Our 3x3 convolutional layer gets the input shape dynamically in the first 2d layer.

After the first two 2*64 node layers, flatten and create a new dense layer of 64 nodes.

For the last layer, we only need one node, and it is a sigmoid activation meaning a decimal between 0-1. closer to 1 will mean more likely dog and closer to 0 will mean more likely cat. we fit the model and remember to specify callbacks = [tensorboard] to display graphs and scalars on a local host.

We can use a tensorBoard to see graphs of each epoch and get a visual understanding of what’s happening as and after the data trains.

On Sentdex’s tutorial, he trains very quickly, finishing up to 100 epochs in seconds. He definitely has a better GPU than my 2013 retina MacBook pro, and I don’t really have the capability to train that much an obtain that sort of data. However, I did obtain some (3 epochs worth).

My network only obtained around 75% accuracy in the 3 epochs that it ran. My Terminal after running 3 Epochs

Graphs From TensorBoard

I am giddy to be seeing just how deep you can really go with machine learning, and the process of using it to solve problems statistically rather than logically is very interesting. This opens up a whole new world for computer science.

I’m hoping to deepen my understanding of machine learning with google’s developer course, which focuses on philosophy of machine learning as well as applications.

I also just discovered Kaggle, and it seems like it will be a helpful resource.

Edit:

So that was actually yesterday, and here I am writing on the following day to finish the post. Made significant gains on the website today.