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'

# Use Floyd's cifar-10 dataset if present
floyd_cifar10_location = '/input/cifar-10/python.tar.gz'
if isfile(floyd_cifar10_location):
    tar_gz_path = floyd_cifar10_location
else:
    tar_gz_path = 'cifar-10-python.tar.gz'

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(tar_gz_path):
    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',
            tar_gz_path,
            pbar.hook)

if not isdir(cifar10_dataset_folder_path):
    with tarfile.open(tar_gz_path) as tar:
        tar.extractall()
        tar.close()


tests.test_folder_path(cifar10_dataset_folder_path)


Out[1]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
CIFAR-10 Dataset: 100%|████████████████████████████████████████████████████████████▉| 170M/170M [00:13<00:00, 15.0MB/s]
Out[1]:
('cifar-10-python.tar.gz', <http.client.HTTPMessage at 0x19c6b515780>)
CIFAR-10 Dataset: 171MB [00:13, 12.6MB/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 [13]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import helper
import numpy as np

# Explore the dataset
for bid in range(1,5):
    for sid in range(9):
        batch_id = bid
        sample_id = sid
        helper.display_stats(cifar10_dataset_folder_path, batch_id, sample_id)


Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 0:
Image - Min Value: 0 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 1:
Image - Min Value: 5 Max Value: 254
Image - Shape: (32, 32, 3)
Label - Label Id: 9 Name: truck

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 2:
Image - Min Value: 20 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 9 Name: truck

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 3:
Image - Min Value: 4 Max Value: 234
Image - Shape: (32, 32, 3)
Label - Label Id: 4 Name: deer

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 4:
Image - Min Value: 0 Max Value: 254
Image - Shape: (32, 32, 3)
Label - Label Id: 1 Name: automobile

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 5:
Image - Min Value: 0 Max Value: 252
Image - Shape: (32, 32, 3)
Label - Label Id: 1 Name: automobile

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 6:
Image - Min Value: 7 Max Value: 249
Image - Shape: (32, 32, 3)
Label - Label Id: 2 Name: bird

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 7:
Image - Min Value: 9 Max Value: 248
Image - Shape: (32, 32, 3)
Label - Label Id: 7 Name: horse

Stats of batch 1:
Samples: 10000
Label Counts: {0: 1005, 1: 974, 2: 1032, 3: 1016, 4: 999, 5: 937, 6: 1030, 7: 1001, 8: 1025, 9: 981}
First 20 Labels: [6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6]

Example of Image 8:
Image - Min Value: 8 Max Value: 252
Image - Shape: (32, 32, 3)
Label - Label Id: 8 Name: ship

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 0:
Image - Min Value: 5 Max Value: 225
Image - Shape: (32, 32, 3)
Label - Label Id: 1 Name: automobile

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 1:
Image - Min Value: 2 Max Value: 247
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

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 2:
Image - Min Value: 0 Max Value: 240
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

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 3:
Image - Min Value: 4 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 8 Name: ship

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 4:
Image - Min Value: 0 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 8 Name: ship

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 5:
Image - Min Value: 3 Max Value: 219
Image - Shape: (32, 32, 3)
Label - Label Id: 3 Name: cat

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 6:
Image - Min Value: 0 Max Value: 235
Image - Shape: (32, 32, 3)
Label - Label Id: 4 Name: deer

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 7:
Image - Min Value: 4 Max Value: 226
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

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 8:
Image - Min Value: 31 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 0 Name: airplane

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 0:
Image - Min Value: 0 Max Value: 254
Image - Shape: (32, 32, 3)
Label - Label Id: 8 Name: ship

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 1:
Image - Min Value: 15 Max Value: 249
Image - Shape: (32, 32, 3)
Label - Label Id: 5 Name: dog

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 2:
Image - Min Value: 21 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 0 Name: airplane

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 3:
Image - Min Value: 40 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 4:
Image - Min Value: 10 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 9 Name: truck

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 5:
Image - Min Value: 9 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 2 Name: bird

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 6:
Image - Min Value: 30 Max Value: 242
Image - Shape: (32, 32, 3)
Label - Label Id: 8 Name: ship

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 7:
Image - Min Value: 12 Max Value: 254
Image - Shape: (32, 32, 3)
Label - Label Id: 3 Name: cat

Stats of batch 3:
Samples: 10000
Label Counts: {0: 994, 1: 1042, 2: 965, 3: 997, 4: 990, 5: 1029, 6: 978, 7: 1015, 8: 961, 9: 1029}
First 20 Labels: [8, 5, 0, 6, 9, 2, 8, 3, 6, 2, 7, 4, 6, 9, 0, 0, 7, 3, 7, 2]

Example of Image 8:
Image - Min Value: 14 Max Value: 218
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 0:
Image - Min Value: 34 Max Value: 203
Image - Shape: (32, 32, 3)
Label - Label Id: 0 Name: airplane

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 1:
Image - Min Value: 0 Max Value: 246
Image - Shape: (32, 32, 3)
Label - Label Id: 6 Name: frog

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 2:
Image - Min Value: 2 Max Value: 204
Image - Shape: (32, 32, 3)
Label - Label Id: 0 Name: airplane

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 3:
Image - Min Value: 0 Max Value: 248
Image - Shape: (32, 32, 3)
Label - Label Id: 2 Name: bird

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 4:
Image - Min Value: 1 Max Value: 243
Image - Shape: (32, 32, 3)
Label - Label Id: 7 Name: horse

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 5:
Image - Min Value: 13 Max Value: 169
Image - Shape: (32, 32, 3)
Label - Label Id: 2 Name: bird

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 6:
Image - Min Value: 5 Max Value: 255
Image - Shape: (32, 32, 3)
Label - Label Id: 1 Name: automobile

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 7:
Image - Min Value: 17 Max Value: 221
Image - Shape: (32, 32, 3)
Label - Label Id: 2 Name: bird

Stats of batch 4:
Samples: 10000
Label Counts: {0: 1003, 1: 963, 2: 1041, 3: 976, 4: 1004, 5: 1021, 6: 1004, 7: 981, 8: 1024, 9: 983}
First 20 Labels: [0, 6, 0, 2, 7, 2, 1, 2, 4, 1, 5, 6, 6, 3, 1, 3, 5, 5, 8, 1]

Example of Image 8:
Image - Min Value: 15 Max Value: 235
Image - Shape: (32, 32, 3)
Label - Label Id: 4 Name: deer

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 [215]:
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
    """
    return x/255.0

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


Out[215]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [216]:
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
    """
#     y = np.zeros((len(x), 10))
#     for i in range(len(x)):
#         y[i,x[i]] = 1
    return np.eye(10)[x]


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


Out[216]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [217]:
"""
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)


Out[217]:
"\nDON'T MODIFY ANYTHING IN THIS CELL\n"

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 [218]:
"""
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'))


Out[218]:
"\nDON'T MODIFY ANYTHING IN THIS CELL\n"

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 [220]:
import tensorflow as tf

def neural_net_image_input(image_shape):
    """
    Return a Tensor for a batch of image input
    : image_shape: Shape of the images
    : return: Tensor for image input.
    """
    return tf.placeholder(tf.float32, shape=[None] + list(image_shape), name="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.
    """
    return tf.placeholder(tf.float32, [None, n_classes], name="y")


def neural_net_keep_prob_input():
    """
    Return a Tensor for keep probability
    : return: Tensor for keep probability.
    """
    return tf.placeholder(tf.float32, name="keep_prob") #dropout (keep probability)


"""
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)


Out[220]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [238]:
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
    """
    # Filter (weights and bias)
    # The shape of the filter weight is (height, width, input_depth, output_depth)
    # The shape of the filter bias is (output_depth,)
    # TODO: Define the filter weights `F_W` and filter bias `F_b`.
    # NOTE: Remember to wrap them in `tf.Variable`, they are trainable parameters after all.
    input_shape = x_tensor.shape # (batch_size, height, width, depth)
    input_height = int(input_shape[1])
    input_width = int(input_shape[2])
    input_depth = int(input_shape[3])
    
    filter_height = conv_ksize[0] # since it's a 2-D Tuple for the convolutional layer for spatial dimension
    filter_width = conv_ksize[1] # since it's a 2-D Tuple for the convolutional layer for spatial dimension
    filter_depth = conv_num_outputs # since we want to increase depth to 'conv_num_outputs' as output_shape is (1,2,2,conv_num_outputs)
    
    # TODO: Set the stride for each dimension (batch_size, height, width, depth)
    strides = [1] + list(conv_strides) + [1]
    
    output_height = np.ceil(float(input_height) / float(strides[1])) # for SAME padding
    output_width  = np.ceil(float(input_width) / float(strides[2])) # for SAME padding
    output_depth = conv_num_outputs
    
    # shape of filter weight is (height, width, input_depth, output_depth)
    F_shape = [int(filter_height), int(filter_width), int(input_depth), int(output_depth)]
    initializer = tf.contrib.layers.xavier_initializer()
    F_W = tf.Variable(initializer(F_shape))
    
    # shape of the filter bias is (output_depth,)
    # F_b = tf.Variable(tf.zeros(conv_num_outputs))
    F_b = tf.Variable(tf.constant(0.1, shape=[conv_num_outputs,]))
    
    # TODO: set the padding, either 'VALID' or 'SAME'.
    padding = 'SAME'
    # https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#conv2d
    # `tf.nn.conv2d` does not include the bias computation so we have to add it ourselves after.
    conv_layer = tf.nn.conv2d(x_tensor, F_W, strides, padding)
    conv_layer = tf.nn.bias_add(conv_layer, F_b)
    conv_layer = tf.nn.elu(conv_layer)
    
    # TODO: Set the ksize (filter size) for each dimension (batch_size, height, width, depth)
    ksize = [1] + list(pool_ksize) + [1]
    # TODO: Set the stride for each dimension (batch_size, height, width, depth)
    strides = [1] + list(pool_strides) + [1]
    # TODO: set the padding, either 'VALID' or 'SAME'.
    padding = 'SAME'
    # TODO: Implement Function
    conv_layer = tf.nn.max_pool(conv_layer, ksize, strides, padding) 
    return conv_layer


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


Out[238]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [222]:
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).
    """
    dims = x_tensor.shape.as_list() # e.g. (1, 32, 32, 5) => dims[1:] = (32, 32, 5)
    return tf.reshape(x_tensor,[-1, np.prod(dims[1:])]) # e.g. for a greyscale image of 32x32x1 size prod = 1024


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


Out[222]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [239]:
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.
    """
    dims = x_tensor.get_shape().as_list()
    shape = list( (dims[-1],) + (num_outputs,)) #list((dims[-1], num_outputs))
    weight = tf.Variable(tf.truncated_normal(shape, 0, 0.1))
    bias = tf.Variable(tf.zeros(num_outputs))
#     initializer = tf.contrib.layers.xavier_initializer()
#     weight = tf.Variable(initializer(shape))
#     bias = tf.Variable(tf.constant(0.1, shape=[num_outputs,]))
    
    fc1 = tf.matmul(x_tensor, weight)
    fc1 = tf.add(fc1, bias)
    fc1 = tf.nn.elu(fc1)
    return fc1


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


Out[239]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [240]:
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
    dims = x_tensor.get_shape().as_list()
    shape = list( (dims[-1],) + (num_outputs,)) #list((dims[-1], num_outputs))
    weight = tf.Variable(tf.truncated_normal(shape, 0, 0.1))
    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)


Out[240]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [241]:
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)
    conv = conv2d_maxpool(x, conv_num_outputs=20, conv_ksize=(2,2), conv_strides=(1,1), pool_ksize=(4,4), pool_strides=(1,1))
    
    # Here's more info on the architecture of conv nets. 
    # Usually we don't apply dropout to convolutional layers because they already have a lot of regularization built-in.
    # conv = tf.nn.dropout(conv, keep_prob)

    # TODO: Apply a Flatten Layer
    # Function Definition from Above:
    conv = flatten(conv)
    
    # 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)
    conv = fully_conn(conv, 384)
    conv = tf.nn.dropout(conv, keep_prob)
    
    # TODO: Apply an Output Layer
    #    Set this to the number of classes
    # Function Definition from Above:
    conv = output(conv, 10)
    
    # TODO: return output
    return conv


"""
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)


Out[241]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [242]:
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
    """
    # Launch the graph
    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)


Out[242]:
"\nDON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE\n"
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 [243]:
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
    loss = session.run(cost, feed_dict={x:feature_batch, y:label_batch, keep_prob:1.0})
    valid_accuracy = session.run(accuracy, feed_dict={x: valid_features,
                                                         y: valid_labels,
                                                         keep_prob: 1.0})
    print("Loss = " + "{:.6f}".format(loss) + ", Validation accuracy= " + "{:.5f}".format(valid_accuracy))

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 [244]:
# TODO: Tune Parameters
epochs = 100
batch_size = 256
keep_probability = 0.75

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 [245]:
"""
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)


Out[245]:
"\nDON'T MODIFY ANYTHING IN THIS CELL\n"
Checking the Training on a Single Batch...
Epoch  1, CIFAR-10 Batch 1:  Loss = 2.072946, Validation accuracy= 0.30400
Epoch  2, CIFAR-10 Batch 1:  Loss = 1.828676, Validation accuracy= 0.36420
Epoch  3, CIFAR-10 Batch 1:  Loss = 1.673929, Validation accuracy= 0.38760
Epoch  4, CIFAR-10 Batch 1:  Loss = 1.475083, Validation accuracy= 0.42000
Epoch  5, CIFAR-10 Batch 1:  Loss = 1.378349, Validation accuracy= 0.41960
Epoch  6, CIFAR-10 Batch 1:  Loss = 1.202924, Validation accuracy= 0.43300
Epoch  7, CIFAR-10 Batch 1:  Loss = 1.146461, Validation accuracy= 0.46700
Epoch  8, CIFAR-10 Batch 1:  Loss = 1.037178, Validation accuracy= 0.47000
Epoch  9, CIFAR-10 Batch 1:  Loss = 0.943333, Validation accuracy= 0.48320
Epoch 10, CIFAR-10 Batch 1:  Loss = 0.868253, Validation accuracy= 0.47880
Epoch 11, CIFAR-10 Batch 1:  Loss = 0.771609, Validation accuracy= 0.50300
Epoch 12, CIFAR-10 Batch 1:  Loss = 0.680711, Validation accuracy= 0.50580
Epoch 13, CIFAR-10 Batch 1:  Loss = 0.645709, Validation accuracy= 0.52640
Epoch 14, CIFAR-10 Batch 1:  Loss = 0.580768, Validation accuracy= 0.52920
Epoch 15, CIFAR-10 Batch 1:  Loss = 0.530973, Validation accuracy= 0.53600
Epoch 16, CIFAR-10 Batch 1:  Loss = 0.464050, Validation accuracy= 0.52580
Epoch 17, CIFAR-10 Batch 1:  Loss = 0.417281, Validation accuracy= 0.53880
Epoch 18, CIFAR-10 Batch 1:  Loss = 0.428933, Validation accuracy= 0.53560
Epoch 19, CIFAR-10 Batch 1:  Loss = 0.353812, Validation accuracy= 0.53780
Epoch 20, CIFAR-10 Batch 1:  Loss = 0.327778, Validation accuracy= 0.55540
Epoch 21, CIFAR-10 Batch 1:  Loss = 0.266631, Validation accuracy= 0.56320
Epoch 22, CIFAR-10 Batch 1:  Loss = 0.233583, Validation accuracy= 0.56140
Epoch 23, CIFAR-10 Batch 1:  Loss = 0.202988, Validation accuracy= 0.56420
Epoch 24, CIFAR-10 Batch 1:  Loss = 0.184351, Validation accuracy= 0.56980
Epoch 25, CIFAR-10 Batch 1:  Loss = 0.191008, Validation accuracy= 0.56520
Epoch 26, CIFAR-10 Batch 1:  Loss = 0.186093, Validation accuracy= 0.56680
Epoch 27, CIFAR-10 Batch 1:  Loss = 0.134545, Validation accuracy= 0.57020
Epoch 28, CIFAR-10 Batch 1:  Loss = 0.122740, Validation accuracy= 0.57620
Epoch 29, CIFAR-10 Batch 1:  Loss = 0.102916, Validation accuracy= 0.58200
Epoch 30, CIFAR-10 Batch 1:  Loss = 0.105667, Validation accuracy= 0.58400
Epoch 31, CIFAR-10 Batch 1:  Loss = 0.092229, Validation accuracy= 0.59160
Epoch 32, CIFAR-10 Batch 1:  Loss = 0.079892, Validation accuracy= 0.58000
Epoch 33, CIFAR-10 Batch 1:  Loss = 0.069705, Validation accuracy= 0.58560
Epoch 34, CIFAR-10 Batch 1:  Loss = 0.062553, Validation accuracy= 0.58560
Epoch 35, CIFAR-10 Batch 1:  Loss = 0.061077, Validation accuracy= 0.58320
Epoch 36, CIFAR-10 Batch 1:  Loss = 0.052870, Validation accuracy= 0.58820
Epoch 37, CIFAR-10 Batch 1:  Loss = 0.038525, Validation accuracy= 0.59340
Epoch 38, CIFAR-10 Batch 1:  Loss = 0.039714, Validation accuracy= 0.59200
Epoch 39, CIFAR-10 Batch 1:  Loss = 0.039761, Validation accuracy= 0.59640
Epoch 40, CIFAR-10 Batch 1:  Loss = 0.029181, Validation accuracy= 0.59600
Epoch 41, CIFAR-10 Batch 1:  Loss = 0.029986, Validation accuracy= 0.59620
Epoch 42, CIFAR-10 Batch 1:  Loss = 0.026018, Validation accuracy= 0.59860
Epoch 43, CIFAR-10 Batch 1:  Loss = 0.023493, Validation accuracy= 0.58560
Epoch 44, CIFAR-10 Batch 1:  Loss = 0.016385, Validation accuracy= 0.58700
Epoch 45, CIFAR-10 Batch 1:  Loss = 0.020985, Validation accuracy= 0.57880
Epoch 46, CIFAR-10 Batch 1:  Loss = 0.024058, Validation accuracy= 0.58200
Epoch 47, CIFAR-10 Batch 1:  Loss = 0.021292, Validation accuracy= 0.58700
Epoch 48, CIFAR-10 Batch 1:  Loss = 0.014831, Validation accuracy= 0.60180
Epoch 49, CIFAR-10 Batch 1:  Loss = 0.014799, Validation accuracy= 0.58260
Epoch 50, CIFAR-10 Batch 1:  Loss = 0.013115, Validation accuracy= 0.59140
Epoch 51, CIFAR-10 Batch 1:  Loss = 0.015557, Validation accuracy= 0.60220
Epoch 52, CIFAR-10 Batch 1:  Loss = 0.007595, Validation accuracy= 0.60180
Epoch 53, CIFAR-10 Batch 1:  Loss = 0.010648, Validation accuracy= 0.58860
Epoch 54, CIFAR-10 Batch 1:  Loss = 0.008407, Validation accuracy= 0.59140
Epoch 55, CIFAR-10 Batch 1:  Loss = 0.010553, Validation accuracy= 0.59360
Epoch 56, CIFAR-10 Batch 1:  Loss = 0.007103, Validation accuracy= 0.59060
Epoch 57, CIFAR-10 Batch 1:  Loss = 0.006559, Validation accuracy= 0.58940
Epoch 58, CIFAR-10 Batch 1:  Loss = 0.005732, Validation accuracy= 0.59580
Epoch 59, CIFAR-10 Batch 1:  Loss = 0.004999, Validation accuracy= 0.59100
Epoch 60, CIFAR-10 Batch 1:  Loss = 0.004732, Validation accuracy= 0.59640
Epoch 61, CIFAR-10 Batch 1:  Loss = 0.008838, Validation accuracy= 0.58900
Epoch 62, CIFAR-10 Batch 1:  Loss = 0.003406, Validation accuracy= 0.59740
Epoch 63, CIFAR-10 Batch 1:  Loss = 0.003233, Validation accuracy= 0.60520
Epoch 64, CIFAR-10 Batch 1:  Loss = 0.003556, Validation accuracy= 0.60440
Epoch 65, CIFAR-10 Batch 1:  Loss = 0.003297, Validation accuracy= 0.60160
Epoch 66, CIFAR-10 Batch 1:  Loss = 0.002047, Validation accuracy= 0.59600
Epoch 67, CIFAR-10 Batch 1:  Loss = 0.001996, Validation accuracy= 0.59800
Epoch 68, CIFAR-10 Batch 1:  Loss = 0.003581, Validation accuracy= 0.59960
Epoch 69, CIFAR-10 Batch 1:  Loss = 0.001395, Validation accuracy= 0.60580
Epoch 70, CIFAR-10 Batch 1:  Loss = 0.001518, Validation accuracy= 0.60160
Epoch 71, CIFAR-10 Batch 1:  Loss = 0.001923, Validation accuracy= 0.60260
Epoch 72, CIFAR-10 Batch 1:  Loss = 0.001893, Validation accuracy= 0.61300
Epoch 73, CIFAR-10 Batch 1:  Loss = 0.001824, Validation accuracy= 0.61240
Epoch 74, CIFAR-10 Batch 1:  Loss = 0.001239, Validation accuracy= 0.60640
Epoch 75, CIFAR-10 Batch 1:  Loss = 0.002297, Validation accuracy= 0.59920
Epoch 76, CIFAR-10 Batch 1:  Loss = 0.001457, Validation accuracy= 0.58440
Epoch 77, CIFAR-10 Batch 1:  Loss = 0.001477, Validation accuracy= 0.58940
Epoch 78, CIFAR-10 Batch 1:  Loss = 0.001593, Validation accuracy= 0.58740
Epoch 79, CIFAR-10 Batch 1:  Loss = 0.004403, Validation accuracy= 0.58380
Epoch 80, CIFAR-10 Batch 1:  Loss = 0.002279, Validation accuracy= 0.58980
Epoch 81, CIFAR-10 Batch 1:  Loss = 0.000837, Validation accuracy= 0.58900
Epoch 82, CIFAR-10 Batch 1:  Loss = 0.000873, Validation accuracy= 0.59180
Epoch 83, CIFAR-10 Batch 1:  Loss = 0.001394, Validation accuracy= 0.59400
Epoch 84, CIFAR-10 Batch 1:  Loss = 0.000512, Validation accuracy= 0.59960
Epoch 85, CIFAR-10 Batch 1:  Loss = 0.004432, Validation accuracy= 0.58400
Epoch 86, CIFAR-10 Batch 1:  Loss = 0.000347, Validation accuracy= 0.60100
Epoch 87, CIFAR-10 Batch 1:  Loss = 0.001351, Validation accuracy= 0.59520
Epoch 88, CIFAR-10 Batch 1:  Loss = 0.001099, Validation accuracy= 0.58760
Epoch 89, CIFAR-10 Batch 1:  Loss = 0.000630, Validation accuracy= 0.59460
Epoch 90, CIFAR-10 Batch 1:  Loss = 0.000644, Validation accuracy= 0.60040
Epoch 91, CIFAR-10 Batch 1:  Loss = 0.000287, Validation accuracy= 0.59940
Epoch 92, CIFAR-10 Batch 1:  Loss = 0.001703, Validation accuracy= 0.59860
Epoch 93, CIFAR-10 Batch 1:  Loss = 0.000470, Validation accuracy= 0.60440
Epoch 94, CIFAR-10 Batch 1:  Loss = 0.003236, Validation accuracy= 0.60080
Epoch 95, CIFAR-10 Batch 1:  Loss = 0.000464, Validation accuracy= 0.58920
Epoch 96, CIFAR-10 Batch 1:  Loss = 0.001135, Validation accuracy= 0.59240
Epoch 97, CIFAR-10 Batch 1:  Loss = 0.001790, Validation accuracy= 0.58600
Epoch 98, CIFAR-10 Batch 1:  Loss = 0.001106, Validation accuracy= 0.59320
Epoch 99, CIFAR-10 Batch 1:  Loss = 0.000329, Validation accuracy= 0.59260
Epoch 100, CIFAR-10 Batch 1:  Loss = 0.008967, Validation accuracy= 0.59500

Fully Train the Model

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


In [247]:
"""
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)


Out[247]:
"\nDON'T MODIFY ANYTHING IN THIS CELL\n"
Training...
Epoch  1, CIFAR-10 Batch 1:  Loss = 2.052647, Validation accuracy= 0.31040
Epoch  1, CIFAR-10 Batch 2:  Loss = 1.675713, Validation accuracy= 0.35640
Epoch  1, CIFAR-10 Batch 3:  Loss = 1.718917, Validation accuracy= 0.38200
Epoch  1, CIFAR-10 Batch 4:  Loss = 1.572142, Validation accuracy= 0.41120
Epoch  1, CIFAR-10 Batch 5:  Loss = 1.677982, Validation accuracy= 0.40740
Epoch  2, CIFAR-10 Batch 1:  Loss = 1.751342, Validation accuracy= 0.43060
Epoch  2, CIFAR-10 Batch 2:  Loss = 1.423612, Validation accuracy= 0.44820
Epoch  2, CIFAR-10 Batch 3:  Loss = 1.335750, Validation accuracy= 0.47220
Epoch  2, CIFAR-10 Batch 4:  Loss = 1.379023, Validation accuracy= 0.47760
Epoch  2, CIFAR-10 Batch 5:  Loss = 1.432295, Validation accuracy= 0.48540
Epoch  3, CIFAR-10 Batch 1:  Loss = 1.567043, Validation accuracy= 0.49420
Epoch  3, CIFAR-10 Batch 2:  Loss = 1.174536, Validation accuracy= 0.51300
Epoch  3, CIFAR-10 Batch 3:  Loss = 1.089843, Validation accuracy= 0.51100
Epoch  3, CIFAR-10 Batch 4:  Loss = 1.209648, Validation accuracy= 0.52320
Epoch  3, CIFAR-10 Batch 5:  Loss = 1.281283, Validation accuracy= 0.54180
Epoch  4, CIFAR-10 Batch 1:  Loss = 1.336137, Validation accuracy= 0.52120
Epoch  4, CIFAR-10 Batch 2:  Loss = 1.037714, Validation accuracy= 0.53700
Epoch  4, CIFAR-10 Batch 3:  Loss = 0.894911, Validation accuracy= 0.55320
Epoch  4, CIFAR-10 Batch 4:  Loss = 0.966304, Validation accuracy= 0.57200
Epoch  4, CIFAR-10 Batch 5:  Loss = 1.103050, Validation accuracy= 0.56060
Epoch  5, CIFAR-10 Batch 1:  Loss = 1.062439, Validation accuracy= 0.56540
Epoch  5, CIFAR-10 Batch 2:  Loss = 0.893786, Validation accuracy= 0.57880
Epoch  5, CIFAR-10 Batch 3:  Loss = 0.738354, Validation accuracy= 0.57620
Epoch  5, CIFAR-10 Batch 4:  Loss = 0.855856, Validation accuracy= 0.58800
Epoch  5, CIFAR-10 Batch 5:  Loss = 0.921613, Validation accuracy= 0.59420
Epoch  6, CIFAR-10 Batch 1:  Loss = 0.935270, Validation accuracy= 0.57720
Epoch  6, CIFAR-10 Batch 2:  Loss = 0.776862, Validation accuracy= 0.59340
Epoch  6, CIFAR-10 Batch 3:  Loss = 0.628799, Validation accuracy= 0.59500
Epoch  6, CIFAR-10 Batch 4:  Loss = 0.749922, Validation accuracy= 0.60380
Epoch  6, CIFAR-10 Batch 5:  Loss = 0.831328, Validation accuracy= 0.61300
Epoch  7, CIFAR-10 Batch 1:  Loss = 0.787665, Validation accuracy= 0.60880
Epoch  7, CIFAR-10 Batch 2:  Loss = 0.672521, Validation accuracy= 0.61980
Epoch  7, CIFAR-10 Batch 3:  Loss = 0.507217, Validation accuracy= 0.59660
Epoch  7, CIFAR-10 Batch 4:  Loss = 0.654334, Validation accuracy= 0.62060
Epoch  7, CIFAR-10 Batch 5:  Loss = 0.656652, Validation accuracy= 0.62600
Epoch  8, CIFAR-10 Batch 1:  Loss = 0.596479, Validation accuracy= 0.61800
Epoch  8, CIFAR-10 Batch 2:  Loss = 0.481349, Validation accuracy= 0.62220
Epoch  8, CIFAR-10 Batch 3:  Loss = 0.439151, Validation accuracy= 0.61020
Epoch  8, CIFAR-10 Batch 4:  Loss = 0.559872, Validation accuracy= 0.63560
Epoch  8, CIFAR-10 Batch 5:  Loss = 0.554056, Validation accuracy= 0.63380
Epoch  9, CIFAR-10 Batch 1:  Loss = 0.538195, Validation accuracy= 0.63300
Epoch  9, CIFAR-10 Batch 2:  Loss = 0.394866, Validation accuracy= 0.63720
Epoch  9, CIFAR-10 Batch 3:  Loss = 0.313692, Validation accuracy= 0.63840
Epoch  9, CIFAR-10 Batch 4:  Loss = 0.442913, Validation accuracy= 0.64320
Epoch  9, CIFAR-10 Batch 5:  Loss = 0.434439, Validation accuracy= 0.64360
Epoch 10, CIFAR-10 Batch 1:  Loss = 0.419105, Validation accuracy= 0.64540
Epoch 10, CIFAR-10 Batch 2:  Loss = 0.297183, Validation accuracy= 0.64080
Epoch 10, CIFAR-10 Batch 3:  Loss = 0.263204, Validation accuracy= 0.64900
Epoch 10, CIFAR-10 Batch 4:  Loss = 0.383913, Validation accuracy= 0.65260
Epoch 10, CIFAR-10 Batch 5:  Loss = 0.323526, Validation accuracy= 0.65520
Epoch 11, CIFAR-10 Batch 1:  Loss = 0.387799, Validation accuracy= 0.64920
Epoch 11, CIFAR-10 Batch 2:  Loss = 0.227935, Validation accuracy= 0.64820
Epoch 11, CIFAR-10 Batch 3:  Loss = 0.216833, Validation accuracy= 0.65480
Epoch 11, CIFAR-10 Batch 4:  Loss = 0.311324, Validation accuracy= 0.65860
Epoch 11, CIFAR-10 Batch 5:  Loss = 0.236103, Validation accuracy= 0.66060
Epoch 12, CIFAR-10 Batch 1:  Loss = 0.288914, Validation accuracy= 0.65540
Epoch 12, CIFAR-10 Batch 2:  Loss = 0.190359, Validation accuracy= 0.65840
Epoch 12, CIFAR-10 Batch 3:  Loss = 0.165095, Validation accuracy= 0.65960
Epoch 12, CIFAR-10 Batch 4:  Loss = 0.256097, Validation accuracy= 0.66240
Epoch 12, CIFAR-10 Batch 5:  Loss = 0.211500, Validation accuracy= 0.66560
Epoch 13, CIFAR-10 Batch 1:  Loss = 0.249974, Validation accuracy= 0.66480
Epoch 13, CIFAR-10 Batch 2:  Loss = 0.155013, Validation accuracy= 0.65300
Epoch 13, CIFAR-10 Batch 3:  Loss = 0.136251, Validation accuracy= 0.67500
Epoch 13, CIFAR-10 Batch 4:  Loss = 0.220338, Validation accuracy= 0.67220
Epoch 13, CIFAR-10 Batch 5:  Loss = 0.161624, Validation accuracy= 0.66600
Epoch 14, CIFAR-10 Batch 1:  Loss = 0.221809, Validation accuracy= 0.66400
Epoch 14, CIFAR-10 Batch 2:  Loss = 0.122138, Validation accuracy= 0.65660
Epoch 14, CIFAR-10 Batch 3:  Loss = 0.106367, Validation accuracy= 0.67040
Epoch 14, CIFAR-10 Batch 4:  Loss = 0.188549, Validation accuracy= 0.66320
Epoch 14, CIFAR-10 Batch 5:  Loss = 0.130176, Validation accuracy= 0.68040
Epoch 15, CIFAR-10 Batch 1:  Loss = 0.151881, Validation accuracy= 0.67380
Epoch 15, CIFAR-10 Batch 2:  Loss = 0.089883, Validation accuracy= 0.66640
Epoch 15, CIFAR-10 Batch 3:  Loss = 0.093764, Validation accuracy= 0.68200
Epoch 15, CIFAR-10 Batch 4:  Loss = 0.161079, Validation accuracy= 0.66660
Epoch 15, CIFAR-10 Batch 5:  Loss = 0.105646, Validation accuracy= 0.68180
Epoch 16, CIFAR-10 Batch 1:  Loss = 0.134482, Validation accuracy= 0.67380
Epoch 16, CIFAR-10 Batch 2:  Loss = 0.072012, Validation accuracy= 0.67080
Epoch 16, CIFAR-10 Batch 3:  Loss = 0.073276, Validation accuracy= 0.68000
Epoch 16, CIFAR-10 Batch 4:  Loss = 0.112545, Validation accuracy= 0.67820
Epoch 16, CIFAR-10 Batch 5:  Loss = 0.092598, Validation accuracy= 0.67660
Epoch 17, CIFAR-10 Batch 1:  Loss = 0.085085, Validation accuracy= 0.67620
Epoch 17, CIFAR-10 Batch 2:  Loss = 0.076477, Validation accuracy= 0.66420
Epoch 17, CIFAR-10 Batch 3:  Loss = 0.065239, Validation accuracy= 0.67800
Epoch 17, CIFAR-10 Batch 4:  Loss = 0.089265, Validation accuracy= 0.68380
Epoch 17, CIFAR-10 Batch 5:  Loss = 0.072893, Validation accuracy= 0.67900
Epoch 18, CIFAR-10 Batch 1:  Loss = 0.103340, Validation accuracy= 0.66980
Epoch 18, CIFAR-10 Batch 2:  Loss = 0.053847, Validation accuracy= 0.66660
Epoch 18, CIFAR-10 Batch 3:  Loss = 0.067491, Validation accuracy= 0.67700
Epoch 18, CIFAR-10 Batch 4:  Loss = 0.061970, Validation accuracy= 0.68140
Epoch 18, CIFAR-10 Batch 5:  Loss = 0.061373, Validation accuracy= 0.67900
Epoch 19, CIFAR-10 Batch 1:  Loss = 0.094248, Validation accuracy= 0.68500
Epoch 19, CIFAR-10 Batch 2:  Loss = 0.049302, Validation accuracy= 0.67440
Epoch 19, CIFAR-10 Batch 3:  Loss = 0.053550, Validation accuracy= 0.67640
Epoch 19, CIFAR-10 Batch 4:  Loss = 0.059243, Validation accuracy= 0.68800
Epoch 19, CIFAR-10 Batch 5:  Loss = 0.049381, Validation accuracy= 0.68480
Epoch 20, CIFAR-10 Batch 1:  Loss = 0.055353, Validation accuracy= 0.68240
Epoch 20, CIFAR-10 Batch 2:  Loss = 0.046516, Validation accuracy= 0.65960
Epoch 20, CIFAR-10 Batch 3:  Loss = 0.046675, Validation accuracy= 0.68560
Epoch 20, CIFAR-10 Batch 4:  Loss = 0.037905, Validation accuracy= 0.69120
Epoch 20, CIFAR-10 Batch 5:  Loss = 0.033187, Validation accuracy= 0.68940
Epoch 21, CIFAR-10 Batch 1:  Loss = 0.049178, Validation accuracy= 0.68560
Epoch 21, CIFAR-10 Batch 2:  Loss = 0.031994, Validation accuracy= 0.66860
Epoch 21, CIFAR-10 Batch 3:  Loss = 0.043566, Validation accuracy= 0.68280
Epoch 21, CIFAR-10 Batch 4:  Loss = 0.036855, Validation accuracy= 0.67340
Epoch 21, CIFAR-10 Batch 5:  Loss = 0.030053, Validation accuracy= 0.68700
Epoch 22, CIFAR-10 Batch 1:  Loss = 0.050517, Validation accuracy= 0.69020
Epoch 22, CIFAR-10 Batch 2:  Loss = 0.018214, Validation accuracy= 0.67940
Epoch 22, CIFAR-10 Batch 3:  Loss = 0.035362, Validation accuracy= 0.67660
Epoch 22, CIFAR-10 Batch 4:  Loss = 0.032870, Validation accuracy= 0.68000
Epoch 22, CIFAR-10 Batch 5:  Loss = 0.020368, Validation accuracy= 0.69420
Epoch 23, CIFAR-10 Batch 1:  Loss = 0.047022, Validation accuracy= 0.69280
Epoch 23, CIFAR-10 Batch 2:  Loss = 0.016826, Validation accuracy= 0.67680
Epoch 23, CIFAR-10 Batch 3:  Loss = 0.022533, Validation accuracy= 0.67920
Epoch 23, CIFAR-10 Batch 4:  Loss = 0.022320, Validation accuracy= 0.67860
Epoch 23, CIFAR-10 Batch 5:  Loss = 0.018537, Validation accuracy= 0.69540
Epoch 24, CIFAR-10 Batch 1:  Loss = 0.038939, Validation accuracy= 0.69160
Epoch 24, CIFAR-10 Batch 2:  Loss = 0.017047, Validation accuracy= 0.69160
Epoch 24, CIFAR-10 Batch 3:  Loss = 0.014212, Validation accuracy= 0.68740
Epoch 24, CIFAR-10 Batch 4:  Loss = 0.030373, Validation accuracy= 0.68040
Epoch 24, CIFAR-10 Batch 5:  Loss = 0.017544, Validation accuracy= 0.68900
Epoch 25, CIFAR-10 Batch 1:  Loss = 0.023352, Validation accuracy= 0.68480
Epoch 25, CIFAR-10 Batch 2:  Loss = 0.016333, Validation accuracy= 0.69060
Epoch 25, CIFAR-10 Batch 3:  Loss = 0.021203, Validation accuracy= 0.69420
Epoch 25, CIFAR-10 Batch 4:  Loss = 0.020388, Validation accuracy= 0.68120
Epoch 25, CIFAR-10 Batch 5:  Loss = 0.018951, Validation accuracy= 0.69400
Epoch 26, CIFAR-10 Batch 1:  Loss = 0.025314, Validation accuracy= 0.69460
Epoch 26, CIFAR-10 Batch 2:  Loss = 0.007863, Validation accuracy= 0.68600
Epoch 26, CIFAR-10 Batch 3:  Loss = 0.013899, Validation accuracy= 0.69060
Epoch 26, CIFAR-10 Batch 4:  Loss = 0.016466, Validation accuracy= 0.68320
Epoch 26, CIFAR-10 Batch 5:  Loss = 0.019778, Validation accuracy= 0.69480
Epoch 27, CIFAR-10 Batch 1:  Loss = 0.018133, Validation accuracy= 0.68620
Epoch 27, CIFAR-10 Batch 2:  Loss = 0.007137, Validation accuracy= 0.68480
Epoch 27, CIFAR-10 Batch 3:  Loss = 0.008601, Validation accuracy= 0.68860
Epoch 27, CIFAR-10 Batch 4:  Loss = 0.011091, Validation accuracy= 0.69020
Epoch 27, CIFAR-10 Batch 5:  Loss = 0.022605, Validation accuracy= 0.69000
Epoch 28, CIFAR-10 Batch 1:  Loss = 0.009064, Validation accuracy= 0.68940
Epoch 28, CIFAR-10 Batch 2:  Loss = 0.006080, Validation accuracy= 0.68900
Epoch 28, CIFAR-10 Batch 3:  Loss = 0.008109, Validation accuracy= 0.69040
Epoch 28, CIFAR-10 Batch 4:  Loss = 0.010813, Validation accuracy= 0.68800
Epoch 28, CIFAR-10 Batch 5:  Loss = 0.015975, Validation accuracy= 0.69900
Epoch 29, CIFAR-10 Batch 1:  Loss = 0.011226, Validation accuracy= 0.68020
Epoch 29, CIFAR-10 Batch 2:  Loss = 0.008405, Validation accuracy= 0.69500
Epoch 29, CIFAR-10 Batch 3:  Loss = 0.013315, Validation accuracy= 0.69240
Epoch 29, CIFAR-10 Batch 4:  Loss = 0.004716, Validation accuracy= 0.68860
Epoch 29, CIFAR-10 Batch 5:  Loss = 0.007046, Validation accuracy= 0.69380
Epoch 30, CIFAR-10 Batch 1:  Loss = 0.010359, Validation accuracy= 0.68600
Epoch 30, CIFAR-10 Batch 2:  Loss = 0.008775, Validation accuracy= 0.69720
Epoch 30, CIFAR-10 Batch 3:  Loss = 0.004869, Validation accuracy= 0.69100
Epoch 30, CIFAR-10 Batch 4:  Loss = 0.008777, Validation accuracy= 0.69100
Epoch 30, CIFAR-10 Batch 5:  Loss = 0.003349, Validation accuracy= 0.69820
Epoch 31, CIFAR-10 Batch 1:  Loss = 0.007987, Validation accuracy= 0.67540
Epoch 31, CIFAR-10 Batch 2:  Loss = 0.004993, Validation accuracy= 0.68120
Epoch 31, CIFAR-10 Batch 3:  Loss = 0.004345, Validation accuracy= 0.69240
Epoch 31, CIFAR-10 Batch 4:  Loss = 0.005663, Validation accuracy= 0.68760
Epoch 31, CIFAR-10 Batch 5:  Loss = 0.008630, Validation accuracy= 0.68480
Epoch 32, CIFAR-10 Batch 1:  Loss = 0.007318, Validation accuracy= 0.67600
Epoch 32, CIFAR-10 Batch 2:  Loss = 0.005048, Validation accuracy= 0.68440
Epoch 32, CIFAR-10 Batch 3:  Loss = 0.010432, Validation accuracy= 0.68680
Epoch 32, CIFAR-10 Batch 4:  Loss = 0.004719, Validation accuracy= 0.69140
Epoch 32, CIFAR-10 Batch 5:  Loss = 0.005773, Validation accuracy= 0.69140
Epoch 33, CIFAR-10 Batch 1:  Loss = 0.005463, Validation accuracy= 0.68380
Epoch 33, CIFAR-10 Batch 2:  Loss = 0.005958, Validation accuracy= 0.68640
Epoch 33, CIFAR-10 Batch 3:  Loss = 0.003169, Validation accuracy= 0.69880
Epoch 33, CIFAR-10 Batch 4:  Loss = 0.004385, Validation accuracy= 0.68880
Epoch 33, CIFAR-10 Batch 5:  Loss = 0.003719, Validation accuracy= 0.69500
Epoch 34, CIFAR-10 Batch 1:  Loss = 0.006585, Validation accuracy= 0.67820
Epoch 34, CIFAR-10 Batch 2:  Loss = 0.003241, Validation accuracy= 0.69440
Epoch 34, CIFAR-10 Batch 3:  Loss = 0.002624, Validation accuracy= 0.69020
Epoch 34, CIFAR-10 Batch 4:  Loss = 0.001525, Validation accuracy= 0.68700
Epoch 34, CIFAR-10 Batch 5:  Loss = 0.003613, Validation accuracy= 0.69260
Epoch 35, CIFAR-10 Batch 1:  Loss = 0.004407, Validation accuracy= 0.69080
Epoch 35, CIFAR-10 Batch 2:  Loss = 0.002146, Validation accuracy= 0.69740
Epoch 35, CIFAR-10 Batch 3:  Loss = 0.002892, Validation accuracy= 0.69120
Epoch 35, CIFAR-10 Batch 4:  Loss = 0.003374, Validation accuracy= 0.68840
Epoch 35, CIFAR-10 Batch 5:  Loss = 0.002955, Validation accuracy= 0.68960
Epoch 36, CIFAR-10 Batch 1:  Loss = 0.002694, Validation accuracy= 0.68600
Epoch 36, CIFAR-10 Batch 2:  Loss = 0.005477, Validation accuracy= 0.69680
Epoch 36, CIFAR-10 Batch 3:  Loss = 0.001978, Validation accuracy= 0.69580
Epoch 36, CIFAR-10 Batch 4:  Loss = 0.002978, Validation accuracy= 0.69300
Epoch 36, CIFAR-10 Batch 5:  Loss = 0.006215, Validation accuracy= 0.68340
Epoch 37, CIFAR-10 Batch 1:  Loss = 0.003151, Validation accuracy= 0.68000
Epoch 37, CIFAR-10 Batch 2:  Loss = 0.003436, Validation accuracy= 0.68420
Epoch 37, CIFAR-10 Batch 3:  Loss = 0.002607, Validation accuracy= 0.69600
Epoch 37, CIFAR-10 Batch 4:  Loss = 0.004036, Validation accuracy= 0.69300
Epoch 37, CIFAR-10 Batch 5:  Loss = 0.010199, Validation accuracy= 0.68160
Epoch 38, CIFAR-10 Batch 1:  Loss = 0.006572, Validation accuracy= 0.68500
Epoch 38, CIFAR-10 Batch 2:  Loss = 0.003657, Validation accuracy= 0.70140
Epoch 38, CIFAR-10 Batch 3:  Loss = 0.001546, Validation accuracy= 0.69440
Epoch 38, CIFAR-10 Batch 4:  Loss = 0.003406, Validation accuracy= 0.69340
Epoch 38, CIFAR-10 Batch 5:  Loss = 0.012080, Validation accuracy= 0.69600
Epoch 39, CIFAR-10 Batch 1:  Loss = 0.003407, Validation accuracy= 0.68300
Epoch 39, CIFAR-10 Batch 2:  Loss = 0.001823, Validation accuracy= 0.69520
Epoch 39, CIFAR-10 Batch 3:  Loss = 0.001886, Validation accuracy= 0.70040
Epoch 39, CIFAR-10 Batch 4:  Loss = 0.003066, Validation accuracy= 0.69200
Epoch 39, CIFAR-10 Batch 5:  Loss = 0.001863, Validation accuracy= 0.69760
Epoch 40, CIFAR-10 Batch 1:  Loss = 0.001518, Validation accuracy= 0.68820
Epoch 40, CIFAR-10 Batch 2:  Loss = 0.005469, Validation accuracy= 0.68440
Epoch 40, CIFAR-10 Batch 3:  Loss = 0.001380, Validation accuracy= 0.68740
Epoch 40, CIFAR-10 Batch 4:  Loss = 0.005744, Validation accuracy= 0.68180
Epoch 40, CIFAR-10 Batch 5:  Loss = 0.001693, Validation accuracy= 0.69340
Epoch 41, CIFAR-10 Batch 1:  Loss = 0.002833, Validation accuracy= 0.67340
Epoch 41, CIFAR-10 Batch 2:  Loss = 0.003403, Validation accuracy= 0.69300
Epoch 41, CIFAR-10 Batch 3:  Loss = 0.001181, Validation accuracy= 0.69460
Epoch 41, CIFAR-10 Batch 4:  Loss = 0.001571, Validation accuracy= 0.68520
Epoch 41, CIFAR-10 Batch 5:  Loss = 0.003090, Validation accuracy= 0.68620
Epoch 42, CIFAR-10 Batch 1:  Loss = 0.002446, Validation accuracy= 0.69060
Epoch 42, CIFAR-10 Batch 2:  Loss = 0.001994, Validation accuracy= 0.67700
Epoch 42, CIFAR-10 Batch 3:  Loss = 0.003091, Validation accuracy= 0.68180
Epoch 42, CIFAR-10 Batch 4:  Loss = 0.001362, Validation accuracy= 0.68440
Epoch 42, CIFAR-10 Batch 5:  Loss = 0.004910, Validation accuracy= 0.69540
Epoch 43, CIFAR-10 Batch 1:  Loss = 0.002559, Validation accuracy= 0.68300
Epoch 43, CIFAR-10 Batch 2:  Loss = 0.007655, Validation accuracy= 0.68280
Epoch 43, CIFAR-10 Batch 3:  Loss = 0.005790, Validation accuracy= 0.69100
Epoch 43, CIFAR-10 Batch 4:  Loss = 0.002329, Validation accuracy= 0.68500
Epoch 43, CIFAR-10 Batch 5:  Loss = 0.003101, Validation accuracy= 0.69400
Epoch 44, CIFAR-10 Batch 1:  Loss = 0.001110, Validation accuracy= 0.69040
Epoch 44, CIFAR-10 Batch 2:  Loss = 0.001112, Validation accuracy= 0.67680
Epoch 44, CIFAR-10 Batch 3:  Loss = 0.002105, Validation accuracy= 0.69560
Epoch 44, CIFAR-10 Batch 4:  Loss = 0.002592, Validation accuracy= 0.68520
Epoch 44, CIFAR-10 Batch 5:  Loss = 0.002931, Validation accuracy= 0.69340
Epoch 45, CIFAR-10 Batch 1:  Loss = 0.001157, Validation accuracy= 0.68600
Epoch 45, CIFAR-10 Batch 2:  Loss = 0.001393, Validation accuracy= 0.68460
Epoch 45, CIFAR-10 Batch 3:  Loss = 0.001029, Validation accuracy= 0.69040
Epoch 45, CIFAR-10 Batch 4:  Loss = 0.003776, Validation accuracy= 0.69180
Epoch 45, CIFAR-10 Batch 5:  Loss = 0.004047, Validation accuracy= 0.69540
Epoch 46, CIFAR-10 Batch 1:  Loss = 0.001391, Validation accuracy= 0.68840
Epoch 46, CIFAR-10 Batch 2:  Loss = 0.002411, Validation accuracy= 0.69220
Epoch 46, CIFAR-10 Batch 3:  Loss = 0.000622, Validation accuracy= 0.69260
Epoch 46, CIFAR-10 Batch 4:  Loss = 0.012877, Validation accuracy= 0.69020
Epoch 46, CIFAR-10 Batch 5:  Loss = 0.001266, Validation accuracy= 0.68980
Epoch 47, CIFAR-10 Batch 1:  Loss = 0.002620, Validation accuracy= 0.67980
Epoch 47, CIFAR-10 Batch 2:  Loss = 0.001514, Validation accuracy= 0.68680
Epoch 47, CIFAR-10 Batch 3:  Loss = 0.001192, Validation accuracy= 0.69440
Epoch 47, CIFAR-10 Batch 4:  Loss = 0.001604, Validation accuracy= 0.68900
Epoch 47, CIFAR-10 Batch 5:  Loss = 0.000926, Validation accuracy= 0.69220
Epoch 48, CIFAR-10 Batch 1:  Loss = 0.001306, Validation accuracy= 0.69220
Epoch 48, CIFAR-10 Batch 2:  Loss = 0.002709, Validation accuracy= 0.68020
Epoch 48, CIFAR-10 Batch 3:  Loss = 0.000565, Validation accuracy= 0.69500
Epoch 48, CIFAR-10 Batch 4:  Loss = 0.002891, Validation accuracy= 0.69740
Epoch 48, CIFAR-10 Batch 5:  Loss = 0.003543, Validation accuracy= 0.69400
Epoch 49, CIFAR-10 Batch 1:  Loss = 0.001742, Validation accuracy= 0.69840
Epoch 49, CIFAR-10 Batch 2:  Loss = 0.000635, Validation accuracy= 0.69040
Epoch 49, CIFAR-10 Batch 3:  Loss = 0.000557, Validation accuracy= 0.70260
Epoch 49, CIFAR-10 Batch 4:  Loss = 0.000904, Validation accuracy= 0.69220
Epoch 49, CIFAR-10 Batch 5:  Loss = 0.007569, Validation accuracy= 0.68580
Epoch 50, CIFAR-10 Batch 1:  Loss = 0.001454, Validation accuracy= 0.69780
Epoch 50, CIFAR-10 Batch 2:  Loss = 0.000352, Validation accuracy= 0.69440
Epoch 50, CIFAR-10 Batch 3:  Loss = 0.000618, Validation accuracy= 0.69680
Epoch 50, CIFAR-10 Batch 4:  Loss = 0.001027, Validation accuracy= 0.70220
Epoch 50, CIFAR-10 Batch 5:  Loss = 0.000937, Validation accuracy= 0.69540
Epoch 51, CIFAR-10 Batch 1:  Loss = 0.000769, Validation accuracy= 0.69540
Epoch 51, CIFAR-10 Batch 2:  Loss = 0.000730, Validation accuracy= 0.68760
Epoch 51, CIFAR-10 Batch 3:  Loss = 0.000498, Validation accuracy= 0.70620
Epoch 51, CIFAR-10 Batch 4:  Loss = 0.002078, Validation accuracy= 0.69640
Epoch 51, CIFAR-10 Batch 5:  Loss = 0.000693, Validation accuracy= 0.69860
Epoch 52, CIFAR-10 Batch 1:  Loss = 0.000751, Validation accuracy= 0.69220
Epoch 52, CIFAR-10 Batch 2:  Loss = 0.000313, Validation accuracy= 0.69380
Epoch 52, CIFAR-10 Batch 3:  Loss = 0.000899, Validation accuracy= 0.70080
Epoch 52, CIFAR-10 Batch 4:  Loss = 0.000496, Validation accuracy= 0.69780
Epoch 52, CIFAR-10 Batch 5:  Loss = 0.000789, Validation accuracy= 0.69440
Epoch 53, CIFAR-10 Batch 1:  Loss = 0.002448, Validation accuracy= 0.69860
Epoch 53, CIFAR-10 Batch 2:  Loss = 0.000795, Validation accuracy= 0.69640
Epoch 53, CIFAR-10 Batch 3:  Loss = 0.001506, Validation accuracy= 0.69480
Epoch 53, CIFAR-10 Batch 4:  Loss = 0.001219, Validation accuracy= 0.69580
Epoch 53, CIFAR-10 Batch 5:  Loss = 0.000773, Validation accuracy= 0.69180
Epoch 54, CIFAR-10 Batch 1:  Loss = 0.001675, Validation accuracy= 0.69480
Epoch 54, CIFAR-10 Batch 2:  Loss = 0.000405, Validation accuracy= 0.69580
Epoch 54, CIFAR-10 Batch 3:  Loss = 0.000350, Validation accuracy= 0.69520
Epoch 54, CIFAR-10 Batch 4:  Loss = 0.001365, Validation accuracy= 0.68860
Epoch 54, CIFAR-10 Batch 5:  Loss = 0.000966, Validation accuracy= 0.70740
Epoch 55, CIFAR-10 Batch 1:  Loss = 0.001008, Validation accuracy= 0.70220
Epoch 55, CIFAR-10 Batch 2:  Loss = 0.000392, Validation accuracy= 0.69340
Epoch 55, CIFAR-10 Batch 3:  Loss = 0.000484, Validation accuracy= 0.70080
Epoch 55, CIFAR-10 Batch 4:  Loss = 0.006006, Validation accuracy= 0.68840
Epoch 55, CIFAR-10 Batch 5:  Loss = 0.006892, Validation accuracy= 0.69480
Epoch 56, CIFAR-10 Batch 1:  Loss = 0.001330, Validation accuracy= 0.69680
Epoch 56, CIFAR-10 Batch 2:  Loss = 0.000515, Validation accuracy= 0.69240
Epoch 56, CIFAR-10 Batch 3:  Loss = 0.000289, Validation accuracy= 0.69040
Epoch 56, CIFAR-10 Batch 4:  Loss = 0.001290, Validation accuracy= 0.68840
Epoch 56, CIFAR-10 Batch 5:  Loss = 0.002871, Validation accuracy= 0.69400
Epoch 57, CIFAR-10 Batch 1:  Loss = 0.000323, Validation accuracy= 0.69760
Epoch 57, CIFAR-10 Batch 2:  Loss = 0.000892, Validation accuracy= 0.69460
Epoch 57, CIFAR-10 Batch 3:  Loss = 0.000701, Validation accuracy= 0.69840
Epoch 57, CIFAR-10 Batch 4:  Loss = 0.000595, Validation accuracy= 0.69700
Epoch 57, CIFAR-10 Batch 5:  Loss = 0.000770, Validation accuracy= 0.69140
Epoch 58, CIFAR-10 Batch 1:  Loss = 0.001469, Validation accuracy= 0.69660
Epoch 58, CIFAR-10 Batch 2:  Loss = 0.000512, Validation accuracy= 0.69560
Epoch 58, CIFAR-10 Batch 3:  Loss = 0.000359, Validation accuracy= 0.69400
Epoch 58, CIFAR-10 Batch 4:  Loss = 0.001594, Validation accuracy= 0.68620
Epoch 58, CIFAR-10 Batch 5:  Loss = 0.001354, Validation accuracy= 0.68720
Epoch 59, CIFAR-10 Batch 1:  Loss = 0.003252, Validation accuracy= 0.69200
Epoch 59, CIFAR-10 Batch 2:  Loss = 0.000852, Validation accuracy= 0.69380
Epoch 59, CIFAR-10 Batch 3:  Loss = 0.000555, Validation accuracy= 0.69500
Epoch 59, CIFAR-10 Batch 4:  Loss = 0.000541, Validation accuracy= 0.69720
Epoch 59, CIFAR-10 Batch 5:  Loss = 0.000446, Validation accuracy= 0.69240
Epoch 60, CIFAR-10 Batch 1:  Loss = 0.000343, Validation accuracy= 0.70180
Epoch 60, CIFAR-10 Batch 2:  Loss = 0.000311, Validation accuracy= 0.70020
Epoch 60, CIFAR-10 Batch 3:  Loss = 0.000283, Validation accuracy= 0.69700
Epoch 60, CIFAR-10 Batch 4:  Loss = 0.001350, Validation accuracy= 0.68800
Epoch 60, CIFAR-10 Batch 5:  Loss = 0.001633, Validation accuracy= 0.69680
Epoch 61, CIFAR-10 Batch 1:  Loss = 0.001511, Validation accuracy= 0.69920
Epoch 61, CIFAR-10 Batch 2:  Loss = 0.000836, Validation accuracy= 0.69440
Epoch 61, CIFAR-10 Batch 3:  Loss = 0.000786, Validation accuracy= 0.70220
Epoch 61, CIFAR-10 Batch 4:  Loss = 0.000413, Validation accuracy= 0.69760
Epoch 61, CIFAR-10 Batch 5:  Loss = 0.001535, Validation accuracy= 0.69960
Epoch 62, CIFAR-10 Batch 1:  Loss = 0.001053, Validation accuracy= 0.68920
Epoch 62, CIFAR-10 Batch 2:  Loss = 0.000387, Validation accuracy= 0.69500
Epoch 62, CIFAR-10 Batch 3:  Loss = 0.000517, Validation accuracy= 0.69720
Epoch 62, CIFAR-10 Batch 4:  Loss = 0.001566, Validation accuracy= 0.69100
Epoch 62, CIFAR-10 Batch 5:  Loss = 0.000523, Validation accuracy= 0.69880
Epoch 63, CIFAR-10 Batch 1:  Loss = 0.000493, Validation accuracy= 0.68500
Epoch 63, CIFAR-10 Batch 2:  Loss = 0.000620, Validation accuracy= 0.69220
Epoch 63, CIFAR-10 Batch 3:  Loss = 0.000606, Validation accuracy= 0.69820
Epoch 63, CIFAR-10 Batch 4:  Loss = 0.001762, Validation accuracy= 0.68840
Epoch 63, CIFAR-10 Batch 5:  Loss = 0.001174, Validation accuracy= 0.69340
Epoch 64, CIFAR-10 Batch 1:  Loss = 0.000694, Validation accuracy= 0.69320
Epoch 64, CIFAR-10 Batch 2:  Loss = 0.000532, Validation accuracy= 0.70060
Epoch 64, CIFAR-10 Batch 3:  Loss = 0.001794, Validation accuracy= 0.69420
Epoch 64, CIFAR-10 Batch 4:  Loss = 0.000511, Validation accuracy= 0.69580
Epoch 64, CIFAR-10 Batch 5:  Loss = 0.001233, Validation accuracy= 0.69620
Epoch 65, CIFAR-10 Batch 1:  Loss = 0.000557, Validation accuracy= 0.69340
Epoch 65, CIFAR-10 Batch 2:  Loss = 0.000846, Validation accuracy= 0.70220
Epoch 65, CIFAR-10 Batch 3:  Loss = 0.000567, Validation accuracy= 0.69660
Epoch 65, CIFAR-10 Batch 4:  Loss = 0.000317, Validation accuracy= 0.69720
Epoch 65, CIFAR-10 Batch 5:  Loss = 0.000354, Validation accuracy= 0.70120
Epoch 66, CIFAR-10 Batch 1:  Loss = 0.009938, Validation accuracy= 0.69880
Epoch 66, CIFAR-10 Batch 2:  Loss = 0.000401, Validation accuracy= 0.69840
Epoch 66, CIFAR-10 Batch 3:  Loss = 0.001385, Validation accuracy= 0.69600
Epoch 66, CIFAR-10 Batch 4:  Loss = 0.000767, Validation accuracy= 0.69680
Epoch 66, CIFAR-10 Batch 5:  Loss = 0.001739, Validation accuracy= 0.68860
Epoch 67, CIFAR-10 Batch 1:  Loss = 0.000313, Validation accuracy= 0.69440
Epoch 67, CIFAR-10 Batch 2:  Loss = 0.000208, Validation accuracy= 0.69580
Epoch 67, CIFAR-10 Batch 3:  Loss = 0.000123, Validation accuracy= 0.69640
Epoch 67, CIFAR-10 Batch 4:  Loss = 0.000109, Validation accuracy= 0.69520
Epoch 67, CIFAR-10 Batch 5:  Loss = 0.000672, Validation accuracy= 0.69960
Epoch 68, CIFAR-10 Batch 1:  Loss = 0.000387, Validation accuracy= 0.69620
Epoch 68, CIFAR-10 Batch 2:  Loss = 0.000160, Validation accuracy= 0.69960
Epoch 68, CIFAR-10 Batch 3:  Loss = 0.000084, Validation accuracy= 0.69680
Epoch 68, CIFAR-10 Batch 4:  Loss = 0.000414, Validation accuracy= 0.69680
Epoch 68, CIFAR-10 Batch 5:  Loss = 0.000358, Validation accuracy= 0.70220
Epoch 69, CIFAR-10 Batch 1:  Loss = 0.000891, Validation accuracy= 0.69920
Epoch 69, CIFAR-10 Batch 2:  Loss = 0.000060, Validation accuracy= 0.69500
Epoch 69, CIFAR-10 Batch 3:  Loss = 0.000498, Validation accuracy= 0.68820
Epoch 69, CIFAR-10 Batch 4:  Loss = 0.000718, Validation accuracy= 0.69680
Epoch 69, CIFAR-10 Batch 5:  Loss = 0.000203, Validation accuracy= 0.70420
Epoch 70, CIFAR-10 Batch 1:  Loss = 0.000644, Validation accuracy= 0.69060
Epoch 70, CIFAR-10 Batch 2:  Loss = 0.000273, Validation accuracy= 0.69480
Epoch 70, CIFAR-10 Batch 3:  Loss = 0.000093, Validation accuracy= 0.69800
Epoch 70, CIFAR-10 Batch 4:  Loss = 0.000126, Validation accuracy= 0.69360
Epoch 70, CIFAR-10 Batch 5:  Loss = 0.000176, Validation accuracy= 0.69300
Epoch 71, CIFAR-10 Batch 1:  Loss = 0.000685, Validation accuracy= 0.69580
Epoch 71, CIFAR-10 Batch 2:  Loss = 0.000092, Validation accuracy= 0.69620
Epoch 71, CIFAR-10 Batch 3:  Loss = 0.000162, Validation accuracy= 0.68900
Epoch 71, CIFAR-10 Batch 4:  Loss = 0.000245, Validation accuracy= 0.69360
Epoch 71, CIFAR-10 Batch 5:  Loss = 0.002231, Validation accuracy= 0.69520
Epoch 72, CIFAR-10 Batch 1:  Loss = 0.000815, Validation accuracy= 0.69760
Epoch 72, CIFAR-10 Batch 2:  Loss = 0.000492, Validation accuracy= 0.68720
Epoch 72, CIFAR-10 Batch 3:  Loss = 0.000543, Validation accuracy= 0.69800
Epoch 72, CIFAR-10 Batch 4:  Loss = 0.000450, Validation accuracy= 0.69120
Epoch 72, CIFAR-10 Batch 5:  Loss = 0.000559, Validation accuracy= 0.69320
Epoch 73, CIFAR-10 Batch 1:  Loss = 0.000958, Validation accuracy= 0.69260
Epoch 73, CIFAR-10 Batch 2:  Loss = 0.000432, Validation accuracy= 0.69760
Epoch 73, CIFAR-10 Batch 3:  Loss = 0.000646, Validation accuracy= 0.69480
Epoch 73, CIFAR-10 Batch 4:  Loss = 0.001142, Validation accuracy= 0.69200
Epoch 73, CIFAR-10 Batch 5:  Loss = 0.000122, Validation accuracy= 0.69820
Epoch 74, CIFAR-10 Batch 1:  Loss = 0.000633, Validation accuracy= 0.69260
Epoch 74, CIFAR-10 Batch 2:  Loss = 0.000285, Validation accuracy= 0.69740
Epoch 74, CIFAR-10 Batch 3:  Loss = 0.000065, Validation accuracy= 0.69780
Epoch 74, CIFAR-10 Batch 4:  Loss = 0.000212, Validation accuracy= 0.68880
Epoch 74, CIFAR-10 Batch 5:  Loss = 0.000184, Validation accuracy= 0.69040
Epoch 75, CIFAR-10 Batch 1:  Loss = 0.001102, Validation accuracy= 0.69620
Epoch 75, CIFAR-10 Batch 2:  Loss = 0.000119, Validation accuracy= 0.69640
Epoch 75, CIFAR-10 Batch 3:  Loss = 0.000210, Validation accuracy= 0.70040
Epoch 75, CIFAR-10 Batch 4:  Loss = 0.000065, Validation accuracy= 0.69360
Epoch 75, CIFAR-10 Batch 5:  Loss = 0.000531, Validation accuracy= 0.69480
Epoch 76, CIFAR-10 Batch 1:  Loss = 0.000364, Validation accuracy= 0.69720
Epoch 76, CIFAR-10 Batch 2:  Loss = 0.000052, Validation accuracy= 0.70320
Epoch 76, CIFAR-10 Batch 3:  Loss = 0.000214, Validation accuracy= 0.70120
Epoch 76, CIFAR-10 Batch 4:  Loss = 0.000500, Validation accuracy= 0.69000
Epoch 76, CIFAR-10 Batch 5:  Loss = 0.000644, Validation accuracy= 0.69700
Epoch 77, CIFAR-10 Batch 1:  Loss = 0.000248, Validation accuracy= 0.69680
Epoch 77, CIFAR-10 Batch 2:  Loss = 0.000260, Validation accuracy= 0.69160
Epoch 77, CIFAR-10 Batch 3:  Loss = 0.000120, Validation accuracy= 0.68960
Epoch 77, CIFAR-10 Batch 4:  Loss = 0.000174, Validation accuracy= 0.69260
Epoch 77, CIFAR-10 Batch 5:  Loss = 0.000112, Validation accuracy= 0.69880
Epoch 78, CIFAR-10 Batch 1:  Loss = 0.000269, Validation accuracy= 0.69020
Epoch 78, CIFAR-10 Batch 2:  Loss = 0.000115, Validation accuracy= 0.69700
Epoch 78, CIFAR-10 Batch 3:  Loss = 0.000121, Validation accuracy= 0.69220
Epoch 78, CIFAR-10 Batch 4:  Loss = 0.000301, Validation accuracy= 0.68460
Epoch 78, CIFAR-10 Batch 5:  Loss = 0.000175, Validation accuracy= 0.69360
Epoch 79, CIFAR-10 Batch 1:  Loss = 0.000412, Validation accuracy= 0.69440
Epoch 79, CIFAR-10 Batch 2:  Loss = 0.000460, Validation accuracy= 0.69640
Epoch 79, CIFAR-10 Batch 3:  Loss = 0.000321, Validation accuracy= 0.68480
Epoch 79, CIFAR-10 Batch 4:  Loss = 0.000087, Validation accuracy= 0.69680
Epoch 79, CIFAR-10 Batch 5:  Loss = 0.000080, Validation accuracy= 0.69600
Epoch 80, CIFAR-10 Batch 1:  Loss = 0.001413, Validation accuracy= 0.68360
Epoch 80, CIFAR-10 Batch 2:  Loss = 0.000304, Validation accuracy= 0.68400
Epoch 80, CIFAR-10 Batch 3:  Loss = 0.000291, Validation accuracy= 0.69060
Epoch 80, CIFAR-10 Batch 4:  Loss = 0.000116, Validation accuracy= 0.69360
Epoch 80, CIFAR-10 Batch 5:  Loss = 0.000659, Validation accuracy= 0.69360
Epoch 81, CIFAR-10 Batch 1:  Loss = 0.000145, Validation accuracy= 0.69780
Epoch 81, CIFAR-10 Batch 2:  Loss = 0.000612, Validation accuracy= 0.69320
Epoch 81, CIFAR-10 Batch 3:  Loss = 0.000348, Validation accuracy= 0.68920
Epoch 81, CIFAR-10 Batch 4:  Loss = 0.000038, Validation accuracy= 0.68320
Epoch 81, CIFAR-10 Batch 5:  Loss = 0.000238, Validation accuracy= 0.68800
Epoch 82, CIFAR-10 Batch 1:  Loss = 0.000098, Validation accuracy= 0.69340
Epoch 82, CIFAR-10 Batch 2:  Loss = 0.000533, Validation accuracy= 0.69300
Epoch 82, CIFAR-10 Batch 3:  Loss = 0.000124, Validation accuracy= 0.70020
Epoch 82, CIFAR-10 Batch 4:  Loss = 0.000090, Validation accuracy= 0.69740
Epoch 82, CIFAR-10 Batch 5:  Loss = 0.000054, Validation accuracy= 0.70100
Epoch 83, CIFAR-10 Batch 1:  Loss = 0.000339, Validation accuracy= 0.68760
Epoch 83, CIFAR-10 Batch 2:  Loss = 0.000370, Validation accuracy= 0.68400
Epoch 83, CIFAR-10 Batch 3:  Loss = 0.000091, Validation accuracy= 0.69480
Epoch 83, CIFAR-10 Batch 4:  Loss = 0.000163, Validation accuracy= 0.69180
Epoch 83, CIFAR-10 Batch 5:  Loss = 0.000150, Validation accuracy= 0.69020
Epoch 84, CIFAR-10 Batch 1:  Loss = 0.000217, Validation accuracy= 0.69440
Epoch 84, CIFAR-10 Batch 2:  Loss = 0.000233, Validation accuracy= 0.69100
Epoch 84, CIFAR-10 Batch 3:  Loss = 0.000065, Validation accuracy= 0.69780
Epoch 84, CIFAR-10 Batch 4:  Loss = 0.000131, Validation accuracy= 0.69320
Epoch 84, CIFAR-10 Batch 5:  Loss = 0.000284, Validation accuracy= 0.70240
Epoch 85, CIFAR-10 Batch 1:  Loss = 0.000137, Validation accuracy= 0.69220
Epoch 85, CIFAR-10 Batch 2:  Loss = 0.000567, Validation accuracy= 0.69000
Epoch 85, CIFAR-10 Batch 3:  Loss = 0.000145, Validation accuracy= 0.69060
Epoch 85, CIFAR-10 Batch 4:  Loss = 0.000648, Validation accuracy= 0.68540
Epoch 85, CIFAR-10 Batch 5:  Loss = 0.000315, Validation accuracy= 0.69280
Epoch 86, CIFAR-10 Batch 1:  Loss = 0.000077, Validation accuracy= 0.68940
Epoch 86, CIFAR-10 Batch 2:  Loss = 0.000078, Validation accuracy= 0.68960
Epoch 86, CIFAR-10 Batch 3:  Loss = 0.000220, Validation accuracy= 0.68900
Epoch 86, CIFAR-10 Batch 4:  Loss = 0.000078, Validation accuracy= 0.69180
Epoch 86, CIFAR-10 Batch 5:  Loss = 0.000527, Validation accuracy= 0.69720
Epoch 87, CIFAR-10 Batch 1:  Loss = 0.000422, Validation accuracy= 0.69300
Epoch 87, CIFAR-10 Batch 2:  Loss = 0.000280, Validation accuracy= 0.69380
Epoch 87, CIFAR-10 Batch 3:  Loss = 0.000304, Validation accuracy= 0.69800
Epoch 87, CIFAR-10 Batch 4:  Loss = 0.000095, Validation accuracy= 0.69540
Epoch 87, CIFAR-10 Batch 5:  Loss = 0.000475, Validation accuracy= 0.69300
Epoch 88, CIFAR-10 Batch 1:  Loss = 0.000619, Validation accuracy= 0.69300
Epoch 88, CIFAR-10 Batch 2:  Loss = 0.000308, Validation accuracy= 0.69000
Epoch 88, CIFAR-10 Batch 3:  Loss = 0.000028, Validation accuracy= 0.70260
Epoch 88, CIFAR-10 Batch 4:  Loss = 0.000236, Validation accuracy= 0.69380
Epoch 88, CIFAR-10 Batch 5:  Loss = 0.000149, Validation accuracy= 0.69660
Epoch 89, CIFAR-10 Batch 1:  Loss = 0.000089, Validation accuracy= 0.68980
Epoch 89, CIFAR-10 Batch 2:  Loss = 0.000210, Validation accuracy= 0.68940
Epoch 89, CIFAR-10 Batch 3:  Loss = 0.000058, Validation accuracy= 0.70100
Epoch 89, CIFAR-10 Batch 4:  Loss = 0.000066, Validation accuracy= 0.69280
Epoch 89, CIFAR-10 Batch 5:  Loss = 0.000135, Validation accuracy= 0.69260
Epoch 90, CIFAR-10 Batch 1:  Loss = 0.000031, Validation accuracy= 0.69600
Epoch 90, CIFAR-10 Batch 2:  Loss = 0.001287, Validation accuracy= 0.69520
Epoch 90, CIFAR-10 Batch 3:  Loss = 0.000077, Validation accuracy= 0.70400
Epoch 90, CIFAR-10 Batch 4:  Loss = 0.000134, Validation accuracy= 0.70140
Epoch 90, CIFAR-10 Batch 5:  Loss = 0.000509, Validation accuracy= 0.68600
Epoch 91, CIFAR-10 Batch 1:  Loss = 0.000050, Validation accuracy= 0.69960
Epoch 91, CIFAR-10 Batch 2:  Loss = 0.000088, Validation accuracy= 0.69960
Epoch 91, CIFAR-10 Batch 3:  Loss = 0.000198, Validation accuracy= 0.70260
Epoch 91, CIFAR-10 Batch 4:  Loss = 0.000082, Validation accuracy= 0.68320
Epoch 91, CIFAR-10 Batch 5:  Loss = 0.000683, Validation accuracy= 0.69900
Epoch 92, CIFAR-10 Batch 1:  Loss = 0.000088, Validation accuracy= 0.69960
Epoch 92, CIFAR-10 Batch 2:  Loss = 0.000065, Validation accuracy= 0.69440
Epoch 92, CIFAR-10 Batch 3:  Loss = 0.000329, Validation accuracy= 0.69280
Epoch 92, CIFAR-10 Batch 4:  Loss = 0.000022, Validation accuracy= 0.69820
Epoch 92, CIFAR-10 Batch 5:  Loss = 0.000290, Validation accuracy= 0.69780
Epoch 93, CIFAR-10 Batch 1:  Loss = 0.000028, Validation accuracy= 0.70080
Epoch 93, CIFAR-10 Batch 2:  Loss = 0.000082, Validation accuracy= 0.69640
Epoch 93, CIFAR-10 Batch 3:  Loss = 0.000041, Validation accuracy= 0.69740
Epoch 93, CIFAR-10 Batch 4:  Loss = 0.000025, Validation accuracy= 0.68920
Epoch 93, CIFAR-10 Batch 5:  Loss = 0.000069, Validation accuracy= 0.70420
Epoch 94, CIFAR-10 Batch 1:  Loss = 0.001001, Validation accuracy= 0.70000
Epoch 94, CIFAR-10 Batch 2:  Loss = 0.000224, Validation accuracy= 0.69560
Epoch 94, CIFAR-10 Batch 3:  Loss = 0.000163, Validation accuracy= 0.69520
Epoch 94, CIFAR-10 Batch 4:  Loss = 0.000052, Validation accuracy= 0.69080
Epoch 94, CIFAR-10 Batch 5:  Loss = 0.000111, Validation accuracy= 0.69440
Epoch 95, CIFAR-10 Batch 1:  Loss = 0.000239, Validation accuracy= 0.68720
Epoch 95, CIFAR-10 Batch 2:  Loss = 0.000022, Validation accuracy= 0.69540
Epoch 95, CIFAR-10 Batch 3:  Loss = 0.000146, Validation accuracy= 0.69780
Epoch 95, CIFAR-10 Batch 4:  Loss = 0.000096, Validation accuracy= 0.69100
Epoch 95, CIFAR-10 Batch 5:  Loss = 0.000070, Validation accuracy= 0.69420
Epoch 96, CIFAR-10 Batch 1:  Loss = 0.000554, Validation accuracy= 0.69480
Epoch 96, CIFAR-10 Batch 2:  Loss = 0.000571, Validation accuracy= 0.69100
Epoch 96, CIFAR-10 Batch 3:  Loss = 0.000123, Validation accuracy= 0.69600
Epoch 96, CIFAR-10 Batch 4:  Loss = 0.002325, Validation accuracy= 0.68740
Epoch 96, CIFAR-10 Batch 5:  Loss = 0.000088, Validation accuracy= 0.68780
Epoch 97, CIFAR-10 Batch 1:  Loss = 0.000047, Validation accuracy= 0.69740
Epoch 97, CIFAR-10 Batch 2:  Loss = 0.000039, Validation accuracy= 0.69420
Epoch 97, CIFAR-10 Batch 3:  Loss = 0.000454, Validation accuracy= 0.68800
Epoch 97, CIFAR-10 Batch 4:  Loss = 0.000057, Validation accuracy= 0.68920
Epoch 97, CIFAR-10 Batch 5:  Loss = 0.000024, Validation accuracy= 0.68960
Epoch 98, CIFAR-10 Batch 1:  Loss = 0.000222, Validation accuracy= 0.69620
Epoch 98, CIFAR-10 Batch 2:  Loss = 0.000101, Validation accuracy= 0.69520
Epoch 98, CIFAR-10 Batch 3:  Loss = 0.000094, Validation accuracy= 0.69660
Epoch 98, CIFAR-10 Batch 4:  Loss = 0.000028, Validation accuracy= 0.69420
Epoch 98, CIFAR-10 Batch 5:  Loss = 0.000073, Validation accuracy= 0.69580
Epoch 99, CIFAR-10 Batch 1:  Loss = 0.000226, Validation accuracy= 0.68560
Epoch 99, CIFAR-10 Batch 2:  Loss = 0.000165, Validation accuracy= 0.69080
Epoch 99, CIFAR-10 Batch 3:  Loss = 0.000078, Validation accuracy= 0.69760
Epoch 99, CIFAR-10 Batch 4:  Loss = 0.000014, Validation accuracy= 0.68780
Epoch 99, CIFAR-10 Batch 5:  Loss = 0.000148, Validation accuracy= 0.69520
Epoch 100, CIFAR-10 Batch 1:  Loss = 0.000021, Validation accuracy= 0.69920
Epoch 100, CIFAR-10 Batch 2:  Loss = 0.000063, Validation accuracy= 0.69660
Epoch 100, CIFAR-10 Batch 3:  Loss = 0.000104, Validation accuracy= 0.69760
Epoch 100, CIFAR-10 Batch 4:  Loss = 0.000009, Validation accuracy= 0.69100
Epoch 100, CIFAR-10 Batch 5:  Loss = 0.000039, Validation accuracy= 0.69460

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 [248]:
"""
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_test.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 test_feature_batch, test_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: test_feature_batch, loaded_y: test_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()


Out[248]:
"\nDON'T MODIFY ANYTHING IN THIS CELL\n"
INFO:tensorflow:Restoring parameters from ./image_classification
Testing Accuracy: 0.70087890625

Why 50-80% 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 80%. 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.


In [ ]: