The Complete TensorFlow Tutorial for Newbies

Only one line to define the loss function!Notice again how we used the placeholders, and recognize the construction and computation phases of the code cell above.

One-hot encodingOne-hot encoding is a technique to transform mutliclass labels to vectors of 0s and 1s.

Let’s see how we can do it in TensorFlow:Again, TensorFlow makes it very easy to manipulate our data.

Now that you are more comfortable to the general structure, let’s move on to building an actual neural network to classify hand signs!Hand Signs RecognitionIn this little project, we will build a hand signs recognition system.

Specifically, our neural network will recognize if a hand is expressing a number from 0 to 5.

Let’s load the dataset and take a look at a sample image:And you should see:A sample of the datasetBefore building our model, we will first flatten the images, normalize their features, and one-hot encode the labels:Onto building the model now!Create placeholdersFirst, we write a function to create placeholders for the feature matrix and label matrix:Then, we write a function to initialize the weight matrix and bias matrix:Awesome!.Now, we must define forward propagation:Note that in the code cell above, the comments show the equivalent syntax in numpy.

Finally, we define a function to compute the cost:Now, we are ready to combine everything into a model!Wait…What about backpropagation?.Unlike previous posts where we wrote backpropagation from scratch, deep learning frameworks take care of it automatically with a few lines of code!Putting everything into a single modelNow, we combine all our functions into a model, and we will use mini-batch gradient descent to train the neural network:Now, we run the model with the following line of code:parameters = model(X_train, Y_train, X_test, Y_test)And you should get:Great!.The test accuracy is not that good, because we only used a small part of the entire dataset, and we did not train for very long.

The main objective of this tutorial was to get used to TensorFlow and to get an overview to its API.

Good job!.You are now ready to use TensorFlow for more advanced neural networks and applications.

In following posts, we will explore different neural network structures and use TensorFlow or Keras (another deep learning framework) to build them.

Stay tuned and keep learning!.

. More details

Leave a Reply