This video is a short clip. For the complete tutorial please head tour article here - https://www.activestate.com/resources...
In this example, a TensorFlow Keras application is created by combining the TensorFlow - foundation library with Keras classes (TensorFlow subclasses). We’ll define a simple CNN (Convolutional Neural Network) model for handwritten character recognition using the MNIST dataset.
Import the required TensorFlow library
and Keras classes for this example:
import tensorflow as tf
from tensorflow.keras import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, AveragePooling2D
Load MNIST dataset and split into training and testing samples:
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
Reshape the image dimensions:
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
Normalize the output from the previous function:
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
Build the model:
model = Sequential()
model.add(Conv2D(filters=6, kernel_size=(3, 3), activation='tanh', input_shape=(28,28,1)))
model.add(AveragePooling2D())
model.add(Conv2D(filters=16, kernel_size=(3, 3), activation='tanh'))
model.add(AveragePooling2D())
model.add(Flatten())
model.add(Dense(units=128, activation='tanh'))
model.add(Dense(units=10, activation = 'softmax'))
Print a summary of the model:
model.summary()
Get the rest of the tutorial at activestate.com/resources/quick-reads/what-is-tensorflow/
Get more Python tutorials related to Numpy, Matplotlib, Scikit-Learn and Pandas here: https://www.activestate.com/learn-python
#machinelearning #Tensorflow #python #opensource #ai #deeplearning