In [1]:
from IPython.display import Image
Image('image/network_flowchart.png')


Out[1]:

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
from sklearn.metrics import confusion_matrix
import time
from datetime import timedelta
import math
import os

import sys
sys.path.append('./utility')

Download CIFAR10

download.maybe_download_and_extract(url=data_url, download_dir=data_path)

data_url = "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"

data_path = "data/CIFAR-10/"


In [3]:
import cifar10
cifar10.maybe_download_and_extract()


Data has apparently already been downloaded and unpacked.

CIFAR 10 Attributres

Classes in CIFAR10


In [4]:
class_names = cifar10.load_class_names()
class_names


Loading data: data/CIFAR-10/cifar-10-batches-py/batches.meta
Out[4]:
['airplane',
 'automobile',
 'bird',
 'cat',
 'deer',
 'dog',
 'frog',
 'horse',
 'ship',
 'truck']

Load Training Data


In [5]:
images_train, cls_train, labels_train = cifar10.load_training_data()


Loading data: data/CIFAR-10/cifar-10-batches-py/data_batch_1
Loading data: data/CIFAR-10/cifar-10-batches-py/data_batch_2
Loading data: data/CIFAR-10/cifar-10-batches-py/data_batch_3
Loading data: data/CIFAR-10/cifar-10-batches-py/data_batch_4
Loading data: data/CIFAR-10/cifar-10-batches-py/data_batch_5

In [6]:
print(images_train.shape)
print(labels_train.shape)
print(cls_train.shape)


(50000, 32, 32, 3)
(50000, 10)
(50000,)

In [7]:
images_test, cls_test, labels_test = cifar10.load_test_data()
print("Size of:")
print("- Training-set:\t\t{}".format(len(images_train)))
print("- Test-set:\t\t{}".format(len(images_test)))


Loading data: data/CIFAR-10/cifar-10-batches-py/test_batch
Size of:
- Training-set:		50000
- Test-set:		10000

In [8]:
import help_function as h

# Get the first images from the test-set.
images = images_test[0:9]
# Get the true classes for those images.
cls_true = cls_test[0:9]
# Plot the images and labels using our helper-function above.
h.plot_images(images=images, cls_true=cls_true, smooth=False)


Loading data: data/CIFAR-10/cifar-10-batches-py/batches.meta

Buildup Placeholder


In [9]:
from cifar10 import img_size, num_channels, num_classes
x = tf.placeholder(tf.float32, shape=[None, img_size, img_size, num_channels], name='x')
y_true = tf.placeholder(tf.float32, shape=[None, num_classes], name='y_true')
y_true_cls = tf.argmax(y_true, dimension=1)

is_training = tf.placeholder(tf.bool, name='is_training')

Main Architechture of Model


In [10]:
Image('image/network_flowchart.png')


Out[10]: