How to create amazing Tensorflow model in few lines of code

Photo by Umberto on Unsplash

Although TensorFlow looks very hare but it is very easy to create a machine learning model using this library in very easy and few steps. In this tutorial I will share how to create a machine learning model in minimum lines of code

  1. Why are we using TensorFlow: It is one of the most popular library used for deep learning task at enterprise level. It is very easy to learn and implement
  2. Steps to create model : You need to follow below simple steps to create your first deep learning model in TensorFlow
import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

First layer is Flatten layer that will transform the input matrix [28*28] into flat array

Second layer will be Dense layer with ‘relu’ activation function

Third is also a dense layer. This layer also works as output layer

model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
]), y_train, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)

That’s it. Kudos to you. You have created your first deep learning model



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store