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/null
# 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

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

We value our customers and so we ensure that what we do is 100% original..
With us you are guaranteed of quality work done by our qualified experts.Your information and everything that you do with us is kept completely confidential.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

The Product ordered is guaranteed to be original. Orders are checked by the most advanced anti-plagiarism software in the market to assure that the Product is 100% original. The Company has a zero tolerance policy for plagiarism.

Read more

Free-revision policy

The Free Revision policy is a courtesy service that the Company provides to help ensure Customer’s total satisfaction with the completed Order. To receive free revision the Company requires that the Customer provide the request within fourteen (14) days from the first completion date and within a period of thirty (30) days for dissertations.

Read more

Privacy policy

The Company is committed to protect the privacy of the Customer and it will never resell or share any of Customer’s personal information, including credit card data, with any third party. All the online transactions are processed through the secure and reliable online payment systems.

Read more

Fair-cooperation guarantee

By placing an order with us, you agree to the service we provide. We will endear to do all that it takes to deliver a comprehensive paper as per your requirements. We also count on your cooperation to ensure that we deliver on this mandate.

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency

Order your paper today and save 15% with the discount code HAPPY

X
error: Content is protected !!
Open chat
1
You can contact our live agent via WhatsApp! Via + 1 323 412 5597

Feel free to ask questions, clarifications, or discounts available when placing an order.