DEV Community

Mohamed Bakrey
Mohamed Bakrey

Posted on

Introduction to TensorFlow 2

Hello TensorFlow!

How to import tensorflow.

# Import TensorFlow
import tensorflow as tf

Loading the image

print('Loading data...\n')
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
print('MNIST dataset loaded.\n')

creat the model

x_train = x_train/255.
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(16, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])

make compile for the model

model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

Make Fit foe the model

print('Training model...\n')
model.fit(x_train, y_train, epochs=3, batch_size=32)
print('Model trained successfully!')

Top comments (0)