Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this code in parallel please with explenation step by step import numpy as np import mnist from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Conv2D,

Write this code in parallel please with explenation step by step

import numpy as np

import mnist

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten

from tensorflow.keras.utils import to_categorical

train_images = mnist.train_images()

train_labels = mnist.train_labels()

test_images = mnist.test_images()

test_labels = mnist.test_labels()

Normalize the images.

train_images = (train_images / 255) - 0.5

test_images = (test_images / 255) - 0.5

# Reshape the images.

train_images = np.expand_dims(train_images, axis=3)

test_images = np.expand_dims(test_images, axis=3)

num_filters = 8

filter_size = 3

pool_size = 2

# Build the model.

model = Sequential([

Conv2D(num_filters, filter_size, input_shape=(28, 28, 1)),

MaxPooling2D(pool_size=pool_size),

Flatten(),

Dense(10, activation='softmax'),

])

# Compile the model.

model.compile(

'adam',

loss='categorical_crossentropy',

metrics=['accuracy'],

)

# Train the model.

model.fit(

train_images,

to_categorical(train_labels),

epochs=3,

validation_data=(test_images, to_categorical(test_labels)),

)

# Predict on the first 5 test images.

predictions = model.predict(test_images[:5])

# Print our model's predictions.

print(np.argmax(predictions, axis=1)) # [7, 2, 1, 0, 4]

# Check our predictions against the ground truths.

print(test_labels[:5]) # [7, 2, 1, 0, 4]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions