Image Classification

In this project, you'll classify images from the CIFAR-10 dataset. The dataset consists of airplanes, dogs, cats, and other objects. You'll preprocess the images, then train a convolutional neural network on all the samples. The images need to be normalized and the labels need to be one-hot encoded. You'll get to apply what you learned and build a convolutional, max pooling, dropout, and fully connected layers. At the end, you'll get to see your neural network's predictions on the sample images.

Get the Data

Run the following cell to download the CIFAR-10 dataset for python.

In [1]:
"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
from urllib.request import urlretrieve
from os.path import isfile, isdir
from tqdm import tqdm
import problem_unittests as tests
import tarfile

cifar10_dataset_folder_path = 'cifar-10-batches-py'

class DLProgress(tqdm):
    last_block = 0

    def hook(self, block_num=1, block_size=1, total_size=None):
        self.total = total_size
        self.update((block_num - self.last_block) * block_size)
        self.last_block = block_num

if not isfile('cifar-10-python.tar.gz'):
    with DLProgress(unit='B', unit_scale=True, miniters=1, desc='CIFAR-10 Dataset') as pbar:
        urlretrieve(
            'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz',
            'cifar-10-python.tar.gz',
            pbar.hook)

if not isdir(cifar10_dataset_folder_path):
    with tarfile.open('cifar-10-python.tar.gz') as tar:
        tar.extractall()
        tar.close()


tests.test_folder_path(cifar10_dataset_folder_path)
CIFAR-10 Dataset: 171MB [00:26, 6.48MB/s]                              
All files found!

Explore the Data

The dataset is broken into batches to prevent your machine from running out of memory. The CIFAR-10 dataset consists of 5 batches, named data_batch_1, data_batch_2, etc.. Each batch contains the labels and images that are one of the following:

  • airplane
  • automobile
  • bird
  • cat
  • deer
  • dog
  • frog
  • horse
  • ship
  • truck

Understanding a dataset is part of making predictions on the data. Play around with the code cell below by changing the batch_id and sample_id. The batch_id is the id for a batch (1-5). The sample_id is the id for a image and label pair in the batch.

Ask yourself "What are all possible labels?", "What is the range of values for the image data?", "Are the labels in order or random?". Answers to questions like these will help you preprocess the data and end up with better predictions.

In [2]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import helper
import numpy as np

# Explore the dataset
batch_id = 2
sample_id = 9999
helper.display_stats(cifar10_dataset_folder_path, batch_id, sample_id)
Stats of batch 2:
Samples: 10000
Label Counts: {0: 984, 1: 1007, 2: 1010, 3: 995, 4: 1010, 5: 988, 6: 1008, 7: 1026, 8: 987, 9: 985}
First 20 Labels: [1, 6, 6, 8, 8, 3, 4, 6, 0, 6, 0, 3, 6, 6, 5, 4, 8, 3, 2, 6]

Example of Image 9999:
Image - Min Value: 3 Max Value: 253
Image - Shape: (32, 32, 3)
Label - Label Id: 5 Name: dog

Answer to the data exploration questions

There are 10 possible labels: airplane, automobile, bird etc. These labels are encoded to 0, 1, 2, ..., 9. Please note that the encoding starts from 0, not 1. The batch id starts from 1, and ends at 5; the image id starts from 0, and ends at 9999. So there are totally 10K images per batch, and 50K images for all the batches.

Each image contains values ranges from 0 to 255, the dimension is 32(width)x32(height)x3(color). The labels are in random order.

Implement Preprocess Functions

Normalize

In the cell below, implement the normalize function to take in image data, x, and return it as a normalized Numpy array. The values should be in the range of 0 to 1, inclusive. The return object should be the same shape as x.

In [3]:
def normalize(x):
    """
    Normalize a list of sample image data in the range of 0 to 1
    : x: List of image data.  The image shape is (32, 32, 3)
    : return: Numpy array of normalize data
    """
    # TODO: Implement Function
    # return None
    a = 0
    b = 255
    return (x-a)/(b-a)

"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_normalize(normalize)
Tests Passed

One-hot encode

Just like the previous code cell, you'll be implementing a function for preprocessing. This time, you'll implement the one_hot_encode function. The input, x, are a list of labels. Implement the function to return the list of labels as One-Hot encoded Numpy array. The possible values for labels are 0 to 9. The one-hot encoding function should return the same encoding for each value between each call to one_hot_encode. Make sure to save the map of encodings outside the function.

Hint: Don't reinvent the wheel.

In [4]:
def one_hot_encode(x):
    """
    One hot encode a list of sample labels. Return a one-hot encoded vector for each label.
    : x: List of sample Labels
    : return: Numpy array of one-hot encoded labels
    """
    # TODO: Implement Function
    # return None
    y = np.zeros((len(x), 10))
    for i in range(len(x)):
        y[i,x[i]] = 1
    return y

"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_one_hot_encode(one_hot_encode)
Tests Passed

Randomize Data

As you saw from exploring the data above, the order of the samples are randomized. It doesn't hurt to randomize it again, but you don't need to for this dataset.

Preprocess all the data and save it

Running the code cell below will preprocess all the CIFAR-10 data and save it to file. The code below also uses 10% of the training data for validation.

In [5]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
# Preprocess Training, Validation, and Testing Data
helper.preprocess_and_save_data(cifar10_dataset_folder_path, normalize, one_hot_encode)

Check Point

This is your first checkpoint. If you ever decide to come back to this notebook or have to restart the notebook, you can start from here. The preprocessed data has been saved to disk.

In [1]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
import pickle
import problem_unittests as tests
import helper

# Load the Preprocessed Validation data
valid_features, valid_labels = pickle.load(open('preprocess_validation.p', mode='rb'))
In [2]:
#need to delete
print(valid_labels)
valid_labels.shape
valid_features.shape
valid_features
[[ 0.  0.  0. ...,  0.  0.  0.]
 [ 0.  0.  1. ...,  0.  0.  0.]
 [ 0.  0.  1. ...,  0.  0.  0.]
 ..., 
 [ 0.  0.  0. ...,  0.  0.  1.]
 [ 0.  1.  0. ...,  0.  0.  0.]
 [ 0.  1.  0. ...,  0.  0.  0.]]
Out[2]:
array([[[[ 0.54901961,  0.49019608,  0.45098039],
         [ 0.57254902,  0.50980392,  0.47843137],
         [ 0.56078431,  0.49803922,  0.47843137],
         ..., 
         [ 0.66666667,  0.56862745,  0.51372549],
         [ 0.69019608,  0.58823529,  0.5254902 ],
         [ 0.66666667,  0.57647059,  0.52156863]],

        [[ 0.4745098 ,  0.42352941,  0.50588235],
         [ 0.50980392,  0.4627451 ,  0.54509804],
         [ 0.5254902 ,  0.4745098 ,  0.56078431],
         ..., 
         [ 0.63921569,  0.55294118,  0.61568627],
         [ 0.66666667,  0.57254902,  0.63137255],
         [ 0.66666667,  0.58039216,  0.63137255]],

        [[ 0.59607843,  0.54509804,  0.68235294],
         [ 0.61568627,  0.56862745,  0.70196078],
         [ 0.60784314,  0.56078431,  0.68627451],
         ..., 
         [ 0.69411765,  0.60392157,  0.75686275],
         [ 0.70980392,  0.61176471,  0.76078431],
         [ 0.71764706,  0.62745098,  0.76078431]],

        ..., 
        [[ 0.49019608,  0.43137255,  0.4       ],
         [ 0.50588235,  0.43921569,  0.40392157],
         [ 0.29803922,  0.2627451 ,  0.18431373],
         ..., 
         [ 0.65882353,  0.5372549 ,  0.47058824],
         [ 0.61960784,  0.49411765,  0.40392157],
         [ 0.57254902,  0.45490196,  0.34117647]],

        [[ 0.33333333,  0.30196078,  0.2745098 ],
         [ 0.36862745,  0.31764706,  0.27843137],
         [ 0.29019608,  0.25490196,  0.17647059],
         ..., 
         [ 0.63529412,  0.51764706,  0.41568627],
         [ 0.65098039,  0.5254902 ,  0.39215686],
         [ 0.61960784,  0.50196078,  0.36078431]],

        [[ 0.49019608,  0.43921569,  0.43529412],
         [ 0.50980392,  0.44313725,  0.43529412],
         [ 0.41176471,  0.35686275,  0.29411765],
         ..., 
         [ 0.51764706,  0.41568627,  0.30588235],
         [ 0.50980392,  0.39607843,  0.25098039],
         [ 0.55686275,  0.45098039,  0.30588235]]],


       [[[ 0.39215686,  0.42745098,  0.32941176],
         [ 0.47843137,  0.49411765,  0.42745098],
         [ 0.34117647,  0.34117647,  0.29803922],
         ..., 
         [ 0.29411765,  0.30588235,  0.27058824],
         [ 0.2745098 ,  0.28627451,  0.25098039],
         [ 0.2745098 ,  0.28627451,  0.25098039]],

        [[ 0.3372549 ,  0.38823529,  0.27843137],
         [ 0.29803922,  0.32941176,  0.25882353],
         [ 0.23529412,  0.25098039,  0.21176471],
         ..., 
         [ 0.30588235,  0.31764706,  0.28235294],
         [ 0.29803922,  0.30980392,  0.2745098 ],
         [ 0.32156863,  0.33333333,  0.29803922]],

        [[ 0.32941176,  0.39215686,  0.28627451],
         [ 0.3254902 ,  0.37254902,  0.29411765],
         [ 0.30196078,  0.3372549 ,  0.28235294],
         ..., 
         [ 0.29019608,  0.30196078,  0.26666667],
         [ 0.28627451,  0.29803922,  0.2627451 ],
         [ 0.3254902 ,  0.3372549 ,  0.30196078]],

        ..., 
        [[ 0.25098039,  0.30196078,  0.30980392],
         [ 0.47843137,  0.52156863,  0.56470588],
         [ 0.5254902 ,  0.56862745,  0.61176471],
         ..., 
         [ 0.41176471,  0.48235294,  0.47058824],
         [ 0.32941176,  0.40392157,  0.35686275],
         [ 0.23529412,  0.34509804,  0.24705882]],

        [[ 0.17254902,  0.2       ,  0.21960784],
         [ 0.30588235,  0.32941176,  0.36862745],
         [ 0.37647059,  0.39607843,  0.43137255],
         ..., 
         [ 0.57647059,  0.64705882,  0.69803922],
         [ 0.49411765,  0.56078431,  0.58431373],
         [ 0.36862745,  0.45882353,  0.44313725]],

        [[ 0.14117647,  0.1372549 ,  0.15294118],
         [ 0.23137255,  0.22745098,  0.25882353],
         [ 0.32156863,  0.31764706,  0.33333333],
         ..., 
         [ 0.5254902 ,  0.6       ,  0.62745098],
         [ 0.54117647,  0.59607843,  0.61960784],
         [ 0.50980392,  0.58039216,  0.58823529]]],


       [[[ 0.0745098 ,  0.1254902 ,  0.05882353],
         [ 0.08235294,  0.14901961,  0.08235294],
         [ 0.10588235,  0.19215686,  0.1254902 ],
         ..., 
         [ 0.29411765,  0.48627451,  0.51372549],
         [ 0.29803922,  0.48627451,  0.50980392],
         [ 0.27843137,  0.4627451 ,  0.48627451]],

        [[ 0.09019608,  0.12156863,  0.05490196],
         [ 0.08235294,  0.11764706,  0.04705882],
         [ 0.09019608,  0.1372549 ,  0.05490196],
         ..., 
         [ 0.28235294,  0.4627451 ,  0.49411765],
         [ 0.29411765,  0.46666667,  0.48627451],
         [ 0.26666667,  0.43529412,  0.44705882]],

        [[ 0.09411765,  0.14509804,  0.06666667],
         [ 0.08627451,  0.1372549 ,  0.0627451 ],
         [ 0.09411765,  0.14117647,  0.07058824],
         ..., 
         [ 0.25098039,  0.42745098,  0.43921569],
         [ 0.2627451 ,  0.42745098,  0.43529412],
         [ 0.25098039,  0.41176471,  0.41176471]],

        ..., 
        [[ 0.24313725,  0.18039216,  0.09019608],
         [ 0.23529412,  0.18039216,  0.10588235],
         [ 0.21568627,  0.18823529,  0.10980392],
         ..., 
         [ 0.05098039,  0.02352941,  0.01568627],
         [ 0.04705882,  0.05490196,  0.03137255],
         [ 0.09803922,  0.15686275,  0.11764706]],

        [[ 0.24705882,  0.20784314,  0.11764706],
         [ 0.19215686,  0.17647059,  0.08627451],
         [ 0.17647059,  0.18039216,  0.09019608],
         ..., 
         [ 0.11372549,  0.1372549 ,  0.12156863],
         [ 0.11764706,  0.16470588,  0.14509804],
         [ 0.10588235,  0.19607843,  0.16862745]],

        [[ 0.27058824,  0.20392157,  0.11372549],
         [ 0.19215686,  0.14901961,  0.07843137],
         [ 0.21176471,  0.18039216,  0.10588235],
         ..., 
         [ 0.25882353,  0.34509804,  0.33333333],
         [ 0.15686275,  0.26666667,  0.25098039],
         [ 0.11372549,  0.24313725,  0.22745098]]],


       ..., 
       [[[ 0.1372549 ,  0.69803922,  0.92156863],
         [ 0.15686275,  0.69019608,  0.9372549 ],
         [ 0.16470588,  0.69019608,  0.94509804],
         ..., 
         [ 0.38823529,  0.69411765,  0.85882353],
         [ 0.30980392,  0.57647059,  0.77254902],
         [ 0.34901961,  0.58039216,  0.74117647]],

        [[ 0.22352941,  0.71372549,  0.91764706],
         [ 0.17254902,  0.72156863,  0.98039216],
         [ 0.19607843,  0.71764706,  0.94117647],
         ..., 
         [ 0.61176471,  0.71372549,  0.78431373],
         [ 0.55294118,  0.69411765,  0.80784314],
         [ 0.45490196,  0.58431373,  0.68627451]],

        [[ 0.38431373,  0.77254902,  0.92941176],
         [ 0.25098039,  0.74117647,  0.98823529],
         [ 0.27058824,  0.75294118,  0.96078431],
         ..., 
         [ 0.7372549 ,  0.76470588,  0.80784314],
         [ 0.46666667,  0.52941176,  0.57647059],
         [ 0.23921569,  0.30980392,  0.35294118]],

        ..., 
        [[ 0.28627451,  0.30980392,  0.30196078],
         [ 0.20784314,  0.24705882,  0.26666667],
         [ 0.21176471,  0.26666667,  0.31372549],
         ..., 
         [ 0.06666667,  0.15686275,  0.25098039],
         [ 0.08235294,  0.14117647,  0.2       ],
         [ 0.12941176,  0.18823529,  0.19215686]],

        [[ 0.23921569,  0.26666667,  0.29411765],
         [ 0.21568627,  0.2745098 ,  0.3372549 ],
         [ 0.22352941,  0.30980392,  0.40392157],
         ..., 
         [ 0.09411765,  0.18823529,  0.28235294],
         [ 0.06666667,  0.1372549 ,  0.20784314],
         [ 0.02745098,  0.09019608,  0.1254902 ]],

        [[ 0.17254902,  0.21960784,  0.28627451],
         [ 0.18039216,  0.25882353,  0.34509804],
         [ 0.19215686,  0.30196078,  0.41176471],
         ..., 
         [ 0.10588235,  0.20392157,  0.30196078],
         [ 0.08235294,  0.16862745,  0.25882353],
         [ 0.04705882,  0.12156863,  0.19607843]]],


       [[[ 0.74117647,  0.82745098,  0.94117647],
         [ 0.72941176,  0.81568627,  0.9254902 ],
         [ 0.7254902 ,  0.81176471,  0.92156863],
         ..., 
         [ 0.68627451,  0.76470588,  0.87843137],
         [ 0.6745098 ,  0.76078431,  0.87058824],
         [ 0.6627451 ,  0.76078431,  0.8627451 ]],

        [[ 0.76078431,  0.82352941,  0.9372549 ],
         [ 0.74901961,  0.81176471,  0.9254902 ],
         [ 0.74509804,  0.80784314,  0.92156863],
         ..., 
         [ 0.67843137,  0.75294118,  0.8627451 ],
         [ 0.67058824,  0.74901961,  0.85490196],
         [ 0.65490196,  0.74509804,  0.84705882]],

        [[ 0.81568627,  0.85882353,  0.95686275],
         [ 0.80392157,  0.84705882,  0.94117647],
         [ 0.8       ,  0.84313725,  0.9372549 ],
         ..., 
         [ 0.68627451,  0.74901961,  0.85098039],
         [ 0.6745098 ,  0.74509804,  0.84705882],
         [ 0.6627451 ,  0.74901961,  0.84313725]],

        ..., 
        [[ 0.81176471,  0.78039216,  0.70980392],
         [ 0.79607843,  0.76470588,  0.68627451],
         [ 0.79607843,  0.76862745,  0.67843137],
         ..., 
         [ 0.52941176,  0.51764706,  0.49803922],
         [ 0.63529412,  0.61960784,  0.58823529],
         [ 0.65882353,  0.63921569,  0.59215686]],

        [[ 0.77647059,  0.74509804,  0.66666667],
         [ 0.74117647,  0.70980392,  0.62352941],
         [ 0.70588235,  0.6745098 ,  0.57647059],
         ..., 
         [ 0.69803922,  0.67058824,  0.62745098],
         [ 0.68627451,  0.6627451 ,  0.61176471],
         [ 0.68627451,  0.6627451 ,  0.60392157]],

        [[ 0.77647059,  0.74117647,  0.67843137],
         [ 0.74117647,  0.70980392,  0.63529412],
         [ 0.69803922,  0.66666667,  0.58431373],
         ..., 
         [ 0.76470588,  0.72156863,  0.6627451 ],
         [ 0.76862745,  0.74117647,  0.67058824],
         [ 0.76470588,  0.74509804,  0.67058824]]],


       [[[ 0.89803922,  0.89803922,  0.9372549 ],
         [ 0.9254902 ,  0.92941176,  0.96862745],
         [ 0.91764706,  0.9254902 ,  0.96862745],
         ..., 
         [ 0.85098039,  0.85882353,  0.91372549],
         [ 0.86666667,  0.8745098 ,  0.91764706],
         [ 0.87058824,  0.8745098 ,  0.91372549]],

        [[ 0.87058824,  0.86666667,  0.89803922],
         [ 0.9372549 ,  0.9372549 ,  0.97647059],
         [ 0.91372549,  0.91764706,  0.96470588],
         ..., 
         [ 0.8745098 ,  0.8745098 ,  0.9254902 ],
         [ 0.89019608,  0.89411765,  0.93333333],
         [ 0.82352941,  0.82745098,  0.8627451 ]],

        [[ 0.83529412,  0.80784314,  0.82745098],
         [ 0.91764706,  0.90980392,  0.9372549 ],
         [ 0.90588235,  0.91372549,  0.95686275],
         ..., 
         [ 0.8627451 ,  0.8627451 ,  0.90980392],
         [ 0.8627451 ,  0.85882353,  0.90980392],
         [ 0.79215686,  0.79607843,  0.84313725]],

        ..., 
        [[ 0.58823529,  0.56078431,  0.52941176],
         [ 0.54901961,  0.52941176,  0.49803922],
         [ 0.51764706,  0.49803922,  0.47058824],
         ..., 
         [ 0.87843137,  0.87058824,  0.85490196],
         [ 0.90196078,  0.89411765,  0.88235294],
         [ 0.94509804,  0.94509804,  0.93333333]],

        [[ 0.5372549 ,  0.51764706,  0.49411765],
         [ 0.50980392,  0.49803922,  0.47058824],
         [ 0.49019608,  0.4745098 ,  0.45098039],
         ..., 
         [ 0.70980392,  0.70588235,  0.69803922],
         [ 0.79215686,  0.78823529,  0.77647059],
         [ 0.83137255,  0.82745098,  0.81176471]],

        [[ 0.47843137,  0.46666667,  0.44705882],
         [ 0.4627451 ,  0.45490196,  0.43137255],
         [ 0.47058824,  0.45490196,  0.43529412],
         ..., 
         [ 0.70196078,  0.69411765,  0.67843137],
         [ 0.64313725,  0.64313725,  0.63529412],
         [ 0.63921569,  0.63921569,  0.63137255]]]])

Build the network

For the neural network, you'll build each layer into a function. Most of the code you've seen has been outside of functions. To test your code more thoroughly, we require that you put each layer in a function. This allows us to give you better feedback and test for simple mistakes using our unittests before you submit your project.

Note: If you're finding it hard to dedicate enough time for this course each week, we've provided a small shortcut to this part of the project. In the next couple of problems, you'll have the option to use classes from the TensorFlow Layers or TensorFlow Layers (contrib) packages to build each layer, except the layers you build in the "Convolutional and Max Pooling Layer" section. TF Layers is similar to Keras's and TFLearn's abstraction to layers, so it's easy to pickup.

However, if you would like to get the most out of this course, try to solve all the problems without using anything from the TF Layers packages. You can still use classes from other packages that happen to have the same name as ones you find in TF Layers! For example, instead of using the TF Layers version of the conv2d class, tf.layers.conv2d, you would want to use the TF Neural Network version of conv2d, tf.nn.conv2d.

Let's begin!

Input

The neural network needs to read the image data, one-hot encoded labels, and dropout keep probability. Implement the following functions

  • Implement neural_net_image_input
    • Return a TF Placeholder
    • Set the shape using image_shape with batch size set to None.
    • Name the TensorFlow placeholder "x" using the TensorFlow name parameter in the TF Placeholder.
  • Implement neural_net_label_input
    • Return a TF Placeholder
    • Set the shape using n_classes with batch size set to None.
    • Name the TensorFlow placeholder "y" using the TensorFlow name parameter in the TF Placeholder.
  • Implement neural_net_keep_prob_input
    • Return a TF Placeholder for dropout keep probability.
    • Name the TensorFlow placeholder "keep_prob" using the TensorFlow name parameter in the TF Placeholder.

These names will be used at the end of the project to load your saved model.

Note: None for shapes in TensorFlow allow for a dynamic size.

In [3]:
import tensorflow as tf

def neural_net_image_input(image_shape):
    """
    Return a Tensor for a bach of image input
    : image_shape: Shape of the images
    : return: Tensor for image input.
    """
    # TODO: Implement Function    
    return tf.placeholder(tf.float32, [None] + list(image_shape), "x")


def neural_net_label_input(n_classes):
    """
    Return a Tensor for a batch of label input
    : n_classes: Number of classes
    : return: Tensor for label input.
    """
    # TODO: Implement Function
    return tf.placeholder(tf.float32, [None, n_classes], "y")


def neural_net_keep_prob_input():
    """
    Return a Tensor for keep probability
    : return: Tensor for keep probability.
    """
    # TODO: Implement Function
    return tf.placeholder(tf.float32, None, "keep_prob")


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tf.reset_default_graph()
tests.test_nn_image_inputs(neural_net_image_input)
tests.test_nn_label_inputs(neural_net_label_input)
tests.test_nn_keep_prob_inputs(neural_net_keep_prob_input)
Image Input Tests Passed.
Label Input Tests Passed.
Keep Prob Tests Passed.

Convolution and Max Pooling Layer

Convolution layers have a lot of success with images. For this code cell, you should implement the function conv2d_maxpool to apply convolution then max pooling:

  • Create the weight and bias using conv_ksize, conv_num_outputs and the shape of x_tensor.
  • Apply a convolution to x_tensor using weight and conv_strides.
    • We recommend you use same padding, but you're welcome to use any padding.
  • Add bias
  • Add a nonlinear activation to the convolution.
  • Apply Max Pooling using pool_ksize and pool_strides.
    • We recommend you use same padding, but you're welcome to use any padding.

Note: You can't use TensorFlow Layers or TensorFlow Layers (contrib) for this layer, but you can still use TensorFlow's Neural Network package. You may still use the shortcut option for all the other layers.

In [4]:
#need to delete
conv_ksize=(32,32)
y=conv_ksize+(3,)+(5,)
print(y)
x=tf.truncated_normal(y)
print(x)
(32, 32, 3, 5)
Tensor("truncated_normal:0", shape=(32, 32, 3, 5), dtype=float32)
In [5]:
def conv2d_maxpool(x_tensor, conv_num_outputs, conv_ksize, conv_strides, pool_ksize, pool_strides):
    """
    Apply convolution then max pooling to x_tensor
    :param x_tensor: TensorFlow Tensor
    :param conv_num_outputs: Number of outputs for the convolutional layer
    :param conv_ksize: kernal size 2-D Tuple for the convolutional layer
    :param conv_strides: Stride 2-D Tuple for convolution
    :param pool_ksize: kernal size 2-D Tuple for pool
    :param pool_strides: Stride 2-D Tuple for pool
    : return: A tensor that represents convolution and max pooling of x_tensor
    """
    # TODO: Implement Function    
    dimension = x_tensor.get_shape().as_list()
    shape = list(conv_ksize + (dimension[-1],) + (conv_num_outputs,))
    #print(shape)
    filter_weights = tf.Variable(tf.truncated_normal(shape,0,0.1)) # (height, width, input_depth, output_depth)
    filter_bias = tf.Variable(tf.zeros(conv_num_outputs))
    padding = 'SAME'
    #print(list((1,)+conv_strides+(1,)))
    #print(filter_weights)
    conv_layer = tf.nn.conv2d(x_tensor, filter_weights, list((1,)+conv_strides+(1,)), padding)
    conv_layer = tf.nn.bias_add(conv_layer, filter_bias)
    
    conv_layer = tf.nn.relu(conv_layer)
    
    conv_layer = tf.nn.max_pool(
        conv_layer,
        ksize=[1] + list(pool_ksize) + [1],
        strides=[1] + list(pool_strides) + [1],
        padding='SAME')
    
    return conv_layer

"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_con_pool(conv2d_maxpool)
Tests Passed

Flatten Layer

Implement the flatten function to change the dimension of x_tensor from a 4-D tensor to a 2-D tensor. The output should be the shape (Batch Size, Flattened Image Size). Shortcut option: you can use classes from the TensorFlow Layers or TensorFlow Layers (contrib) packages for this layer. For more of a challenge, only use other TensorFlow packages.

In [6]:
from numpy import prod
def flatten(x_tensor):
    """
    Flatten x_tensor to (Batch Size, Flattened Image Size)
    : x_tensor: A tensor of size (Batch Size, ...), where ... are the image dimensions.
    : return: A tensor of size (Batch Size, Flattened Image Size).
    """
    # TODO: Implement Function
    #return None
    dimension = x_tensor.get_shape().as_list()    
    return tf.reshape(x_tensor,[-1,prod(dimension[1:])])


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_flatten(flatten)
Tests Passed

Fully-Connected Layer

Implement the fully_conn function to apply a fully connected layer to x_tensor with the shape (Batch Size, num_outputs). Shortcut option: you can use classes from the TensorFlow Layers or TensorFlow Layers (contrib) packages for this layer. For more of a challenge, only use other TensorFlow packages.

In [7]:
def fully_conn(x_tensor, num_outputs):
    """
    Apply a fully connected layer to x_tensor using weight and bias
    : x_tensor: A 2-D tensor where the first dimension is batch size.
    : num_outputs: The number of output that the new tensor should be.
    : return: A 2-D tensor where the second dimension is num_outputs.
    """
    # TODO: Implement Function
    #return None
    dimension = x_tensor.get_shape().as_list()
    shape = list( (dimension[-1],) + (num_outputs,))
    #print(shape)
    weight = tf.Variable(tf.truncated_normal(shape,0,0.1))
    bias = tf.Variable(tf.zeros(num_outputs))
    return tf.nn.relu(tf.add(tf.matmul(x_tensor,weight), bias))



"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_fully_conn(fully_conn)
Tests Passed

Output Layer

Implement the output function to apply a fully connected layer to x_tensor with the shape (Batch Size, num_outputs). Shortcut option: you can use classes from the TensorFlow Layers or TensorFlow Layers (contrib) packages for this layer. For more of a challenge, only use other TensorFlow packages.

Note: Activation, softmax, or cross entropy should not be applied to this.

In [8]:
def output(x_tensor, num_outputs):
    """
    Apply a output layer to x_tensor using weight and bias
    : x_tensor: A 2-D tensor where the first dimension is batch size.
    : num_outputs: The number of output that the new tensor should be.
    : return: A 2-D tensor where the second dimension is num_outputs.
    """
    # TODO: Implement Function
    # return None
    dimension = x_tensor.get_shape().as_list()
    shape = list( (dimension[-1],) + (num_outputs,))
    #print(shape)
    weight = tf.Variable(tf.truncated_normal(shape,0,0.01))
    bias = tf.Variable(tf.zeros(num_outputs))
    return tf.add(tf.matmul(x_tensor,weight), bias)


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_output(output)
Tests Passed

Create Convolutional Model

Implement the function conv_net to create a convolutional neural network model. The function takes in a batch of images, x, and outputs logits. Use the layers you created above to create this model:

  • Apply 1, 2, or 3 Convolution and Max Pool layers
  • Apply a Flatten Layer
  • Apply 1, 2, or 3 Fully Connected Layers
  • Apply an Output Layer
  • Return the output
  • Apply TensorFlow's Dropout to one or more layers in the model using keep_prob.
In [9]:
def conv_net(x, keep_prob):
    """
    Create a convolutional neural network model
    : x: Placeholder tensor that holds image data.
    : keep_prob: Placeholder tensor that hold dropout keep probability.
    : return: Tensor that represents logits
    """
    # TODO: Apply 1, 2, or 3 Convolution and Max Pool layers
    #    Play around with different number of outputs, kernel size and stride
    # Function Definition from Above:
    #    conv2d_maxpool(x_tensor, conv_num_outputs, conv_ksize, conv_strides, pool_ksize, pool_strides)
    model = conv2d_maxpool(x, conv_num_outputs=18, conv_ksize=(4,4), conv_strides=(1,1), pool_ksize=(8,8), pool_strides=(1,1))
    #model = conv2d_maxpool(x, conv_num_outputs=36, conv_ksize=(4,4), conv_strides=(1,1), pool_ksize=(2,2), pool_strides=(1,1))
    #model = conv2d_maxpool(model, conv_num_outputs=8, conv_ksize=(4,4), conv_strides=(1,1), pool_ksize=(4,4), pool_strides=(1,1))
    #model = tf.nn.relu(model)
    model = tf.nn.dropout(model, keep_prob)
    
    # TODO: Apply a Flatten Layer
    # Function Definition from Above:
    #   flatten(x_tensor)
    model = flatten(model)

    # TODO: Apply 1, 2, or 3 Fully Connected Layers
    #    Play around with different number of outputs
    # Function Definition from Above:
    #   fully_conn(x_tensor, num_outputs)
    model = fully_conn(model,384)
    #model = fully_conn(model,200)
    #model = fully_conn(model,20)
    #model = tf.nn.relu(model)
    
    model = tf.nn.dropout(model, keep_prob)
    
    # TODO: Apply an Output Layer
    #    Set this to the number of classes
    # Function Definition from Above:
    #   output(x_tensor, num_outputs)
    model = output(model,10)
    
    # TODO: return output
    return model


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""

##############################
## Build the Neural Network ##
##############################

# Remove previous weights, bias, inputs, etc..
tf.reset_default_graph()

# Inputs
x = neural_net_image_input((32, 32, 3))
y = neural_net_label_input(10)
keep_prob = neural_net_keep_prob_input()

# Model
logits = conv_net(x, keep_prob)

# Name logits Tensor, so that is can be loaded from disk after training
logits = tf.identity(logits, name='logits')

# Loss and Optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
optimizer = tf.train.AdamOptimizer().minimize(cost)

# Accuracy
correct_pred = tf.equal(tf.argmax(logits, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32), name='accuracy')

tests.test_conv_net(conv_net)
Neural Network Built!

Train the Neural Network

Single Optimization

Implement the function train_neural_network to do a single optimization. The optimization should use optimizer to optimize in session with a feed_dict of the following:

  • x for image input
  • y for labels
  • keep_prob for keep probability for dropout

This function will be called for each batch, so tf.global_variables_initializer() has already been called.

Note: Nothing needs to be returned. This function is only optimizing the neural network.

In [10]:
def train_neural_network(session, optimizer, keep_probability, feature_batch, label_batch):
    """
    Optimize the session on a batch of images and labels
    : session: Current TensorFlow session
    : optimizer: TensorFlow optimizer function
    : keep_probability: keep probability
    : feature_batch: Batch of Numpy image data
    : label_batch: Batch of Numpy label data
    """
    # TODO: Implement Function
    # pass
    session.run(optimizer, feed_dict={x:feature_batch, y:label_batch, keep_prob:keep_probability})


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_train_nn(train_neural_network)
Tests Passed

Show Stats

Implement the function print_stats to print loss and validation accuracy. Use the global variables valid_features and valid_labels to calculate validation accuracy. Use a keep probability of 1.0 to calculate the loss and validation accuracy.

In [11]:
def print_stats(session, feature_batch, label_batch, cost, accuracy):
    """
    Print information about loss and validation accuracy
    : session: Current TensorFlow session
    : feature_batch: Batch of Numpy image data
    : label_batch: Batch of Numpy label data
    : cost: TensorFlow cost function
    : accuracy: TensorFlow accuracy function
    """
    # TODO: Implement Function
    # pass
    loss = session.run(cost, feed_dict={x:feature_batch, y:label_batch, keep_prob:1.0})
    valid_acc = sess.run(accuracy, feed_dict={
                x: valid_features,
                y: valid_labels,
                keep_prob: 1.})
    print('Loss: {:>10.4f} Validation Accuracy: {:.6f}'.format(
                loss,
                valid_acc))

Hyperparameters

Tune the following parameters:

  • Set epochs to the number of iterations until the network stops learning or start overfitting
  • Set batch_size to the highest number that your machine has memory for. Most people set them to common sizes of memory:
    • 64
    • 128
    • 256
    • ...
  • Set keep_probability to the probability of keeping a node using dropout
In [12]:
# TODO: Tune Parameters
epochs = 100
batch_size = 512
keep_probability = 0.3

Train on a Single CIFAR-10 Batch

Instead of training the neural network on all the CIFAR-10 batches of data, let's use a single batch. This should save time while you iterate on the model to get a better accuracy. Once the final validation accuracy is 50% or greater, run the model on all the data in the next section.

In [13]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
print('Checking the Training on a Single Batch...')
with tf.Session() as sess:
    # Initializing the variables
    sess.run(tf.global_variables_initializer())
    
    # Training cycle
    for epoch in range(epochs):
        batch_i = 1
        for batch_features, batch_labels in helper.load_preprocess_training_batch(batch_i, batch_size):
            train_neural_network(sess, optimizer, keep_probability, batch_features, batch_labels)
        print('Epoch {:>2}, CIFAR-10 Batch {}:  '.format(epoch + 1, batch_i), end='')
        print_stats(sess, batch_features, batch_labels, cost, accuracy)
Checking the Training on a Single Batch...
Epoch  1, CIFAR-10 Batch 1:  Loss:     2.2873 Validation Accuracy: 0.164200
Epoch  2, CIFAR-10 Batch 1:  Loss:     2.1182 Validation Accuracy: 0.276600
Epoch  3, CIFAR-10 Batch 1:  Loss:     1.9267 Validation Accuracy: 0.345800
Epoch  4, CIFAR-10 Batch 1:  Loss:     1.8256 Validation Accuracy: 0.373800
Epoch  5, CIFAR-10 Batch 1:  Loss:     1.7572 Validation Accuracy: 0.403400
Epoch  6, CIFAR-10 Batch 1:  Loss:     1.6871 Validation Accuracy: 0.420200
Epoch  7, CIFAR-10 Batch 1:  Loss:     1.6280 Validation Accuracy: 0.439200
Epoch  8, CIFAR-10 Batch 1:  Loss:     1.5956 Validation Accuracy: 0.440600
Epoch  9, CIFAR-10 Batch 1:  Loss:     1.5242 Validation Accuracy: 0.461200
Epoch 10, CIFAR-10 Batch 1:  Loss:     1.5036 Validation Accuracy: 0.470000
Epoch 11, CIFAR-10 Batch 1:  Loss:     1.4527 Validation Accuracy: 0.481000
Epoch 12, CIFAR-10 Batch 1:  Loss:     1.4125 Validation Accuracy: 0.494600
Epoch 13, CIFAR-10 Batch 1:  Loss:     1.3972 Validation Accuracy: 0.486200
Epoch 14, CIFAR-10 Batch 1:  Loss:     1.3589 Validation Accuracy: 0.510600
Epoch 15, CIFAR-10 Batch 1:  Loss:     1.3352 Validation Accuracy: 0.510400
Epoch 16, CIFAR-10 Batch 1:  Loss:     1.3044 Validation Accuracy: 0.520400
Epoch 17, CIFAR-10 Batch 1:  Loss:     1.2856 Validation Accuracy: 0.529000
Epoch 18, CIFAR-10 Batch 1:  Loss:     1.2628 Validation Accuracy: 0.524800
Epoch 19, CIFAR-10 Batch 1:  Loss:     1.2310 Validation Accuracy: 0.533600
Epoch 20, CIFAR-10 Batch 1:  Loss:     1.2355 Validation Accuracy: 0.533200
Epoch 21, CIFAR-10 Batch 1:  Loss:     1.1903 Validation Accuracy: 0.546800
Epoch 22, CIFAR-10 Batch 1:  Loss:     1.1644 Validation Accuracy: 0.553400
Epoch 23, CIFAR-10 Batch 1:  Loss:     1.1654 Validation Accuracy: 0.549400
Epoch 24, CIFAR-10 Batch 1:  Loss:     1.1422 Validation Accuracy: 0.555600
Epoch 25, CIFAR-10 Batch 1:  Loss:     1.1353 Validation Accuracy: 0.556600
Epoch 26, CIFAR-10 Batch 1:  Loss:     1.1028 Validation Accuracy: 0.562400
Epoch 27, CIFAR-10 Batch 1:  Loss:     1.0864 Validation Accuracy: 0.572000
Epoch 28, CIFAR-10 Batch 1:  Loss:     1.0626 Validation Accuracy: 0.567600
Epoch 29, CIFAR-10 Batch 1:  Loss:     1.0398 Validation Accuracy: 0.567200
Epoch 30, CIFAR-10 Batch 1:  Loss:     1.0362 Validation Accuracy: 0.570200
Epoch 31, CIFAR-10 Batch 1:  Loss:     1.0220 Validation Accuracy: 0.573600
Epoch 32, CIFAR-10 Batch 1:  Loss:     0.9897 Validation Accuracy: 0.576400
Epoch 33, CIFAR-10 Batch 1:  Loss:     0.9807 Validation Accuracy: 0.580000
Epoch 34, CIFAR-10 Batch 1:  Loss:     0.9611 Validation Accuracy: 0.588200
Epoch 35, CIFAR-10 Batch 1:  Loss:     0.9476 Validation Accuracy: 0.582800
Epoch 36, CIFAR-10 Batch 1:  Loss:     0.9282 Validation Accuracy: 0.590000
Epoch 37, CIFAR-10 Batch 1:  Loss:     0.9335 Validation Accuracy: 0.587600
Epoch 38, CIFAR-10 Batch 1:  Loss:     0.9129 Validation Accuracy: 0.597000
Epoch 39, CIFAR-10 Batch 1:  Loss:     0.9187 Validation Accuracy: 0.584200
Epoch 40, CIFAR-10 Batch 1:  Loss:     0.8773 Validation Accuracy: 0.604800
Epoch 41, CIFAR-10 Batch 1:  Loss:     0.8738 Validation Accuracy: 0.589600
Epoch 42, CIFAR-10 Batch 1:  Loss:     0.8597 Validation Accuracy: 0.600400
Epoch 43, CIFAR-10 Batch 1:  Loss:     0.8325 Validation Accuracy: 0.602400
Epoch 44, CIFAR-10 Batch 1:  Loss:     0.8257 Validation Accuracy: 0.607400
Epoch 45, CIFAR-10 Batch 1:  Loss:     0.8345 Validation Accuracy: 0.595400
Epoch 46, CIFAR-10 Batch 1:  Loss:     0.8021 Validation Accuracy: 0.599400
Epoch 47, CIFAR-10 Batch 1:  Loss:     0.7821 Validation Accuracy: 0.606200
Epoch 48, CIFAR-10 Batch 1:  Loss:     0.7764 Validation Accuracy: 0.602200
Epoch 49, CIFAR-10 Batch 1:  Loss:     0.7890 Validation Accuracy: 0.601200
Epoch 50, CIFAR-10 Batch 1:  Loss:     0.7825 Validation Accuracy: 0.605800
Epoch 51, CIFAR-10 Batch 1:  Loss:     0.7539 Validation Accuracy: 0.608000
Epoch 52, CIFAR-10 Batch 1:  Loss:     0.7366 Validation Accuracy: 0.604800
Epoch 53, CIFAR-10 Batch 1:  Loss:     0.7276 Validation Accuracy: 0.614600
Epoch 54, CIFAR-10 Batch 1:  Loss:     0.7023 Validation Accuracy: 0.613000
Epoch 55, CIFAR-10 Batch 1:  Loss:     0.7062 Validation Accuracy: 0.608000
Epoch 56, CIFAR-10 Batch 1:  Loss:     0.6993 Validation Accuracy: 0.612600
Epoch 57, CIFAR-10 Batch 1:  Loss:     0.6900 Validation Accuracy: 0.614800
Epoch 58, CIFAR-10 Batch 1:  Loss:     0.6802 Validation Accuracy: 0.617600
Epoch 59, CIFAR-10 Batch 1:  Loss:     0.6598 Validation Accuracy: 0.620000
Epoch 60, CIFAR-10 Batch 1:  Loss:     0.6504 Validation Accuracy: 0.613800
Epoch 61, CIFAR-10 Batch 1:  Loss:     0.6389 Validation Accuracy: 0.626400
Epoch 62, CIFAR-10 Batch 1:  Loss:     0.6401 Validation Accuracy: 0.623600
Epoch 63, CIFAR-10 Batch 1:  Loss:     0.6441 Validation Accuracy: 0.617200
Epoch 64, CIFAR-10 Batch 1:  Loss:     0.6487 Validation Accuracy: 0.611000
Epoch 65, CIFAR-10 Batch 1:  Loss:     0.6125 Validation Accuracy: 0.626800
Epoch 66, CIFAR-10 Batch 1:  Loss:     0.6131 Validation Accuracy: 0.617400
Epoch 67, CIFAR-10 Batch 1:  Loss:     0.6040 Validation Accuracy: 0.622000
Epoch 68, CIFAR-10 Batch 1:  Loss:     0.5993 Validation Accuracy: 0.623400
Epoch 69, CIFAR-10 Batch 1:  Loss:     0.5776 Validation Accuracy: 0.627800
Epoch 70, CIFAR-10 Batch 1:  Loss:     0.5647 Validation Accuracy: 0.632200
Epoch 71, CIFAR-10 Batch 1:  Loss:     0.5650 Validation Accuracy: 0.628400
Epoch 72, CIFAR-10 Batch 1:  Loss:     0.5595 Validation Accuracy: 0.634000
Epoch 73, CIFAR-10 Batch 1:  Loss:     0.5378 Validation Accuracy: 0.625000
Epoch 74, CIFAR-10 Batch 1:  Loss:     0.5307 Validation Accuracy: 0.625000
Epoch 75, CIFAR-10 Batch 1:  Loss:     0.5461 Validation Accuracy: 0.625600
Epoch 76, CIFAR-10 Batch 1:  Loss:     0.5188 Validation Accuracy: 0.635600
Epoch 77, CIFAR-10 Batch 1:  Loss:     0.4971 Validation Accuracy: 0.635000
Epoch 78, CIFAR-10 Batch 1:  Loss:     0.4946 Validation Accuracy: 0.633800
Epoch 79, CIFAR-10 Batch 1:  Loss:     0.5017 Validation Accuracy: 0.636600
Epoch 80, CIFAR-10 Batch 1:  Loss:     0.4914 Validation Accuracy: 0.635000
Epoch 81, CIFAR-10 Batch 1:  Loss:     0.5134 Validation Accuracy: 0.626000
Epoch 82, CIFAR-10 Batch 1:  Loss:     0.4576 Validation Accuracy: 0.635800
Epoch 83, CIFAR-10 Batch 1:  Loss:     0.4672 Validation Accuracy: 0.638800
Epoch 84, CIFAR-10 Batch 1:  Loss:     0.4606 Validation Accuracy: 0.637400
Epoch 85, CIFAR-10 Batch 1:  Loss:     0.4272 Validation Accuracy: 0.637600
Epoch 86, CIFAR-10 Batch 1:  Loss:     0.4270 Validation Accuracy: 0.638800
Epoch 87, CIFAR-10 Batch 1:  Loss:     0.4203 Validation Accuracy: 0.638400
Epoch 88, CIFAR-10 Batch 1:  Loss:     0.4340 Validation Accuracy: 0.634600
Epoch 89, CIFAR-10 Batch 1:  Loss:     0.4250 Validation Accuracy: 0.638400
Epoch 90, CIFAR-10 Batch 1:  Loss:     0.4141 Validation Accuracy: 0.638800
Epoch 91, CIFAR-10 Batch 1:  Loss:     0.3890 Validation Accuracy: 0.645000
Epoch 92, CIFAR-10 Batch 1:  Loss:     0.3987 Validation Accuracy: 0.637000
Epoch 93, CIFAR-10 Batch 1:  Loss:     0.4031 Validation Accuracy: 0.639200
Epoch 94, CIFAR-10 Batch 1:  Loss:     0.3873 Validation Accuracy: 0.638400
Epoch 95, CIFAR-10 Batch 1:  Loss:     0.3626 Validation Accuracy: 0.643600
Epoch 96, CIFAR-10 Batch 1:  Loss:     0.3636 Validation Accuracy: 0.641200
Epoch 97, CIFAR-10 Batch 1:  Loss:     0.3674 Validation Accuracy: 0.644200
Epoch 98, CIFAR-10 Batch 1:  Loss:     0.3645 Validation Accuracy: 0.644200
Epoch 99, CIFAR-10 Batch 1:  Loss:     0.3715 Validation Accuracy: 0.635000
Epoch 100, CIFAR-10 Batch 1:  Loss:     0.3429 Validation Accuracy: 0.641000

Fully Train the Model

Now that you got a good accuracy with a single CIFAR-10 batch, try it with all five batches.

In [14]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
save_model_path = './image_classification'

print('Training...')
with tf.Session() as sess:
    # Initializing the variables
    sess.run(tf.global_variables_initializer())
    
    # Training cycle
    for epoch in range(epochs):
        # Loop over all batches
        n_batches = 5
        for batch_i in range(1, n_batches + 1):
            for batch_features, batch_labels in helper.load_preprocess_training_batch(batch_i, batch_size):
                train_neural_network(sess, optimizer, keep_probability, batch_features, batch_labels)
            print('Epoch {:>2}, CIFAR-10 Batch {}:  '.format(epoch + 1, batch_i), end='')
            print_stats(sess, batch_features, batch_labels, cost, accuracy)
            
    # Save Model
    saver = tf.train.Saver()
    save_path = saver.save(sess, save_model_path)
Training...
Epoch  1, CIFAR-10 Batch 1:  Loss:     2.2717 Validation Accuracy: 0.228800
Epoch  1, CIFAR-10 Batch 2:  Loss:     1.9950 Validation Accuracy: 0.326800
Epoch  1, CIFAR-10 Batch 3:  Loss:     1.7954 Validation Accuracy: 0.365600
Epoch  1, CIFAR-10 Batch 4:  Loss:     1.6621 Validation Accuracy: 0.388200
Epoch  1, CIFAR-10 Batch 5:  Loss:     1.6603 Validation Accuracy: 0.397000
Epoch  2, CIFAR-10 Batch 1:  Loss:     1.6711 Validation Accuracy: 0.431600
Epoch  2, CIFAR-10 Batch 2:  Loss:     1.5443 Validation Accuracy: 0.447200
Epoch  2, CIFAR-10 Batch 3:  Loss:     1.4316 Validation Accuracy: 0.453600
Epoch  2, CIFAR-10 Batch 4:  Loss:     1.4152 Validation Accuracy: 0.473400
Epoch  2, CIFAR-10 Batch 5:  Loss:     1.4625 Validation Accuracy: 0.484000
Epoch  3, CIFAR-10 Batch 1:  Loss:     1.4737 Validation Accuracy: 0.492800
Epoch  3, CIFAR-10 Batch 2:  Loss:     1.3960 Validation Accuracy: 0.501200
Epoch  3, CIFAR-10 Batch 3:  Loss:     1.2939 Validation Accuracy: 0.508200
Epoch  3, CIFAR-10 Batch 4:  Loss:     1.2890 Validation Accuracy: 0.518400
Epoch  3, CIFAR-10 Batch 5:  Loss:     1.3079 Validation Accuracy: 0.519800
Epoch  4, CIFAR-10 Batch 1:  Loss:     1.3707 Validation Accuracy: 0.522400
Epoch  4, CIFAR-10 Batch 2:  Loss:     1.2758 Validation Accuracy: 0.540400
Epoch  4, CIFAR-10 Batch 3:  Loss:     1.1940 Validation Accuracy: 0.538000
Epoch  4, CIFAR-10 Batch 4:  Loss:     1.1875 Validation Accuracy: 0.547000
Epoch  4, CIFAR-10 Batch 5:  Loss:     1.2204 Validation Accuracy: 0.545000
Epoch  5, CIFAR-10 Batch 1:  Loss:     1.2936 Validation Accuracy: 0.559800
Epoch  5, CIFAR-10 Batch 2:  Loss:     1.1950 Validation Accuracy: 0.565600
Epoch  5, CIFAR-10 Batch 3:  Loss:     1.1409 Validation Accuracy: 0.557800
Epoch  5, CIFAR-10 Batch 4:  Loss:     1.1192 Validation Accuracy: 0.565400
Epoch  5, CIFAR-10 Batch 5:  Loss:     1.1675 Validation Accuracy: 0.571200
Epoch  6, CIFAR-10 Batch 1:  Loss:     1.2495 Validation Accuracy: 0.567200
Epoch  6, CIFAR-10 Batch 2:  Loss:     1.1466 Validation Accuracy: 0.576200
Epoch  6, CIFAR-10 Batch 3:  Loss:     1.0788 Validation Accuracy: 0.570400
Epoch  6, CIFAR-10 Batch 4:  Loss:     1.0721 Validation Accuracy: 0.585600
Epoch  6, CIFAR-10 Batch 5:  Loss:     1.1048 Validation Accuracy: 0.585600
Epoch  7, CIFAR-10 Batch 1:  Loss:     1.1964 Validation Accuracy: 0.589200
Epoch  7, CIFAR-10 Batch 2:  Loss:     1.1122 Validation Accuracy: 0.585000
Epoch  7, CIFAR-10 Batch 3:  Loss:     1.0528 Validation Accuracy: 0.573800
Epoch  7, CIFAR-10 Batch 4:  Loss:     1.0192 Validation Accuracy: 0.599400
Epoch  7, CIFAR-10 Batch 5:  Loss:     1.0826 Validation Accuracy: 0.585000
Epoch  8, CIFAR-10 Batch 1:  Loss:     1.1561 Validation Accuracy: 0.595400
Epoch  8, CIFAR-10 Batch 2:  Loss:     1.0744 Validation Accuracy: 0.607800
Epoch  8, CIFAR-10 Batch 3:  Loss:     0.9952 Validation Accuracy: 0.595400
Epoch  8, CIFAR-10 Batch 4:  Loss:     0.9764 Validation Accuracy: 0.608400
Epoch  8, CIFAR-10 Batch 5:  Loss:     1.0181 Validation Accuracy: 0.610600
Epoch  9, CIFAR-10 Batch 1:  Loss:     1.1145 Validation Accuracy: 0.611600
Epoch  9, CIFAR-10 Batch 2:  Loss:     1.0451 Validation Accuracy: 0.611200
Epoch  9, CIFAR-10 Batch 3:  Loss:     0.9565 Validation Accuracy: 0.609400
Epoch  9, CIFAR-10 Batch 4:  Loss:     0.9378 Validation Accuracy: 0.617000
Epoch  9, CIFAR-10 Batch 5:  Loss:     1.0029 Validation Accuracy: 0.617600
Epoch 10, CIFAR-10 Batch 1:  Loss:     1.1061 Validation Accuracy: 0.608800
Epoch 10, CIFAR-10 Batch 2:  Loss:     1.0193 Validation Accuracy: 0.622600
Epoch 10, CIFAR-10 Batch 3:  Loss:     0.9261 Validation Accuracy: 0.614200
Epoch 10, CIFAR-10 Batch 4:  Loss:     0.9184 Validation Accuracy: 0.626000
Epoch 10, CIFAR-10 Batch 5:  Loss:     0.9601 Validation Accuracy: 0.624800
Epoch 11, CIFAR-10 Batch 1:  Loss:     1.0759 Validation Accuracy: 0.619400
Epoch 11, CIFAR-10 Batch 2:  Loss:     0.9969 Validation Accuracy: 0.621200
Epoch 11, CIFAR-10 Batch 3:  Loss:     0.9048 Validation Accuracy: 0.618200
Epoch 11, CIFAR-10 Batch 4:  Loss:     0.8955 Validation Accuracy: 0.626600
Epoch 11, CIFAR-10 Batch 5:  Loss:     0.9491 Validation Accuracy: 0.628400
Epoch 12, CIFAR-10 Batch 1:  Loss:     1.0542 Validation Accuracy: 0.617000
Epoch 12, CIFAR-10 Batch 2:  Loss:     0.9558 Validation Accuracy: 0.633600
Epoch 12, CIFAR-10 Batch 3:  Loss:     0.8814 Validation Accuracy: 0.624600
Epoch 12, CIFAR-10 Batch 4:  Loss:     0.8793 Validation Accuracy: 0.631000
Epoch 12, CIFAR-10 Batch 5:  Loss:     0.9221 Validation Accuracy: 0.635200
Epoch 13, CIFAR-10 Batch 1:  Loss:     1.0268 Validation Accuracy: 0.639200
Epoch 13, CIFAR-10 Batch 2:  Loss:     0.9660 Validation Accuracy: 0.635600
Epoch 13, CIFAR-10 Batch 3:  Loss:     0.8614 Validation Accuracy: 0.633400
Epoch 13, CIFAR-10 Batch 4:  Loss:     0.8512 Validation Accuracy: 0.638200
Epoch 13, CIFAR-10 Batch 5:  Loss:     0.9115 Validation Accuracy: 0.639800
Epoch 14, CIFAR-10 Batch 1:  Loss:     0.9792 Validation Accuracy: 0.642000
Epoch 14, CIFAR-10 Batch 2:  Loss:     0.9244 Validation Accuracy: 0.635000
Epoch 14, CIFAR-10 Batch 3:  Loss:     0.8447 Validation Accuracy: 0.633600
Epoch 14, CIFAR-10 Batch 4:  Loss:     0.8324 Validation Accuracy: 0.639200
Epoch 14, CIFAR-10 Batch 5:  Loss:     0.8980 Validation Accuracy: 0.642200
Epoch 15, CIFAR-10 Batch 1:  Loss:     0.9839 Validation Accuracy: 0.646800
Epoch 15, CIFAR-10 Batch 2:  Loss:     0.9070 Validation Accuracy: 0.644800
Epoch 15, CIFAR-10 Batch 3:  Loss:     0.8385 Validation Accuracy: 0.632800
Epoch 15, CIFAR-10 Batch 4:  Loss:     0.8211 Validation Accuracy: 0.649200
Epoch 15, CIFAR-10 Batch 5:  Loss:     0.8685 Validation Accuracy: 0.645600
Epoch 16, CIFAR-10 Batch 1:  Loss:     0.9565 Validation Accuracy: 0.644400
Epoch 16, CIFAR-10 Batch 2:  Loss:     0.8971 Validation Accuracy: 0.646200
Epoch 16, CIFAR-10 Batch 3:  Loss:     0.8234 Validation Accuracy: 0.639400
Epoch 16, CIFAR-10 Batch 4:  Loss:     0.8077 Validation Accuracy: 0.649200
Epoch 16, CIFAR-10 Batch 5:  Loss:     0.8618 Validation Accuracy: 0.650400
Epoch 17, CIFAR-10 Batch 1:  Loss:     0.9333 Validation Accuracy: 0.651200
Epoch 17, CIFAR-10 Batch 2:  Loss:     0.8859 Validation Accuracy: 0.651200
Epoch 17, CIFAR-10 Batch 3:  Loss:     0.8161 Validation Accuracy: 0.643800
Epoch 17, CIFAR-10 Batch 4:  Loss:     0.8004 Validation Accuracy: 0.650400
Epoch 17, CIFAR-10 Batch 5:  Loss:     0.8362 Validation Accuracy: 0.647400
Epoch 18, CIFAR-10 Batch 1:  Loss:     0.9646 Validation Accuracy: 0.649800
Epoch 18, CIFAR-10 Batch 2:  Loss:     0.8772 Validation Accuracy: 0.644000
Epoch 18, CIFAR-10 Batch 3:  Loss:     0.8065 Validation Accuracy: 0.640400
Epoch 18, CIFAR-10 Batch 4:  Loss:     0.7802 Validation Accuracy: 0.654000
Epoch 18, CIFAR-10 Batch 5:  Loss:     0.8206 Validation Accuracy: 0.654800
Epoch 19, CIFAR-10 Batch 1:  Loss:     0.9264 Validation Accuracy: 0.661000
Epoch 19, CIFAR-10 Batch 2:  Loss:     0.8566 Validation Accuracy: 0.654400
Epoch 19, CIFAR-10 Batch 3:  Loss:     0.7740 Validation Accuracy: 0.648200
Epoch 19, CIFAR-10 Batch 4:  Loss:     0.7534 Validation Accuracy: 0.657600
Epoch 19, CIFAR-10 Batch 5:  Loss:     0.7986 Validation Accuracy: 0.654000
Epoch 20, CIFAR-10 Batch 1:  Loss:     0.9027 Validation Accuracy: 0.652800
Epoch 20, CIFAR-10 Batch 2:  Loss:     0.8394 Validation Accuracy: 0.658000
Epoch 20, CIFAR-10 Batch 3:  Loss:     0.7775 Validation Accuracy: 0.649200
Epoch 20, CIFAR-10 Batch 4:  Loss:     0.7467 Validation Accuracy: 0.661800
Epoch 20, CIFAR-10 Batch 5:  Loss:     0.8032 Validation Accuracy: 0.648400
Epoch 21, CIFAR-10 Batch 1:  Loss:     0.8771 Validation Accuracy: 0.655600
Epoch 21, CIFAR-10 Batch 2:  Loss:     0.8202 Validation Accuracy: 0.661600
Epoch 21, CIFAR-10 Batch 3:  Loss:     0.7854 Validation Accuracy: 0.648600
Epoch 21, CIFAR-10 Batch 4:  Loss:     0.7303 Validation Accuracy: 0.661400
Epoch 21, CIFAR-10 Batch 5:  Loss:     0.7712 Validation Accuracy: 0.661800
Epoch 22, CIFAR-10 Batch 1:  Loss:     0.8762 Validation Accuracy: 0.654200
Epoch 22, CIFAR-10 Batch 2:  Loss:     0.8050 Validation Accuracy: 0.660200
Epoch 22, CIFAR-10 Batch 3:  Loss:     0.7569 Validation Accuracy: 0.656000
Epoch 22, CIFAR-10 Batch 4:  Loss:     0.7419 Validation Accuracy: 0.653800
Epoch 22, CIFAR-10 Batch 5:  Loss:     0.7836 Validation Accuracy: 0.659200
Epoch 23, CIFAR-10 Batch 1:  Loss:     0.8692 Validation Accuracy: 0.646800
Epoch 23, CIFAR-10 Batch 2:  Loss:     0.8203 Validation Accuracy: 0.658200
Epoch 23, CIFAR-10 Batch 3:  Loss:     0.7317 Validation Accuracy: 0.651400
Epoch 23, CIFAR-10 Batch 4:  Loss:     0.7439 Validation Accuracy: 0.658800
Epoch 23, CIFAR-10 Batch 5:  Loss:     0.7624 Validation Accuracy: 0.661400
Epoch 24, CIFAR-10 Batch 1:  Loss:     0.8509 Validation Accuracy: 0.662000
Epoch 24, CIFAR-10 Batch 2:  Loss:     0.7992 Validation Accuracy: 0.664400
Epoch 24, CIFAR-10 Batch 3:  Loss:     0.7212 Validation Accuracy: 0.662000
Epoch 24, CIFAR-10 Batch 4:  Loss:     0.7151 Validation Accuracy: 0.672800
Epoch 24, CIFAR-10 Batch 5:  Loss:     0.7467 Validation Accuracy: 0.669600
Epoch 25, CIFAR-10 Batch 1:  Loss:     0.8241 Validation Accuracy: 0.673600
Epoch 25, CIFAR-10 Batch 2:  Loss:     0.7793 Validation Accuracy: 0.671000
Epoch 25, CIFAR-10 Batch 3:  Loss:     0.7406 Validation Accuracy: 0.662400
Epoch 25, CIFAR-10 Batch 4:  Loss:     0.6980 Validation Accuracy: 0.672200
Epoch 25, CIFAR-10 Batch 5:  Loss:     0.7435 Validation Accuracy: 0.657000
Epoch 26, CIFAR-10 Batch 1:  Loss:     0.8146 Validation Accuracy: 0.664400
Epoch 26, CIFAR-10 Batch 2:  Loss:     0.7696 Validation Accuracy: 0.675600
Epoch 26, CIFAR-10 Batch 3:  Loss:     0.7121 Validation Accuracy: 0.664800
Epoch 26, CIFAR-10 Batch 4:  Loss:     0.6887 Validation Accuracy: 0.672200
Epoch 26, CIFAR-10 Batch 5:  Loss:     0.7199 Validation Accuracy: 0.665200
Epoch 27, CIFAR-10 Batch 1:  Loss:     0.8092 Validation Accuracy: 0.675600
Epoch 27, CIFAR-10 Batch 2:  Loss:     0.7615 Validation Accuracy: 0.668200
Epoch 27, CIFAR-10 Batch 3:  Loss:     0.7389 Validation Accuracy: 0.661000
Epoch 27, CIFAR-10 Batch 4:  Loss:     0.6818 Validation Accuracy: 0.672200
Epoch 27, CIFAR-10 Batch 5:  Loss:     0.7275 Validation Accuracy: 0.669400
Epoch 28, CIFAR-10 Batch 1:  Loss:     0.7839 Validation Accuracy: 0.667600
Epoch 28, CIFAR-10 Batch 2:  Loss:     0.7562 Validation Accuracy: 0.673400
Epoch 28, CIFAR-10 Batch 3:  Loss:     0.7017 Validation Accuracy: 0.666600
Epoch 28, CIFAR-10 Batch 4:  Loss:     0.6821 Validation Accuracy: 0.669200
Epoch 28, CIFAR-10 Batch 5:  Loss:     0.7011 Validation Accuracy: 0.669600
Epoch 29, CIFAR-10 Batch 1:  Loss:     0.7888 Validation Accuracy: 0.669000
Epoch 29, CIFAR-10 Batch 2:  Loss:     0.7492 Validation Accuracy: 0.674000
Epoch 29, CIFAR-10 Batch 3:  Loss:     0.6898 Validation Accuracy: 0.669400
Epoch 29, CIFAR-10 Batch 4:  Loss:     0.6591 Validation Accuracy: 0.676400
Epoch 29, CIFAR-10 Batch 5:  Loss:     0.7166 Validation Accuracy: 0.672600
Epoch 30, CIFAR-10 Batch 1:  Loss:     0.7737 Validation Accuracy: 0.671200
Epoch 30, CIFAR-10 Batch 2:  Loss:     0.7394 Validation Accuracy: 0.674000
Epoch 30, CIFAR-10 Batch 3:  Loss:     0.6808 Validation Accuracy: 0.673200
Epoch 30, CIFAR-10 Batch 4:  Loss:     0.6700 Validation Accuracy: 0.676200
Epoch 30, CIFAR-10 Batch 5:  Loss:     0.7070 Validation Accuracy: 0.674000
Epoch 31, CIFAR-10 Batch 1:  Loss:     0.7529 Validation Accuracy: 0.675400
Epoch 31, CIFAR-10 Batch 2:  Loss:     0.7278 Validation Accuracy: 0.676000
Epoch 31, CIFAR-10 Batch 3:  Loss:     0.6679 Validation Accuracy: 0.675400
Epoch 31, CIFAR-10 Batch 4:  Loss:     0.6528 Validation Accuracy: 0.681200
Epoch 31, CIFAR-10 Batch 5:  Loss:     0.6978 Validation Accuracy: 0.673800
Epoch 32, CIFAR-10 Batch 1:  Loss:     0.7396 Validation Accuracy: 0.678400
Epoch 32, CIFAR-10 Batch 2:  Loss:     0.7198 Validation Accuracy: 0.677600
Epoch 32, CIFAR-10 Batch 3:  Loss:     0.6820 Validation Accuracy: 0.675600
Epoch 32, CIFAR-10 Batch 4:  Loss:     0.6486 Validation Accuracy: 0.676600
Epoch 32, CIFAR-10 Batch 5:  Loss:     0.6833 Validation Accuracy: 0.676800
Epoch 33, CIFAR-10 Batch 1:  Loss:     0.7175 Validation Accuracy: 0.677800
Epoch 33, CIFAR-10 Batch 2:  Loss:     0.7231 Validation Accuracy: 0.678200
Epoch 33, CIFAR-10 Batch 3:  Loss:     0.6817 Validation Accuracy: 0.672400
Epoch 33, CIFAR-10 Batch 4:  Loss:     0.6294 Validation Accuracy: 0.678400
Epoch 33, CIFAR-10 Batch 5:  Loss:     0.6640 Validation Accuracy: 0.673200
Epoch 34, CIFAR-10 Batch 1:  Loss:     0.7321 Validation Accuracy: 0.667200
Epoch 34, CIFAR-10 Batch 2:  Loss:     0.7022 Validation Accuracy: 0.677000
Epoch 34, CIFAR-10 Batch 3:  Loss:     0.6618 Validation Accuracy: 0.678600
Epoch 34, CIFAR-10 Batch 4:  Loss:     0.6467 Validation Accuracy: 0.678800
Epoch 34, CIFAR-10 Batch 5:  Loss:     0.6645 Validation Accuracy: 0.674400
Epoch 35, CIFAR-10 Batch 1:  Loss:     0.7278 Validation Accuracy: 0.686400
Epoch 35, CIFAR-10 Batch 2:  Loss:     0.7103 Validation Accuracy: 0.677000
Epoch 35, CIFAR-10 Batch 3:  Loss:     0.6420 Validation Accuracy: 0.678200
Epoch 35, CIFAR-10 Batch 4:  Loss:     0.6275 Validation Accuracy: 0.682200
Epoch 35, CIFAR-10 Batch 5:  Loss:     0.6536 Validation Accuracy: 0.681200
Epoch 36, CIFAR-10 Batch 1:  Loss:     0.7157 Validation Accuracy: 0.675600
Epoch 36, CIFAR-10 Batch 2:  Loss:     0.6937 Validation Accuracy: 0.678200
Epoch 36, CIFAR-10 Batch 3:  Loss:     0.6436 Validation Accuracy: 0.677400
Epoch 36, CIFAR-10 Batch 4:  Loss:     0.6138 Validation Accuracy: 0.687800
Epoch 36, CIFAR-10 Batch 5:  Loss:     0.6314 Validation Accuracy: 0.679600
Epoch 37, CIFAR-10 Batch 1:  Loss:     0.7052 Validation Accuracy: 0.683200
Epoch 37, CIFAR-10 Batch 2:  Loss:     0.6719 Validation Accuracy: 0.678200
Epoch 37, CIFAR-10 Batch 3:  Loss:     0.6342 Validation Accuracy: 0.680400
Epoch 37, CIFAR-10 Batch 4:  Loss:     0.6307 Validation Accuracy: 0.676600
Epoch 37, CIFAR-10 Batch 5:  Loss:     0.6430 Validation Accuracy: 0.677800
Epoch 38, CIFAR-10 Batch 1:  Loss:     0.7100 Validation Accuracy: 0.677400
Epoch 38, CIFAR-10 Batch 2:  Loss:     0.6794 Validation Accuracy: 0.688400
Epoch 38, CIFAR-10 Batch 3:  Loss:     0.6401 Validation Accuracy: 0.674600
Epoch 38, CIFAR-10 Batch 4:  Loss:     0.6034 Validation Accuracy: 0.685200
Epoch 38, CIFAR-10 Batch 5:  Loss:     0.6297 Validation Accuracy: 0.676800
Epoch 39, CIFAR-10 Batch 1:  Loss:     0.6983 Validation Accuracy: 0.674400
Epoch 39, CIFAR-10 Batch 2:  Loss:     0.6510 Validation Accuracy: 0.685600
Epoch 39, CIFAR-10 Batch 3:  Loss:     0.6402 Validation Accuracy: 0.671400
Epoch 39, CIFAR-10 Batch 4:  Loss:     0.6011 Validation Accuracy: 0.685200
Epoch 39, CIFAR-10 Batch 5:  Loss:     0.6375 Validation Accuracy: 0.675600
Epoch 40, CIFAR-10 Batch 1:  Loss:     0.6822 Validation Accuracy: 0.682200
Epoch 40, CIFAR-10 Batch 2:  Loss:     0.6587 Validation Accuracy: 0.691000
Epoch 40, CIFAR-10 Batch 3:  Loss:     0.6296 Validation Accuracy: 0.681200
Epoch 40, CIFAR-10 Batch 4:  Loss:     0.5864 Validation Accuracy: 0.685800
Epoch 40, CIFAR-10 Batch 5:  Loss:     0.6140 Validation Accuracy: 0.682400
Epoch 41, CIFAR-10 Batch 1:  Loss:     0.6794 Validation Accuracy: 0.680400
Epoch 41, CIFAR-10 Batch 2:  Loss:     0.6675 Validation Accuracy: 0.693800
Epoch 41, CIFAR-10 Batch 3:  Loss:     0.6135 Validation Accuracy: 0.681400
Epoch 41, CIFAR-10 Batch 4:  Loss:     0.5812 Validation Accuracy: 0.690600
Epoch 41, CIFAR-10 Batch 5:  Loss:     0.6084 Validation Accuracy: 0.688400
Epoch 42, CIFAR-10 Batch 1:  Loss:     0.6655 Validation Accuracy: 0.682200
Epoch 42, CIFAR-10 Batch 2:  Loss:     0.6624 Validation Accuracy: 0.694600
Epoch 42, CIFAR-10 Batch 3:  Loss:     0.6247 Validation Accuracy: 0.677600
Epoch 42, CIFAR-10 Batch 4:  Loss:     0.5777 Validation Accuracy: 0.690400
Epoch 42, CIFAR-10 Batch 5:  Loss:     0.6063 Validation Accuracy: 0.680600
Epoch 43, CIFAR-10 Batch 1:  Loss:     0.6518 Validation Accuracy: 0.690200
Epoch 43, CIFAR-10 Batch 2:  Loss:     0.6564 Validation Accuracy: 0.692800
Epoch 43, CIFAR-10 Batch 3:  Loss:     0.6066 Validation Accuracy: 0.689400
Epoch 43, CIFAR-10 Batch 4:  Loss:     0.5765 Validation Accuracy: 0.683600
Epoch 43, CIFAR-10 Batch 5:  Loss:     0.5927 Validation Accuracy: 0.688000
Epoch 44, CIFAR-10 Batch 1:  Loss:     0.6479 Validation Accuracy: 0.691600
Epoch 44, CIFAR-10 Batch 2:  Loss:     0.6372 Validation Accuracy: 0.687400
Epoch 44, CIFAR-10 Batch 3:  Loss:     0.5895 Validation Accuracy: 0.689000
Epoch 44, CIFAR-10 Batch 4:  Loss:     0.5568 Validation Accuracy: 0.691600
Epoch 44, CIFAR-10 Batch 5:  Loss:     0.5846 Validation Accuracy: 0.682600
Epoch 45, CIFAR-10 Batch 1:  Loss:     0.6543 Validation Accuracy: 0.690600
Epoch 45, CIFAR-10 Batch 2:  Loss:     0.6307 Validation Accuracy: 0.695000
Epoch 45, CIFAR-10 Batch 3:  Loss:     0.5906 Validation Accuracy: 0.694400
Epoch 45, CIFAR-10 Batch 4:  Loss:     0.5606 Validation Accuracy: 0.693200
Epoch 45, CIFAR-10 Batch 5:  Loss:     0.5936 Validation Accuracy: 0.690000
Epoch 46, CIFAR-10 Batch 1:  Loss:     0.6443 Validation Accuracy: 0.682800
Epoch 46, CIFAR-10 Batch 2:  Loss:     0.6299 Validation Accuracy: 0.692400
Epoch 46, CIFAR-10 Batch 3:  Loss:     0.6112 Validation Accuracy: 0.687400
Epoch 46, CIFAR-10 Batch 4:  Loss:     0.5439 Validation Accuracy: 0.697600
Epoch 46, CIFAR-10 Batch 5:  Loss:     0.5743 Validation Accuracy: 0.694400
Epoch 47, CIFAR-10 Batch 1:  Loss:     0.6506 Validation Accuracy: 0.694800
Epoch 47, CIFAR-10 Batch 2:  Loss:     0.6308 Validation Accuracy: 0.694400
Epoch 47, CIFAR-10 Batch 3:  Loss:     0.6063 Validation Accuracy: 0.687200
Epoch 47, CIFAR-10 Batch 4:  Loss:     0.5351 Validation Accuracy: 0.694200
Epoch 47, CIFAR-10 Batch 5:  Loss:     0.5855 Validation Accuracy: 0.689200
Epoch 48, CIFAR-10 Batch 1:  Loss:     0.6401 Validation Accuracy: 0.690600
Epoch 48, CIFAR-10 Batch 2:  Loss:     0.6238 Validation Accuracy: 0.697800
Epoch 48, CIFAR-10 Batch 3:  Loss:     0.5835 Validation Accuracy: 0.692400
Epoch 48, CIFAR-10 Batch 4:  Loss:     0.5215 Validation Accuracy: 0.693200
Epoch 48, CIFAR-10 Batch 5:  Loss:     0.5705 Validation Accuracy: 0.691200
Epoch 49, CIFAR-10 Batch 1:  Loss:     0.6273 Validation Accuracy: 0.692000
Epoch 49, CIFAR-10 Batch 2:  Loss:     0.6062 Validation Accuracy: 0.693000
Epoch 49, CIFAR-10 Batch 3:  Loss:     0.5852 Validation Accuracy: 0.688400
Epoch 49, CIFAR-10 Batch 4:  Loss:     0.5442 Validation Accuracy: 0.698200
Epoch 49, CIFAR-10 Batch 5:  Loss:     0.5457 Validation Accuracy: 0.691000
Epoch 50, CIFAR-10 Batch 1:  Loss:     0.6160 Validation Accuracy: 0.695800
Epoch 50, CIFAR-10 Batch 2:  Loss:     0.6056 Validation Accuracy: 0.697200
Epoch 50, CIFAR-10 Batch 3:  Loss:     0.5974 Validation Accuracy: 0.690000
Epoch 50, CIFAR-10 Batch 4:  Loss:     0.5563 Validation Accuracy: 0.690200
Epoch 50, CIFAR-10 Batch 5:  Loss:     0.5562 Validation Accuracy: 0.693800
Epoch 51, CIFAR-10 Batch 1:  Loss:     0.6157 Validation Accuracy: 0.695000
Epoch 51, CIFAR-10 Batch 2:  Loss:     0.6018 Validation Accuracy: 0.693000
Epoch 51, CIFAR-10 Batch 3:  Loss:     0.5866 Validation Accuracy: 0.691000
Epoch 51, CIFAR-10 Batch 4:  Loss:     0.5258 Validation Accuracy: 0.693800
Epoch 51, CIFAR-10 Batch 5:  Loss:     0.5272 Validation Accuracy: 0.694200
Epoch 52, CIFAR-10 Batch 1:  Loss:     0.6006 Validation Accuracy: 0.698800
Epoch 52, CIFAR-10 Batch 2:  Loss:     0.5968 Validation Accuracy: 0.698200
Epoch 52, CIFAR-10 Batch 3:  Loss:     0.5803 Validation Accuracy: 0.689600
Epoch 52, CIFAR-10 Batch 4:  Loss:     0.5381 Validation Accuracy: 0.688400
Epoch 52, CIFAR-10 Batch 5:  Loss:     0.5321 Validation Accuracy: 0.693600
Epoch 53, CIFAR-10 Batch 1:  Loss:     0.5921 Validation Accuracy: 0.693600
Epoch 53, CIFAR-10 Batch 2:  Loss:     0.6084 Validation Accuracy: 0.683000
Epoch 53, CIFAR-10 Batch 3:  Loss:     0.5728 Validation Accuracy: 0.689800
Epoch 53, CIFAR-10 Batch 4:  Loss:     0.5191 Validation Accuracy: 0.691000
Epoch 53, CIFAR-10 Batch 5:  Loss:     0.5390 Validation Accuracy: 0.695600
Epoch 54, CIFAR-10 Batch 1:  Loss:     0.5776 Validation Accuracy: 0.697400
Epoch 54, CIFAR-10 Batch 2:  Loss:     0.5849 Validation Accuracy: 0.694800
Epoch 54, CIFAR-10 Batch 3:  Loss:     0.5593 Validation Accuracy: 0.692600
Epoch 54, CIFAR-10 Batch 4:  Loss:     0.5272 Validation Accuracy: 0.687800
Epoch 54, CIFAR-10 Batch 5:  Loss:     0.5568 Validation Accuracy: 0.694400
Epoch 55, CIFAR-10 Batch 1:  Loss:     0.5804 Validation Accuracy: 0.698600
Epoch 55, CIFAR-10 Batch 2:  Loss:     0.5931 Validation Accuracy: 0.693600
Epoch 55, CIFAR-10 Batch 3:  Loss:     0.5485 Validation Accuracy: 0.693400
Epoch 55, CIFAR-10 Batch 4:  Loss:     0.5265 Validation Accuracy: 0.691600
Epoch 55, CIFAR-10 Batch 5:  Loss:     0.5519 Validation Accuracy: 0.693600
Epoch 56, CIFAR-10 Batch 1:  Loss:     0.5852 Validation Accuracy: 0.695200
Epoch 56, CIFAR-10 Batch 2:  Loss:     0.5940 Validation Accuracy: 0.696000
Epoch 56, CIFAR-10 Batch 3:  Loss:     0.5630 Validation Accuracy: 0.694200
Epoch 56, CIFAR-10 Batch 4:  Loss:     0.5087 Validation Accuracy: 0.694800
Epoch 56, CIFAR-10 Batch 5:  Loss:     0.5154 Validation Accuracy: 0.700400
Epoch 57, CIFAR-10 Batch 1:  Loss:     0.5864 Validation Accuracy: 0.701200
Epoch 57, CIFAR-10 Batch 2:  Loss:     0.5770 Validation Accuracy: 0.697000
Epoch 57, CIFAR-10 Batch 3:  Loss:     0.5455 Validation Accuracy: 0.696800
Epoch 57, CIFAR-10 Batch 4:  Loss:     0.5026 Validation Accuracy: 0.695200
Epoch 57, CIFAR-10 Batch 5:  Loss:     0.5223 Validation Accuracy: 0.691800
Epoch 58, CIFAR-10 Batch 1:  Loss:     0.5550 Validation Accuracy: 0.700800
Epoch 58, CIFAR-10 Batch 2:  Loss:     0.5658 Validation Accuracy: 0.699600
Epoch 58, CIFAR-10 Batch 3:  Loss:     0.5437 Validation Accuracy: 0.694200
Epoch 58, CIFAR-10 Batch 4:  Loss:     0.5066 Validation Accuracy: 0.699200
Epoch 58, CIFAR-10 Batch 5:  Loss:     0.5128 Validation Accuracy: 0.698800
Epoch 59, CIFAR-10 Batch 1:  Loss:     0.5671 Validation Accuracy: 0.695200
Epoch 59, CIFAR-10 Batch 2:  Loss:     0.5550 Validation Accuracy: 0.699800
Epoch 59, CIFAR-10 Batch 3:  Loss:     0.5446 Validation Accuracy: 0.693600
Epoch 59, CIFAR-10 Batch 4:  Loss:     0.4932 Validation Accuracy: 0.693200
Epoch 59, CIFAR-10 Batch 5:  Loss:     0.5290 Validation Accuracy: 0.695200
Epoch 60, CIFAR-10 Batch 1:  Loss:     0.5582 Validation Accuracy: 0.692200
Epoch 60, CIFAR-10 Batch 2:  Loss:     0.5573 Validation Accuracy: 0.700000
Epoch 60, CIFAR-10 Batch 3:  Loss:     0.5350 Validation Accuracy: 0.688200
Epoch 60, CIFAR-10 Batch 4:  Loss:     0.4937 Validation Accuracy: 0.693800
Epoch 60, CIFAR-10 Batch 5:  Loss:     0.5096 Validation Accuracy: 0.696800
Epoch 61, CIFAR-10 Batch 1:  Loss:     0.5432 Validation Accuracy: 0.697000
Epoch 61, CIFAR-10 Batch 2:  Loss:     0.5477 Validation Accuracy: 0.703200
Epoch 61, CIFAR-10 Batch 3:  Loss:     0.5154 Validation Accuracy: 0.695800
Epoch 61, CIFAR-10 Batch 4:  Loss:     0.4816 Validation Accuracy: 0.705800
Epoch 61, CIFAR-10 Batch 5:  Loss:     0.5007 Validation Accuracy: 0.700600
Epoch 62, CIFAR-10 Batch 1:  Loss:     0.5274 Validation Accuracy: 0.695600
Epoch 62, CIFAR-10 Batch 2:  Loss:     0.5560 Validation Accuracy: 0.687400
Epoch 62, CIFAR-10 Batch 3:  Loss:     0.5555 Validation Accuracy: 0.689800
Epoch 62, CIFAR-10 Batch 4:  Loss:     0.4723 Validation Accuracy: 0.700400
Epoch 62, CIFAR-10 Batch 5:  Loss:     0.4883 Validation Accuracy: 0.700800
Epoch 63, CIFAR-10 Batch 1:  Loss:     0.5600 Validation Accuracy: 0.696400
Epoch 63, CIFAR-10 Batch 2:  Loss:     0.5493 Validation Accuracy: 0.701200
Epoch 63, CIFAR-10 Batch 3:  Loss:     0.5183 Validation Accuracy: 0.699600
Epoch 63, CIFAR-10 Batch 4:  Loss:     0.4668 Validation Accuracy: 0.706400
Epoch 63, CIFAR-10 Batch 5:  Loss:     0.4987 Validation Accuracy: 0.698600
Epoch 64, CIFAR-10 Batch 1:  Loss:     0.5235 Validation Accuracy: 0.702600
Epoch 64, CIFAR-10 Batch 2:  Loss:     0.5294 Validation Accuracy: 0.702200
Epoch 64, CIFAR-10 Batch 3:  Loss:     0.5285 Validation Accuracy: 0.693200
Epoch 64, CIFAR-10 Batch 4:  Loss:     0.4750 Validation Accuracy: 0.699600
Epoch 64, CIFAR-10 Batch 5:  Loss:     0.4927 Validation Accuracy: 0.704000
Epoch 65, CIFAR-10 Batch 1:  Loss:     0.5247 Validation Accuracy: 0.696000
Epoch 65, CIFAR-10 Batch 2:  Loss:     0.5383 Validation Accuracy: 0.699600
Epoch 65, CIFAR-10 Batch 3:  Loss:     0.5118 Validation Accuracy: 0.695800
Epoch 65, CIFAR-10 Batch 4:  Loss:     0.4672 Validation Accuracy: 0.699000
Epoch 65, CIFAR-10 Batch 5:  Loss:     0.4779 Validation Accuracy: 0.699400
Epoch 66, CIFAR-10 Batch 1:  Loss:     0.5251 Validation Accuracy: 0.703600
Epoch 66, CIFAR-10 Batch 2:  Loss:     0.5514 Validation Accuracy: 0.701800
Epoch 66, CIFAR-10 Batch 3:  Loss:     0.5123 Validation Accuracy: 0.694200
Epoch 66, CIFAR-10 Batch 4:  Loss:     0.4462 Validation Accuracy: 0.696800
Epoch 66, CIFAR-10 Batch 5:  Loss:     0.4696 Validation Accuracy: 0.699400
Epoch 67, CIFAR-10 Batch 1:  Loss:     0.5317 Validation Accuracy: 0.703200
Epoch 67, CIFAR-10 Batch 2:  Loss:     0.5532 Validation Accuracy: 0.702600
Epoch 67, CIFAR-10 Batch 3:  Loss:     0.5209 Validation Accuracy: 0.696200
Epoch 67, CIFAR-10 Batch 4:  Loss:     0.4571 Validation Accuracy: 0.694800
Epoch 67, CIFAR-10 Batch 5:  Loss:     0.4896 Validation Accuracy: 0.698000
Epoch 68, CIFAR-10 Batch 1:  Loss:     0.5025 Validation Accuracy: 0.703400
Epoch 68, CIFAR-10 Batch 2:  Loss:     0.5262 Validation Accuracy: 0.699800
Epoch 68, CIFAR-10 Batch 3:  Loss:     0.5124 Validation Accuracy: 0.696800
Epoch 68, CIFAR-10 Batch 4:  Loss:     0.4716 Validation Accuracy: 0.699400
Epoch 68, CIFAR-10 Batch 5:  Loss:     0.4712 Validation Accuracy: 0.702600
Epoch 69, CIFAR-10 Batch 1:  Loss:     0.4952 Validation Accuracy: 0.705200
Epoch 69, CIFAR-10 Batch 2:  Loss:     0.5123 Validation Accuracy: 0.700600
Epoch 69, CIFAR-10 Batch 3:  Loss:     0.4915 Validation Accuracy: 0.703200
Epoch 69, CIFAR-10 Batch 4:  Loss:     0.4558 Validation Accuracy: 0.702600
Epoch 69, CIFAR-10 Batch 5:  Loss:     0.4679 Validation Accuracy: 0.705600
Epoch 70, CIFAR-10 Batch 1:  Loss:     0.5059 Validation Accuracy: 0.700800
Epoch 70, CIFAR-10 Batch 2:  Loss:     0.5108 Validation Accuracy: 0.705000
Epoch 70, CIFAR-10 Batch 3:  Loss:     0.4899 Validation Accuracy: 0.698000
Epoch 70, CIFAR-10 Batch 4:  Loss:     0.4502 Validation Accuracy: 0.698800
Epoch 70, CIFAR-10 Batch 5:  Loss:     0.4634 Validation Accuracy: 0.701200
Epoch 71, CIFAR-10 Batch 1:  Loss:     0.5183 Validation Accuracy: 0.704400
Epoch 71, CIFAR-10 Batch 2:  Loss:     0.5265 Validation Accuracy: 0.702400
Epoch 71, CIFAR-10 Batch 3:  Loss:     0.4953 Validation Accuracy: 0.698400
Epoch 71, CIFAR-10 Batch 4:  Loss:     0.4419 Validation Accuracy: 0.698800
Epoch 71, CIFAR-10 Batch 5:  Loss:     0.4681 Validation Accuracy: 0.702200
Epoch 72, CIFAR-10 Batch 1:  Loss:     0.5108 Validation Accuracy: 0.701800
Epoch 72, CIFAR-10 Batch 2:  Loss:     0.5121 Validation Accuracy: 0.703400
Epoch 72, CIFAR-10 Batch 3:  Loss:     0.4930 Validation Accuracy: 0.696400
Epoch 72, CIFAR-10 Batch 4:  Loss:     0.4240 Validation Accuracy: 0.704200
Epoch 72, CIFAR-10 Batch 5:  Loss:     0.4551 Validation Accuracy: 0.704000
Epoch 73, CIFAR-10 Batch 1:  Loss:     0.4928 Validation Accuracy: 0.707400
Epoch 73, CIFAR-10 Batch 2:  Loss:     0.5201 Validation Accuracy: 0.702800
Epoch 73, CIFAR-10 Batch 3:  Loss:     0.4910 Validation Accuracy: 0.702400
Epoch 73, CIFAR-10 Batch 4:  Loss:     0.4393 Validation Accuracy: 0.699800
Epoch 73, CIFAR-10 Batch 5:  Loss:     0.4629 Validation Accuracy: 0.702000
Epoch 74, CIFAR-10 Batch 1:  Loss:     0.4916 Validation Accuracy: 0.700400
Epoch 74, CIFAR-10 Batch 2:  Loss:     0.4824 Validation Accuracy: 0.704600
Epoch 74, CIFAR-10 Batch 3:  Loss:     0.4753 Validation Accuracy: 0.704400
Epoch 74, CIFAR-10 Batch 4:  Loss:     0.4321 Validation Accuracy: 0.702200
Epoch 74, CIFAR-10 Batch 5:  Loss:     0.4368 Validation Accuracy: 0.701600
Epoch 75, CIFAR-10 Batch 1:  Loss:     0.4816 Validation Accuracy: 0.701800
Epoch 75, CIFAR-10 Batch 2:  Loss:     0.4955 Validation Accuracy: 0.704000
Epoch 75, CIFAR-10 Batch 3:  Loss:     0.4702 Validation Accuracy: 0.698200
Epoch 75, CIFAR-10 Batch 4:  Loss:     0.4337 Validation Accuracy: 0.698200
Epoch 75, CIFAR-10 Batch 5:  Loss:     0.4512 Validation Accuracy: 0.704000
Epoch 76, CIFAR-10 Batch 1:  Loss:     0.4818 Validation Accuracy: 0.708600
Epoch 76, CIFAR-10 Batch 2:  Loss:     0.4941 Validation Accuracy: 0.706200
Epoch 76, CIFAR-10 Batch 3:  Loss:     0.4729 Validation Accuracy: 0.704800
Epoch 76, CIFAR-10 Batch 4:  Loss:     0.4245 Validation Accuracy: 0.698800
Epoch 76, CIFAR-10 Batch 5:  Loss:     0.4508 Validation Accuracy: 0.700000
Epoch 77, CIFAR-10 Batch 1:  Loss:     0.5010 Validation Accuracy: 0.697200
Epoch 77, CIFAR-10 Batch 2:  Loss:     0.4891 Validation Accuracy: 0.700000
Epoch 77, CIFAR-10 Batch 3:  Loss:     0.4538 Validation Accuracy: 0.694600
Epoch 77, CIFAR-10 Batch 4:  Loss:     0.4203 Validation Accuracy: 0.703800
Epoch 77, CIFAR-10 Batch 5:  Loss:     0.4484 Validation Accuracy: 0.697400
Epoch 78, CIFAR-10 Batch 1:  Loss:     0.4822 Validation Accuracy: 0.704000
Epoch 78, CIFAR-10 Batch 2:  Loss:     0.4785 Validation Accuracy: 0.706200
Epoch 78, CIFAR-10 Batch 3:  Loss:     0.4981 Validation Accuracy: 0.699800
Epoch 78, CIFAR-10 Batch 4:  Loss:     0.4132 Validation Accuracy: 0.696600
Epoch 78, CIFAR-10 Batch 5:  Loss:     0.4543 Validation Accuracy: 0.701600
Epoch 79, CIFAR-10 Batch 1:  Loss:     0.4708 Validation Accuracy: 0.704000
Epoch 79, CIFAR-10 Batch 2:  Loss:     0.4845 Validation Accuracy: 0.707600
Epoch 79, CIFAR-10 Batch 3:  Loss:     0.4445 Validation Accuracy: 0.707800
Epoch 79, CIFAR-10 Batch 4:  Loss:     0.4397 Validation Accuracy: 0.701000
Epoch 79, CIFAR-10 Batch 5:  Loss:     0.4344 Validation Accuracy: 0.702400
Epoch 80, CIFAR-10 Batch 1:  Loss:     0.4834 Validation Accuracy: 0.706600
Epoch 80, CIFAR-10 Batch 2:  Loss:     0.4733 Validation Accuracy: 0.702000
Epoch 80, CIFAR-10 Batch 3:  Loss:     0.4551 Validation Accuracy: 0.701200
Epoch 80, CIFAR-10 Batch 4:  Loss:     0.4077 Validation Accuracy: 0.708000
Epoch 80, CIFAR-10 Batch 5:  Loss:     0.4344 Validation Accuracy: 0.709000
Epoch 81, CIFAR-10 Batch 1:  Loss:     0.4721 Validation Accuracy: 0.705400
Epoch 81, CIFAR-10 Batch 2:  Loss:     0.4718 Validation Accuracy: 0.707000
Epoch 81, CIFAR-10 Batch 3:  Loss:     0.4653 Validation Accuracy: 0.703200
Epoch 81, CIFAR-10 Batch 4:  Loss:     0.4220 Validation Accuracy: 0.695200
Epoch 81, CIFAR-10 Batch 5:  Loss:     0.4365 Validation Accuracy: 0.703200
Epoch 82, CIFAR-10 Batch 1:  Loss:     0.4621 Validation Accuracy: 0.707400
Epoch 82, CIFAR-10 Batch 2:  Loss:     0.4658 Validation Accuracy: 0.713600
Epoch 82, CIFAR-10 Batch 3:  Loss:     0.4445 Validation Accuracy: 0.699200
Epoch 82, CIFAR-10 Batch 4:  Loss:     0.4268 Validation Accuracy: 0.700000
Epoch 82, CIFAR-10 Batch 5:  Loss:     0.4294 Validation Accuracy: 0.702200
Epoch 83, CIFAR-10 Batch 1:  Loss:     0.4745 Validation Accuracy: 0.709800
Epoch 83, CIFAR-10 Batch 2:  Loss:     0.4506 Validation Accuracy: 0.708000
Epoch 83, CIFAR-10 Batch 3:  Loss:     0.4423 Validation Accuracy: 0.694400
Epoch 83, CIFAR-10 Batch 4:  Loss:     0.4051 Validation Accuracy: 0.704600
Epoch 83, CIFAR-10 Batch 5:  Loss:     0.4176 Validation Accuracy: 0.698400
Epoch 84, CIFAR-10 Batch 1:  Loss:     0.4614 Validation Accuracy: 0.702400
Epoch 84, CIFAR-10 Batch 2:  Loss:     0.4618 Validation Accuracy: 0.708400
Epoch 84, CIFAR-10 Batch 3:  Loss:     0.4267 Validation Accuracy: 0.702200
Epoch 84, CIFAR-10 Batch 4:  Loss:     0.4111 Validation Accuracy: 0.701200
Epoch 84, CIFAR-10 Batch 5:  Loss:     0.4249 Validation Accuracy: 0.705400
Epoch 85, CIFAR-10 Batch 1:  Loss:     0.4623 Validation Accuracy: 0.703400
Epoch 85, CIFAR-10 Batch 2:  Loss:     0.4718 Validation Accuracy: 0.698600
Epoch 85, CIFAR-10 Batch 3:  Loss:     0.4279 Validation Accuracy: 0.702800
Epoch 85, CIFAR-10 Batch 4:  Loss:     0.3961 Validation Accuracy: 0.703600
Epoch 85, CIFAR-10 Batch 5:  Loss:     0.4099 Validation Accuracy: 0.702600
Epoch 86, CIFAR-10 Batch 1:  Loss:     0.4614 Validation Accuracy: 0.703600
Epoch 86, CIFAR-10 Batch 2:  Loss:     0.4665 Validation Accuracy: 0.703400
Epoch 86, CIFAR-10 Batch 3:  Loss:     0.4490 Validation Accuracy: 0.705800
Epoch 86, CIFAR-10 Batch 4:  Loss:     0.4042 Validation Accuracy: 0.703200
Epoch 86, CIFAR-10 Batch 5:  Loss:     0.4123 Validation Accuracy: 0.705200
Epoch 87, CIFAR-10 Batch 1:  Loss:     0.4281 Validation Accuracy: 0.706400
Epoch 87, CIFAR-10 Batch 2:  Loss:     0.4392 Validation Accuracy: 0.705800
Epoch 87, CIFAR-10 Batch 3:  Loss:     0.4382 Validation Accuracy: 0.708000
Epoch 87, CIFAR-10 Batch 4:  Loss:     0.4030 Validation Accuracy: 0.706400
Epoch 87, CIFAR-10 Batch 5:  Loss:     0.4087 Validation Accuracy: 0.706400
Epoch 88, CIFAR-10 Batch 1:  Loss:     0.4310 Validation Accuracy: 0.705200
Epoch 88, CIFAR-10 Batch 2:  Loss:     0.4768 Validation Accuracy: 0.703600
Epoch 88, CIFAR-10 Batch 3:  Loss:     0.4377 Validation Accuracy: 0.705200
Epoch 88, CIFAR-10 Batch 4:  Loss:     0.4266 Validation Accuracy: 0.696600
Epoch 88, CIFAR-10 Batch 5:  Loss:     0.4149 Validation Accuracy: 0.702800
Epoch 89, CIFAR-10 Batch 1:  Loss:     0.4591 Validation Accuracy: 0.708200
Epoch 89, CIFAR-10 Batch 2:  Loss:     0.4534 Validation Accuracy: 0.705800
Epoch 89, CIFAR-10 Batch 3:  Loss:     0.4283 Validation Accuracy: 0.703800
Epoch 89, CIFAR-10 Batch 4:  Loss:     0.3996 Validation Accuracy: 0.702600
Epoch 89, CIFAR-10 Batch 5:  Loss:     0.3864 Validation Accuracy: 0.708400
Epoch 90, CIFAR-10 Batch 1:  Loss:     0.4604 Validation Accuracy: 0.708800
Epoch 90, CIFAR-10 Batch 2:  Loss:     0.4469 Validation Accuracy: 0.708600
Epoch 90, CIFAR-10 Batch 3:  Loss:     0.4218 Validation Accuracy: 0.706600
Epoch 90, CIFAR-10 Batch 4:  Loss:     0.4024 Validation Accuracy: 0.699400
Epoch 90, CIFAR-10 Batch 5:  Loss:     0.4044 Validation Accuracy: 0.705800
Epoch 91, CIFAR-10 Batch 1:  Loss:     0.4331 Validation Accuracy: 0.706200
Epoch 91, CIFAR-10 Batch 2:  Loss:     0.4373 Validation Accuracy: 0.711000
Epoch 91, CIFAR-10 Batch 3:  Loss:     0.4246 Validation Accuracy: 0.702600
Epoch 91, CIFAR-10 Batch 4:  Loss:     0.3834 Validation Accuracy: 0.707600
Epoch 91, CIFAR-10 Batch 5:  Loss:     0.3970 Validation Accuracy: 0.703800
Epoch 92, CIFAR-10 Batch 1:  Loss:     0.4287 Validation Accuracy: 0.707400
Epoch 92, CIFAR-10 Batch 2:  Loss:     0.4313 Validation Accuracy: 0.706000
Epoch 92, CIFAR-10 Batch 3:  Loss:     0.4410 Validation Accuracy: 0.711200
Epoch 92, CIFAR-10 Batch 4:  Loss:     0.3925 Validation Accuracy: 0.703600
Epoch 92, CIFAR-10 Batch 5:  Loss:     0.4053 Validation Accuracy: 0.701200
Epoch 93, CIFAR-10 Batch 1:  Loss:     0.4186 Validation Accuracy: 0.707800
Epoch 93, CIFAR-10 Batch 2:  Loss:     0.4495 Validation Accuracy: 0.708600
Epoch 93, CIFAR-10 Batch 3:  Loss:     0.4425 Validation Accuracy: 0.710000
Epoch 93, CIFAR-10 Batch 4:  Loss:     0.3727 Validation Accuracy: 0.699000
Epoch 93, CIFAR-10 Batch 5:  Loss:     0.3874 Validation Accuracy: 0.700200
Epoch 94, CIFAR-10 Batch 1:  Loss:     0.4112 Validation Accuracy: 0.711200
Epoch 94, CIFAR-10 Batch 2:  Loss:     0.4232 Validation Accuracy: 0.706000
Epoch 94, CIFAR-10 Batch 3:  Loss:     0.3998 Validation Accuracy: 0.705600
Epoch 94, CIFAR-10 Batch 4:  Loss:     0.3726 Validation Accuracy: 0.702200
Epoch 94, CIFAR-10 Batch 5:  Loss:     0.3915 Validation Accuracy: 0.706600
Epoch 95, CIFAR-10 Batch 1:  Loss:     0.4415 Validation Accuracy: 0.702600
Epoch 95, CIFAR-10 Batch 2:  Loss:     0.4321 Validation Accuracy: 0.705400
Epoch 95, CIFAR-10 Batch 3:  Loss:     0.4211 Validation Accuracy: 0.707600
Epoch 95, CIFAR-10 Batch 4:  Loss:     0.3615 Validation Accuracy: 0.697800
Epoch 95, CIFAR-10 Batch 5:  Loss:     0.4031 Validation Accuracy: 0.704000
Epoch 96, CIFAR-10 Batch 1:  Loss:     0.4306 Validation Accuracy: 0.704600
Epoch 96, CIFAR-10 Batch 2:  Loss:     0.4368 Validation Accuracy: 0.700400
Epoch 96, CIFAR-10 Batch 3:  Loss:     0.4113 Validation Accuracy: 0.701800
Epoch 96, CIFAR-10 Batch 4:  Loss:     0.3621 Validation Accuracy: 0.709600
Epoch 96, CIFAR-10 Batch 5:  Loss:     0.3973 Validation Accuracy: 0.698200
Epoch 97, CIFAR-10 Batch 1:  Loss:     0.4202 Validation Accuracy: 0.704400
Epoch 97, CIFAR-10 Batch 2:  Loss:     0.4250 Validation Accuracy: 0.706200
Epoch 97, CIFAR-10 Batch 3:  Loss:     0.4284 Validation Accuracy: 0.705000
Epoch 97, CIFAR-10 Batch 4:  Loss:     0.3874 Validation Accuracy: 0.704600
Epoch 97, CIFAR-10 Batch 5:  Loss:     0.3820 Validation Accuracy: 0.698000
Epoch 98, CIFAR-10 Batch 1:  Loss:     0.4180 Validation Accuracy: 0.708800
Epoch 98, CIFAR-10 Batch 2:  Loss:     0.4172 Validation Accuracy: 0.709000
Epoch 98, CIFAR-10 Batch 3:  Loss:     0.4122 Validation Accuracy: 0.703200
Epoch 98, CIFAR-10 Batch 4:  Loss:     0.3771 Validation Accuracy: 0.705800
Epoch 98, CIFAR-10 Batch 5:  Loss:     0.3907 Validation Accuracy: 0.707200
Epoch 99, CIFAR-10 Batch 1:  Loss:     0.4162 Validation Accuracy: 0.706800
Epoch 99, CIFAR-10 Batch 2:  Loss:     0.4094 Validation Accuracy: 0.709200
Epoch 99, CIFAR-10 Batch 3:  Loss:     0.4274 Validation Accuracy: 0.706400
Epoch 99, CIFAR-10 Batch 4:  Loss:     0.3708 Validation Accuracy: 0.705000
Epoch 99, CIFAR-10 Batch 5:  Loss:     0.3799 Validation Accuracy: 0.705400
Epoch 100, CIFAR-10 Batch 1:  Loss:     0.4265 Validation Accuracy: 0.700600
Epoch 100, CIFAR-10 Batch 2:  Loss:     0.4087 Validation Accuracy: 0.706400
Epoch 100, CIFAR-10 Batch 3:  Loss:     0.4034 Validation Accuracy: 0.708400
Epoch 100, CIFAR-10 Batch 4:  Loss:     0.3437 Validation Accuracy: 0.705400
Epoch 100, CIFAR-10 Batch 5:  Loss:     0.3754 Validation Accuracy: 0.700800

Checkpoint

The model has been saved to disk.

Test Model

Test your model against the test dataset. This will be your final accuracy. You should have an accuracy greater than 50%. If you don't, keep tweaking the model architecture and parameters.

In [15]:
"""
DON'T MODIFY ANYTHING IN THIS CELL
"""
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import tensorflow as tf
import pickle
import helper
import random

# Set batch size if not already set
try:
    if batch_size:
        pass
except NameError:
    batch_size = 64

save_model_path = './image_classification'
n_samples = 4
top_n_predictions = 3

def test_model():
    """
    Test the saved model against the test dataset
    """

    test_features, test_labels = pickle.load(open('preprocess_training.p', mode='rb'))
    loaded_graph = tf.Graph()

    with tf.Session(graph=loaded_graph) as sess:
        # Load model
        loader = tf.train.import_meta_graph(save_model_path + '.meta')
        loader.restore(sess, save_model_path)

        # Get Tensors from loaded model
        loaded_x = loaded_graph.get_tensor_by_name('x:0')
        loaded_y = loaded_graph.get_tensor_by_name('y:0')
        loaded_keep_prob = loaded_graph.get_tensor_by_name('keep_prob:0')
        loaded_logits = loaded_graph.get_tensor_by_name('logits:0')
        loaded_acc = loaded_graph.get_tensor_by_name('accuracy:0')
        
        # Get accuracy in batches for memory limitations
        test_batch_acc_total = 0
        test_batch_count = 0
        
        for train_feature_batch, train_label_batch in helper.batch_features_labels(test_features, test_labels, batch_size):
            test_batch_acc_total += sess.run(
                loaded_acc,
                feed_dict={loaded_x: train_feature_batch, loaded_y: train_label_batch, loaded_keep_prob: 1.0})
            test_batch_count += 1

        print('Testing Accuracy: {}\n'.format(test_batch_acc_total/test_batch_count))

        # Print Random Samples
        random_test_features, random_test_labels = tuple(zip(*random.sample(list(zip(test_features, test_labels)), n_samples)))
        random_test_predictions = sess.run(
            tf.nn.top_k(tf.nn.softmax(loaded_logits), top_n_predictions),
            feed_dict={loaded_x: random_test_features, loaded_y: random_test_labels, loaded_keep_prob: 1.0})
        helper.display_image_predictions(random_test_features, random_test_labels, random_test_predictions)


test_model()
Testing Accuracy: 0.7043772995471954

Why 50-70% Accuracy?

You might be wondering why you can't get an accuracy any higher. First things first, 50% isn't bad for a simple CNN. Pure guessing would get you 10% accuracy. However, you might notice people are getting scores well above 70%. That's because we haven't taught you all there is to know about neural networks. We still need to cover a few more techniques.

Submitting This Project

When submitting this project, make sure to run all the cells before saving the notebook. Save the notebook file as "dlnd_image_classification.ipynb" and save it as a HTML file under "File" -> "Download as". Include the "helper.py" and "problem_unittests.py" files in your submission.

Some thoughts

In this project, I find parameter tuning is an important and time-consuming step. Building the network per se is a relatively easy job, especially if we use tensorflow or other libraries. However, chooseing the right parameter to ensure a high accuracy is hard.

In the beginning, I found no matter what I do, I could not achieve a 40% accuracy. After reading forum discussions, I noticed that I have initialized the weights using the default paremter (standard deviation 1). When I chose a much smaller value (standard deviation = 0.1), the accuracy jumped to above 0.55.

The keep_probability also matters. I find lower keep_probability gives a better result (though the process is slower). After trying a few values, including 0.5, 0.1, 0.3, etc, I eventually chose 0.3.

The number of output in the convolution layer is set to 18, which is larger than my initial value. The ksize of the max_pooling layer was set to 4 initially, but after changing to 8 the accuracy increased to 0.64 from 0.61.

The final accuracy of the single-batch training is 0.64, for all the 5 batches it is 0.71, and for the test data it is 0.71. This is an acceptable result.


The reviewer suggested to apply ReLU for the convolution layer (before max pooling), and for the fully connected layer. In the first submission ReLU was applied in the convolutional model. I moved ReLU inside the convolutional layer and fully connected layer definition. The final accuracy is largely unchange (0.70).