python convolutional neural network Exercise

USE Jupyter Notebook
NB: Please only do Tasks 1-2
We will combine what we’ve learned about convolution, max-pooling and feed-forward layers, to build a ConvNet classifier for images.
Given Code:
in[]from __future__ import absolute_import, division, print_function
# Prerequisits

!pip install pydot_ng

!pip install graphviz

!apt install graphviz /dev/
# import statements

import tensorflow as tf

import tensorflow.contrib.eager as tfe

import numpy as np

import matplotlib.pyplot as plt

from IPython import display

%matplotlib inline
# Enable the interactive TensorFlow interface, which is easier to understand as a beginner.

try:

tf.enable_eager_execution()

print(‘Running in Eager mode.’)

except ValueError:

print(‘Already running in Eager mode’)
in[]cifar = tf.keras.datasets.cifar10

(train_images, train_labels), (test_images, test_labels) = cifar.load_data()

cifar_labels = [‘airplane’, ‘automobile’, ‘bird’, ‘cat’, ‘deer’, ‘dog’, ‘frog’, ‘horse’, ‘ship’, ‘truck’]
in[]# Take the last 10000 images from the training set to form a validation set

train_labels = train_labels.squeeze()

validation_images = train_images[-10000:, :, :]

validation_labels = train_labels[-10000:]

train_images = train_images[:-10000, :, :]

train_labels = train_labels[:-10000]
in[]print(‘train_images.shape = {}, data-type = {}’.format(train_images.shape, train_images.dtype))

print(‘train_labels.shape = {}, data-type = {}’.format(train_labels.shape, train_labels.dtype))
print(‘validation_images.shape = {}, data-type = {}’.format(validation_images.shape, validation_images.dtype))

print(‘validation_labels.shape = {}, data-type = {}’.format(validation_labels.shape, validation_labels.dtype))
in[]plt.figure(figsize=(10,10))

for i in range(25):

plt.subplot(5,5,i+1)

plt.xticks([])

plt.yticks([])

plt.grid(‘off’)
in[]# Define the convolutinal part of the model architecture using Keras Layers.

model = tf.keras.models.Sequential([

tf.keras.layers.Conv2D(filters=48, kernel_size=(3, 3), activation=tf.nn.relu, input_shape=(32, 32, 3), padding=’same’),

tf.keras.layers.MaxPooling2D(pool_size=(3, 3)),

tf.keras.layers.Conv2D(filters=128, kernel_size=(3, 3), activation=tf.nn.relu, padding=’same’),

tf.keras.layers.MaxPooling2D(pool_size=(3, 3)),

tf.keras.layers.Conv2D(filters=192, kernel_size=(3, 3), activation=tf.nn.relu, padding=’same’),

tf.keras.layers.Conv2D(filters=192, kernel_size=(3, 3), activation=tf.nn.relu, padding=’same’),

tf.keras.layers.Conv2D(filters=128, kernel_size=(3, 3), activation=tf.nn.relu, padding=’same’),

tf.keras.layers.MaxPooling2D(pool_size=(3, 3)),
in[]model.summary()
in[]model.add(tf.keras.layers.Flatten()) # Flatten “squeezes” a 3-D volume down into a single vector.

model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))

model.add(tf.keras.layers.Dropout(rate=0.5))

model.add(tf.keras.layers.Dense(1024, activation=tf.nn.relu))

model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))
in[]tf.keras.utils.plot_model(model, to_file=’small_lenet.png’, show_shapes=True, show_layer_names=True)

display.display(display.Image(‘small_lenet.png’))
in[]batch_size = 128

num_epochs = 10 # The number of epochs (full passes through the data) to train for
# Compiling the model adds a loss function, optimiser and metrics to track during training

model.compile(optimizer=tf.train.AdamOptimizer(),

loss=tf.keras.losses.sparse_categorical_crossentropy,

metrics=[‘accuracy’])
# The fit function allows you to fit the compiled model to some training data

model.fit(x=train_images,

y=train_labels,

batch_size=batch_size,

epochs=num_epochs,

validation_data=(validation_images, validation_labels.astype(np.float32)))
print(‘Training complete’)
in[]metric_values = model.evaluate(x=test_images, y=test_labels)
print(‘Final TEST performance’)

for metric_value, metric_name in zip(metric_values, model.metrics_names):

print(‘{}: {}’.format(metric_name, metric_value))
in[]img_indices = np.random.randint(0, len(test_images), size=[25])

sample_test_images = test_images[img_indices]

sample_test_labels = [cifar_labels[i] for i in test_labels[img_indices].squeeze()]
predictions = model.predict(sample_test_images)

max_prediction = np.argmax(predictions, axis=1)

prediction_probs = np.max(predictions, axis=1)
in[]plt.figure(figsize=(10,10))

for i, (img, prediction, prob, true_label) in enumerate(

zip(sample_test_images, max_prediction, prediction_probs, sample_test_labels)):

plt.subplot(5,5,i+1)

plt.xticks([])

plt.yticks([])

plt.grid(‘off’)
plt.imshow(img)

plt.xlabel(‘{} ({:0.3f})’.format(cifar_labels[prediction], prob))

plt.ylabel(‘{}’.format(true_label))
NB: Please only do Tasks 1-2
Tensorflow documentation: from ‘tensorflow.org’ website: search: ‘tf.keras.layers.BatchNormalization’
research paper: search on web: ‘proceedings.mlr.press/v37/ioffe15.pdf’

NB: Please only do Tasks 1-2

Custom Paper Help
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.