Kaggle Project: Dog Breed Identification (Playground)

Project Page

In this playground competition, you are provided a strictly canine subset of ImageNet in order to practice fine-grained image categorization. How well you can tell your Norfolk Terriers from your Norwich Terriers? With 120 breeds of dogs and a limited number training images per class, you might find the problem more, err, ruff than you anticipated.

File descriptions

  • train.zip - the training set, you are provided the breed for these dogs
  • test.zip - the test set, you must predict the probability of each breed for each image
  • sample_submission.csv - a sample submission file in the correct format
  • labels.csv - the breeds for the images in the train set

Submission File

or each image in the test set, you must predict a probability for each of the different breeds. The file should contain a header and have the following format:

id,affenpinscher,afghan_hound,..,yorkshire_terrier
000621fb3cbb32d8935728e48679680e,0.0083,0.0,...,0.0083
etc.

In [1]:
import math
from glob import glob
import os
import random
from os import listdir
from os.path import isfile, join
from tqdm import tqdm

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import sklearn
import scipy

from sklearn.model_selection import train_test_split

%matplotlib inline

# Import Keras from Tensorflow
import keras
from keras.models import Sequential, Model, load_model
from keras import applications
from keras import optimizers
from keras.callbacks import ModelCheckpoint, EarlyStopping, TensorBoard 
from keras.layers import Dropout, Flatten, Dense, Input
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img


Using TensorFlow backend.

Preview data labels and train/ test images


In [2]:
# Read train label data
train_labels = pd.read_csv("./input/labels.csv")
print("Number of training examples:{}".format(len(train_labels)))
train_labels.head()


Number of training examples:10222
Out[2]:
id breed
0 000bec180eb18c7604dcecc8fe0dba07 boston_bull
1 001513dfcb2ffafc82cccf4d8bbaba97 dingo
2 001cdf01b096e06d78e9e5112d419397 pekinese
3 00214f311d5d2247d5dfe4fe24b2303d bluetick
4 0021f9ceb3235effd7fcde7f7538ed62 golden_retriever

In [3]:
# Turn train_lables to a dic
train_labels_dict = train_labels.set_index('id')['breed'].to_dict()

In [4]:
all_breeds = sorted(train_labels['breed'].unique())

num_breeds = len(all_breeds)
print("Number of Breeds: {}".format(num_breeds))


Number of Breeds: 120

In [5]:
# Set file directories
TRAIN_DIR = './input/train/'
TEST_DIR = './input/test/'
train_file_paths = [(os.path.splitext(os.path.basename(filename))[0], os.path.join(TRAIN_DIR, filename)) 
                    for filename in os.listdir(TRAIN_DIR)]

test_file_paths = [(os.path.splitext(os.path.basename(filename))[0], os.path.join(TEST_DIR, filename)) 
                    for filename in os.listdir(TEST_DIR)]

In [6]:
# Preview train images

fig, axes = plt.subplots(figsize=(20, 20), nrows=10, ncols=1)
plt.tight_layout() # Increases space between subplots

# Randomly select and display images
for ax in axes.flat:
    file_id, file_path = random.choice(train_file_paths)
    img=mpimg.imread(file_path)
    ax.imshow(img)
    ax.set_title("{}, {}, breed:{}".format(file_id, img.shape, train_labels_dict[file_id]))
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)



In [7]:
# Preview test images

fig, axes = plt.subplots(figsize=(20, 20), nrows=10, ncols=1)
plt.tight_layout() # Increases space between subplots

# Randomly select and display images
for ax in axes.flat:
    file_id, file_path = random.choice(test_file_paths)
    img=mpimg.imread(file_path)
    ax.imshow(img)
    ax.set_title("{}, {}".format(file_id, img.shape))
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)


Prepare Data for Supervised Learning Task

Steps

  1. Split train data into train and validation sets
  2. Copy train and validation images into directories so we can use Keras' ImageDataGenerator.flow_from_directory
  3. Convert samples' breed info into numeric labels and one-hot encode them
  4. Set up Image DataGenerator for test and validation sets

In [8]:
# Split train data into train and validation

X_train, X_val, y_train, y_val = train_test_split(train_labels['id'], 
                                                    train_labels['breed'], 
                                                    test_size=0.1, 
                                                    stratify=train_labels['breed'])

In [9]:
# Verify that we have all 120 breeds in both train and validation sets
print(len(y_train.unique()))
print(len(y_val.unique()))


120
120

In [10]:
# Make the temp directories to store the images for train and test sets
import shutil
import os


TRAIN_TEMP_BASEDIR = './input/temp/train'
VALID_TEMP_BASEDIR = './input/temp/valid'

# Remove any existing temp directory
shutil.rmtree('./input/temp', ignore_errors=True)

# Make the directories
os.makedirs(TRAIN_TEMP_BASEDIR)
os.makedirs(VALID_TEMP_BASEDIR)

# Make sub-directory for each breed under TRAIN_TEMP_BASEDIR
for breed in all_breeds:
    os.makedirs(os.path.join(TRAIN_TEMP_BASEDIR, breed))
# Make sub-directory for each breed under TRAIN_TEMP_BASEDIR
for breed in all_breeds:
    os.makedirs(os.path.join(VALID_TEMP_BASEDIR, breed))

In [11]:
# Copy train files to destination based on breed

for index, file_id in X_train.iteritems():
    breed = y_train[index]
    src = os.path.join(TRAIN_DIR, "{}.jpg".format(file_id))
    dst = os.path.join(TRAIN_TEMP_BASEDIR, breed)
    shutil.copy2(src, dst)

In [12]:
# Copy valid files to destination based on breed

for index, file_id in X_val.iteritems():
    breed = y_val[index]
    src = os.path.join(TRAIN_DIR, "{}.jpg".format(file_id))
    dst = os.path.join(VALID_TEMP_BASEDIR, breed)
    shutil.copy2(src, dst)

Set up Keras model and image generator


In [25]:
# Model parameters

IMG_HEIGHT = 299
IMG_WIDTH = 299
BATCH_SIZE = 128
NUM_EPOCHS = 20
FC_SIZE = 1024

In [26]:
# Set up to use combined outputs from both InceptionV3 , Xception , and ResNet50

input_ = Input((IMG_HEIGHT, IMG_WIDTH, 3))

base_model_1 = applications.inception_v3.InceptionV3(include_top=False, 
                                                  weights='imagenet', 
                                                  input_tensor=input_,
                                                  pooling='avg')

base_model_2 = applications.xception.Xception(include_top=False, 
                                                  weights='imagenet', 
                                                  input_tensor=input_,
                                                  pooling='avg')

# base_model_3 = applications.resnet50.ResNet50(include_top=False, 
#                                                   weights='imagenet', 
#                                                   input_tensor=input_,
#                                                   pooling='avg')


# Freeze the base model's layers from training
for layer in base_model_1.layers:
    layer.trainable = False
    
for layer in base_model_2.layers:
    layer.trainable = False
    
# for layer in base_model_3.layers:
#     layer.trainable = False

# Add a hidden layer and a new top layer
x1 = base_model_1.output
x2 = base_model_2.output
# x3 = base_model_3.output
x = keras.layers.concatenate([x1, x2], axis=-1)
x = Dropout(0.5)(x)
predictions = Dense(num_breeds, activation='softmax')(x)

# This is the model we will train
model = Model(inputs=input_, outputs=predictions)

model.compile(loss = 'categorical_crossentropy', 
              optimizer = 'adam', 
              metrics = ['accuracy'])
model.summary()


____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
input_5 (InputLayer)             (None, 299, 299, 3)   0                                            
____________________________________________________________________________________________________
conv2d_393 (Conv2D)              (None, 149, 149, 32)  864         input_5[0][0]                    
____________________________________________________________________________________________________
batch_normalization_393 (BatchNo (None, 149, 149, 32)  96          conv2d_393[0][0]                 
____________________________________________________________________________________________________
activation_426 (Activation)      (None, 149, 149, 32)  0           batch_normalization_393[0][0]    
____________________________________________________________________________________________________
conv2d_394 (Conv2D)              (None, 147, 147, 32)  9216        activation_426[0][0]             
____________________________________________________________________________________________________
batch_normalization_394 (BatchNo (None, 147, 147, 32)  96          conv2d_394[0][0]                 
____________________________________________________________________________________________________
activation_427 (Activation)      (None, 147, 147, 32)  0           batch_normalization_394[0][0]    
____________________________________________________________________________________________________
conv2d_395 (Conv2D)              (None, 147, 147, 64)  18432       activation_427[0][0]             
____________________________________________________________________________________________________
batch_normalization_395 (BatchNo (None, 147, 147, 64)  192         conv2d_395[0][0]                 
____________________________________________________________________________________________________
activation_428 (Activation)      (None, 147, 147, 64)  0           batch_normalization_395[0][0]    
____________________________________________________________________________________________________
max_pooling2d_18 (MaxPooling2D)  (None, 73, 73, 64)    0           activation_428[0][0]             
____________________________________________________________________________________________________
conv2d_396 (Conv2D)              (None, 73, 73, 80)    5120        max_pooling2d_18[0][0]           
____________________________________________________________________________________________________
batch_normalization_396 (BatchNo (None, 73, 73, 80)    240         conv2d_396[0][0]                 
____________________________________________________________________________________________________
activation_429 (Activation)      (None, 73, 73, 80)    0           batch_normalization_396[0][0]    
____________________________________________________________________________________________________
conv2d_397 (Conv2D)              (None, 71, 71, 192)   138240      activation_429[0][0]             
____________________________________________________________________________________________________
batch_normalization_397 (BatchNo (None, 71, 71, 192)   576         conv2d_397[0][0]                 
____________________________________________________________________________________________________
activation_430 (Activation)      (None, 71, 71, 192)   0           batch_normalization_397[0][0]    
____________________________________________________________________________________________________
max_pooling2d_19 (MaxPooling2D)  (None, 35, 35, 192)   0           activation_430[0][0]             
____________________________________________________________________________________________________
conv2d_401 (Conv2D)              (None, 35, 35, 64)    12288       max_pooling2d_19[0][0]           
____________________________________________________________________________________________________
batch_normalization_401 (BatchNo (None, 35, 35, 64)    192         conv2d_401[0][0]                 
____________________________________________________________________________________________________
activation_434 (Activation)      (None, 35, 35, 64)    0           batch_normalization_401[0][0]    
____________________________________________________________________________________________________
conv2d_399 (Conv2D)              (None, 35, 35, 48)    9216        max_pooling2d_19[0][0]           
____________________________________________________________________________________________________
conv2d_402 (Conv2D)              (None, 35, 35, 96)    55296       activation_434[0][0]             
____________________________________________________________________________________________________
batch_normalization_399 (BatchNo (None, 35, 35, 48)    144         conv2d_399[0][0]                 
____________________________________________________________________________________________________
batch_normalization_402 (BatchNo (None, 35, 35, 96)    288         conv2d_402[0][0]                 
____________________________________________________________________________________________________
activation_432 (Activation)      (None, 35, 35, 48)    0           batch_normalization_399[0][0]    
____________________________________________________________________________________________________
activation_435 (Activation)      (None, 35, 35, 96)    0           batch_normalization_402[0][0]    
____________________________________________________________________________________________________
average_pooling2d_37 (AveragePoo (None, 35, 35, 192)   0           max_pooling2d_19[0][0]           
____________________________________________________________________________________________________
conv2d_398 (Conv2D)              (None, 35, 35, 64)    12288       max_pooling2d_19[0][0]           
____________________________________________________________________________________________________
conv2d_400 (Conv2D)              (None, 35, 35, 64)    76800       activation_432[0][0]             
____________________________________________________________________________________________________
conv2d_403 (Conv2D)              (None, 35, 35, 96)    82944       activation_435[0][0]             
____________________________________________________________________________________________________
conv2d_404 (Conv2D)              (None, 35, 35, 32)    6144        average_pooling2d_37[0][0]       
____________________________________________________________________________________________________
batch_normalization_398 (BatchNo (None, 35, 35, 64)    192         conv2d_398[0][0]                 
____________________________________________________________________________________________________
batch_normalization_400 (BatchNo (None, 35, 35, 64)    192         conv2d_400[0][0]                 
____________________________________________________________________________________________________
batch_normalization_403 (BatchNo (None, 35, 35, 96)    288         conv2d_403[0][0]                 
____________________________________________________________________________________________________
batch_normalization_404 (BatchNo (None, 35, 35, 32)    96          conv2d_404[0][0]                 
____________________________________________________________________________________________________
activation_431 (Activation)      (None, 35, 35, 64)    0           batch_normalization_398[0][0]    
____________________________________________________________________________________________________
activation_433 (Activation)      (None, 35, 35, 64)    0           batch_normalization_400[0][0]    
____________________________________________________________________________________________________
activation_436 (Activation)      (None, 35, 35, 96)    0           batch_normalization_403[0][0]    
____________________________________________________________________________________________________
activation_437 (Activation)      (None, 35, 35, 32)    0           batch_normalization_404[0][0]    
____________________________________________________________________________________________________
mixed0 (Concatenate)             (None, 35, 35, 256)   0           activation_431[0][0]             
                                                                   activation_433[0][0]             
                                                                   activation_436[0][0]             
                                                                   activation_437[0][0]             
____________________________________________________________________________________________________
conv2d_408 (Conv2D)              (None, 35, 35, 64)    16384       mixed0[0][0]                     
____________________________________________________________________________________________________
batch_normalization_408 (BatchNo (None, 35, 35, 64)    192         conv2d_408[0][0]                 
____________________________________________________________________________________________________
activation_441 (Activation)      (None, 35, 35, 64)    0           batch_normalization_408[0][0]    
____________________________________________________________________________________________________
conv2d_406 (Conv2D)              (None, 35, 35, 48)    12288       mixed0[0][0]                     
____________________________________________________________________________________________________
conv2d_409 (Conv2D)              (None, 35, 35, 96)    55296       activation_441[0][0]             
____________________________________________________________________________________________________
batch_normalization_406 (BatchNo (None, 35, 35, 48)    144         conv2d_406[0][0]                 
____________________________________________________________________________________________________
batch_normalization_409 (BatchNo (None, 35, 35, 96)    288         conv2d_409[0][0]                 
____________________________________________________________________________________________________
activation_439 (Activation)      (None, 35, 35, 48)    0           batch_normalization_406[0][0]    
____________________________________________________________________________________________________
activation_442 (Activation)      (None, 35, 35, 96)    0           batch_normalization_409[0][0]    
____________________________________________________________________________________________________
average_pooling2d_38 (AveragePoo (None, 35, 35, 256)   0           mixed0[0][0]                     
____________________________________________________________________________________________________
conv2d_405 (Conv2D)              (None, 35, 35, 64)    16384       mixed0[0][0]                     
____________________________________________________________________________________________________
conv2d_407 (Conv2D)              (None, 35, 35, 64)    76800       activation_439[0][0]             
____________________________________________________________________________________________________
conv2d_410 (Conv2D)              (None, 35, 35, 96)    82944       activation_442[0][0]             
____________________________________________________________________________________________________
conv2d_411 (Conv2D)              (None, 35, 35, 64)    16384       average_pooling2d_38[0][0]       
____________________________________________________________________________________________________
block1_conv1 (Conv2D)            (None, 149, 149, 32)  864         input_5[0][0]                    
____________________________________________________________________________________________________
batch_normalization_405 (BatchNo (None, 35, 35, 64)    192         conv2d_405[0][0]                 
____________________________________________________________________________________________________
batch_normalization_407 (BatchNo (None, 35, 35, 64)    192         conv2d_407[0][0]                 
____________________________________________________________________________________________________
batch_normalization_410 (BatchNo (None, 35, 35, 96)    288         conv2d_410[0][0]                 
____________________________________________________________________________________________________
batch_normalization_411 (BatchNo (None, 35, 35, 64)    192         conv2d_411[0][0]                 
____________________________________________________________________________________________________
block1_conv1_bn (BatchNormalizat (None, 149, 149, 32)  128         block1_conv1[0][0]               
____________________________________________________________________________________________________
activation_438 (Activation)      (None, 35, 35, 64)    0           batch_normalization_405[0][0]    
____________________________________________________________________________________________________
activation_440 (Activation)      (None, 35, 35, 64)    0           batch_normalization_407[0][0]    
____________________________________________________________________________________________________
activation_443 (Activation)      (None, 35, 35, 96)    0           batch_normalization_410[0][0]    
____________________________________________________________________________________________________
activation_444 (Activation)      (None, 35, 35, 64)    0           batch_normalization_411[0][0]    
____________________________________________________________________________________________________
block1_conv1_act (Activation)    (None, 149, 149, 32)  0           block1_conv1_bn[0][0]            
____________________________________________________________________________________________________
mixed1 (Concatenate)             (None, 35, 35, 288)   0           activation_438[0][0]             
                                                                   activation_440[0][0]             
                                                                   activation_443[0][0]             
                                                                   activation_444[0][0]             
____________________________________________________________________________________________________
block1_conv2 (Conv2D)            (None, 147, 147, 64)  18432       block1_conv1_act[0][0]           
____________________________________________________________________________________________________
conv2d_415 (Conv2D)              (None, 35, 35, 64)    18432       mixed1[0][0]                     
____________________________________________________________________________________________________
block1_conv2_bn (BatchNormalizat (None, 147, 147, 64)  256         block1_conv2[0][0]               
____________________________________________________________________________________________________
batch_normalization_415 (BatchNo (None, 35, 35, 64)    192         conv2d_415[0][0]                 
____________________________________________________________________________________________________
block1_conv2_act (Activation)    (None, 147, 147, 64)  0           block1_conv2_bn[0][0]            
____________________________________________________________________________________________________
activation_448 (Activation)      (None, 35, 35, 64)    0           batch_normalization_415[0][0]    
____________________________________________________________________________________________________
block2_sepconv1 (SeparableConv2D (None, 147, 147, 128) 8768        block1_conv2_act[0][0]           
____________________________________________________________________________________________________
conv2d_413 (Conv2D)              (None, 35, 35, 48)    13824       mixed1[0][0]                     
____________________________________________________________________________________________________
conv2d_416 (Conv2D)              (None, 35, 35, 96)    55296       activation_448[0][0]             
____________________________________________________________________________________________________
block2_sepconv1_bn (BatchNormali (None, 147, 147, 128) 512         block2_sepconv1[0][0]            
____________________________________________________________________________________________________
batch_normalization_413 (BatchNo (None, 35, 35, 48)    144         conv2d_413[0][0]                 
____________________________________________________________________________________________________
batch_normalization_416 (BatchNo (None, 35, 35, 96)    288         conv2d_416[0][0]                 
____________________________________________________________________________________________________
block2_sepconv2_act (Activation) (None, 147, 147, 128) 0           block2_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
activation_446 (Activation)      (None, 35, 35, 48)    0           batch_normalization_413[0][0]    
____________________________________________________________________________________________________
activation_449 (Activation)      (None, 35, 35, 96)    0           batch_normalization_416[0][0]    
____________________________________________________________________________________________________
average_pooling2d_39 (AveragePoo (None, 35, 35, 288)   0           mixed1[0][0]                     
____________________________________________________________________________________________________
block2_sepconv2 (SeparableConv2D (None, 147, 147, 128) 17536       block2_sepconv2_act[0][0]        
____________________________________________________________________________________________________
conv2d_412 (Conv2D)              (None, 35, 35, 64)    18432       mixed1[0][0]                     
____________________________________________________________________________________________________
conv2d_414 (Conv2D)              (None, 35, 35, 64)    76800       activation_446[0][0]             
____________________________________________________________________________________________________
conv2d_417 (Conv2D)              (None, 35, 35, 96)    82944       activation_449[0][0]             
____________________________________________________________________________________________________
conv2d_418 (Conv2D)              (None, 35, 35, 64)    18432       average_pooling2d_39[0][0]       
____________________________________________________________________________________________________
block2_sepconv2_bn (BatchNormali (None, 147, 147, 128) 512         block2_sepconv2[0][0]            
____________________________________________________________________________________________________
conv2d_487 (Conv2D)              (None, 74, 74, 128)   8192        block1_conv2_act[0][0]           
____________________________________________________________________________________________________
batch_normalization_412 (BatchNo (None, 35, 35, 64)    192         conv2d_412[0][0]                 
____________________________________________________________________________________________________
batch_normalization_414 (BatchNo (None, 35, 35, 64)    192         conv2d_414[0][0]                 
____________________________________________________________________________________________________
batch_normalization_417 (BatchNo (None, 35, 35, 96)    288         conv2d_417[0][0]                 
____________________________________________________________________________________________________
batch_normalization_418 (BatchNo (None, 35, 35, 64)    192         conv2d_418[0][0]                 
____________________________________________________________________________________________________
block2_pool (MaxPooling2D)       (None, 74, 74, 128)   0           block2_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_487 (BatchNo (None, 74, 74, 128)   512         conv2d_487[0][0]                 
____________________________________________________________________________________________________
activation_445 (Activation)      (None, 35, 35, 64)    0           batch_normalization_412[0][0]    
____________________________________________________________________________________________________
activation_447 (Activation)      (None, 35, 35, 64)    0           batch_normalization_414[0][0]    
____________________________________________________________________________________________________
activation_450 (Activation)      (None, 35, 35, 96)    0           batch_normalization_417[0][0]    
____________________________________________________________________________________________________
activation_451 (Activation)      (None, 35, 35, 64)    0           batch_normalization_418[0][0]    
____________________________________________________________________________________________________
add_65 (Add)                     (None, 74, 74, 128)   0           block2_pool[0][0]                
                                                                   batch_normalization_487[0][0]    
____________________________________________________________________________________________________
mixed2 (Concatenate)             (None, 35, 35, 288)   0           activation_445[0][0]             
                                                                   activation_447[0][0]             
                                                                   activation_450[0][0]             
                                                                   activation_451[0][0]             
____________________________________________________________________________________________________
block3_sepconv1_act (Activation) (None, 74, 74, 128)   0           add_65[0][0]                     
____________________________________________________________________________________________________
conv2d_420 (Conv2D)              (None, 35, 35, 64)    18432       mixed2[0][0]                     
____________________________________________________________________________________________________
block3_sepconv1 (SeparableConv2D (None, 74, 74, 256)   33920       block3_sepconv1_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_420 (BatchNo (None, 35, 35, 64)    192         conv2d_420[0][0]                 
____________________________________________________________________________________________________
block3_sepconv1_bn (BatchNormali (None, 74, 74, 256)   1024        block3_sepconv1[0][0]            
____________________________________________________________________________________________________
activation_453 (Activation)      (None, 35, 35, 64)    0           batch_normalization_420[0][0]    
____________________________________________________________________________________________________
block3_sepconv2_act (Activation) (None, 74, 74, 256)   0           block3_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
conv2d_421 (Conv2D)              (None, 35, 35, 96)    55296       activation_453[0][0]             
____________________________________________________________________________________________________
block3_sepconv2 (SeparableConv2D (None, 74, 74, 256)   67840       block3_sepconv2_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_421 (BatchNo (None, 35, 35, 96)    288         conv2d_421[0][0]                 
____________________________________________________________________________________________________
block3_sepconv2_bn (BatchNormali (None, 74, 74, 256)   1024        block3_sepconv2[0][0]            
____________________________________________________________________________________________________
conv2d_488 (Conv2D)              (None, 37, 37, 256)   32768       add_65[0][0]                     
____________________________________________________________________________________________________
activation_454 (Activation)      (None, 35, 35, 96)    0           batch_normalization_421[0][0]    
____________________________________________________________________________________________________
block3_pool (MaxPooling2D)       (None, 37, 37, 256)   0           block3_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_488 (BatchNo (None, 37, 37, 256)   1024        conv2d_488[0][0]                 
____________________________________________________________________________________________________
conv2d_419 (Conv2D)              (None, 17, 17, 384)   995328      mixed2[0][0]                     
____________________________________________________________________________________________________
conv2d_422 (Conv2D)              (None, 17, 17, 96)    82944       activation_454[0][0]             
____________________________________________________________________________________________________
add_66 (Add)                     (None, 37, 37, 256)   0           block3_pool[0][0]                
                                                                   batch_normalization_488[0][0]    
____________________________________________________________________________________________________
batch_normalization_419 (BatchNo (None, 17, 17, 384)   1152        conv2d_419[0][0]                 
____________________________________________________________________________________________________
batch_normalization_422 (BatchNo (None, 17, 17, 96)    288         conv2d_422[0][0]                 
____________________________________________________________________________________________________
block4_sepconv1_act (Activation) (None, 37, 37, 256)   0           add_66[0][0]                     
____________________________________________________________________________________________________
activation_452 (Activation)      (None, 17, 17, 384)   0           batch_normalization_419[0][0]    
____________________________________________________________________________________________________
activation_455 (Activation)      (None, 17, 17, 96)    0           batch_normalization_422[0][0]    
____________________________________________________________________________________________________
max_pooling2d_20 (MaxPooling2D)  (None, 17, 17, 288)   0           mixed2[0][0]                     
____________________________________________________________________________________________________
block4_sepconv1 (SeparableConv2D (None, 37, 37, 728)   188672      block4_sepconv1_act[0][0]        
____________________________________________________________________________________________________
mixed3 (Concatenate)             (None, 17, 17, 768)   0           activation_452[0][0]             
                                                                   activation_455[0][0]             
                                                                   max_pooling2d_20[0][0]           
____________________________________________________________________________________________________
block4_sepconv1_bn (BatchNormali (None, 37, 37, 728)   2912        block4_sepconv1[0][0]            
____________________________________________________________________________________________________
conv2d_427 (Conv2D)              (None, 17, 17, 128)   98304       mixed3[0][0]                     
____________________________________________________________________________________________________
block4_sepconv2_act (Activation) (None, 37, 37, 728)   0           block4_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_427 (BatchNo (None, 17, 17, 128)   384         conv2d_427[0][0]                 
____________________________________________________________________________________________________
block4_sepconv2 (SeparableConv2D (None, 37, 37, 728)   536536      block4_sepconv2_act[0][0]        
____________________________________________________________________________________________________
activation_460 (Activation)      (None, 17, 17, 128)   0           batch_normalization_427[0][0]    
____________________________________________________________________________________________________
block4_sepconv2_bn (BatchNormali (None, 37, 37, 728)   2912        block4_sepconv2[0][0]            
____________________________________________________________________________________________________
conv2d_489 (Conv2D)              (None, 19, 19, 728)   186368      add_66[0][0]                     
____________________________________________________________________________________________________
conv2d_428 (Conv2D)              (None, 17, 17, 128)   114688      activation_460[0][0]             
____________________________________________________________________________________________________
block4_pool (MaxPooling2D)       (None, 19, 19, 728)   0           block4_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_489 (BatchNo (None, 19, 19, 728)   2912        conv2d_489[0][0]                 
____________________________________________________________________________________________________
batch_normalization_428 (BatchNo (None, 17, 17, 128)   384         conv2d_428[0][0]                 
____________________________________________________________________________________________________
add_67 (Add)                     (None, 19, 19, 728)   0           block4_pool[0][0]                
                                                                   batch_normalization_489[0][0]    
____________________________________________________________________________________________________
activation_461 (Activation)      (None, 17, 17, 128)   0           batch_normalization_428[0][0]    
____________________________________________________________________________________________________
block5_sepconv1_act (Activation) (None, 19, 19, 728)   0           add_67[0][0]                     
____________________________________________________________________________________________________
conv2d_424 (Conv2D)              (None, 17, 17, 128)   98304       mixed3[0][0]                     
____________________________________________________________________________________________________
conv2d_429 (Conv2D)              (None, 17, 17, 128)   114688      activation_461[0][0]             
____________________________________________________________________________________________________
block5_sepconv1 (SeparableConv2D (None, 19, 19, 728)   536536      block5_sepconv1_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_424 (BatchNo (None, 17, 17, 128)   384         conv2d_424[0][0]                 
____________________________________________________________________________________________________
batch_normalization_429 (BatchNo (None, 17, 17, 128)   384         conv2d_429[0][0]                 
____________________________________________________________________________________________________
block5_sepconv1_bn (BatchNormali (None, 19, 19, 728)   2912        block5_sepconv1[0][0]            
____________________________________________________________________________________________________
activation_457 (Activation)      (None, 17, 17, 128)   0           batch_normalization_424[0][0]    
____________________________________________________________________________________________________
activation_462 (Activation)      (None, 17, 17, 128)   0           batch_normalization_429[0][0]    
____________________________________________________________________________________________________
block5_sepconv2_act (Activation) (None, 19, 19, 728)   0           block5_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
conv2d_425 (Conv2D)              (None, 17, 17, 128)   114688      activation_457[0][0]             
____________________________________________________________________________________________________
conv2d_430 (Conv2D)              (None, 17, 17, 128)   114688      activation_462[0][0]             
____________________________________________________________________________________________________
block5_sepconv2 (SeparableConv2D (None, 19, 19, 728)   536536      block5_sepconv2_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_425 (BatchNo (None, 17, 17, 128)   384         conv2d_425[0][0]                 
____________________________________________________________________________________________________
batch_normalization_430 (BatchNo (None, 17, 17, 128)   384         conv2d_430[0][0]                 
____________________________________________________________________________________________________
block5_sepconv2_bn (BatchNormali (None, 19, 19, 728)   2912        block5_sepconv2[0][0]            
____________________________________________________________________________________________________
activation_458 (Activation)      (None, 17, 17, 128)   0           batch_normalization_425[0][0]    
____________________________________________________________________________________________________
activation_463 (Activation)      (None, 17, 17, 128)   0           batch_normalization_430[0][0]    
____________________________________________________________________________________________________
average_pooling2d_40 (AveragePoo (None, 17, 17, 768)   0           mixed3[0][0]                     
____________________________________________________________________________________________________
block5_sepconv3_act (Activation) (None, 19, 19, 728)   0           block5_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
conv2d_423 (Conv2D)              (None, 17, 17, 192)   147456      mixed3[0][0]                     
____________________________________________________________________________________________________
conv2d_426 (Conv2D)              (None, 17, 17, 192)   172032      activation_458[0][0]             
____________________________________________________________________________________________________
conv2d_431 (Conv2D)              (None, 17, 17, 192)   172032      activation_463[0][0]             
____________________________________________________________________________________________________
conv2d_432 (Conv2D)              (None, 17, 17, 192)   147456      average_pooling2d_40[0][0]       
____________________________________________________________________________________________________
block5_sepconv3 (SeparableConv2D (None, 19, 19, 728)   536536      block5_sepconv3_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_423 (BatchNo (None, 17, 17, 192)   576         conv2d_423[0][0]                 
____________________________________________________________________________________________________
batch_normalization_426 (BatchNo (None, 17, 17, 192)   576         conv2d_426[0][0]                 
____________________________________________________________________________________________________
batch_normalization_431 (BatchNo (None, 17, 17, 192)   576         conv2d_431[0][0]                 
____________________________________________________________________________________________________
batch_normalization_432 (BatchNo (None, 17, 17, 192)   576         conv2d_432[0][0]                 
____________________________________________________________________________________________________
block5_sepconv3_bn (BatchNormali (None, 19, 19, 728)   2912        block5_sepconv3[0][0]            
____________________________________________________________________________________________________
activation_456 (Activation)      (None, 17, 17, 192)   0           batch_normalization_423[0][0]    
____________________________________________________________________________________________________
activation_459 (Activation)      (None, 17, 17, 192)   0           batch_normalization_426[0][0]    
____________________________________________________________________________________________________
activation_464 (Activation)      (None, 17, 17, 192)   0           batch_normalization_431[0][0]    
____________________________________________________________________________________________________
activation_465 (Activation)      (None, 17, 17, 192)   0           batch_normalization_432[0][0]    
____________________________________________________________________________________________________
add_68 (Add)                     (None, 19, 19, 728)   0           block5_sepconv3_bn[0][0]         
                                                                   add_67[0][0]                     
____________________________________________________________________________________________________
mixed4 (Concatenate)             (None, 17, 17, 768)   0           activation_456[0][0]             
                                                                   activation_459[0][0]             
                                                                   activation_464[0][0]             
                                                                   activation_465[0][0]             
____________________________________________________________________________________________________
block6_sepconv1_act (Activation) (None, 19, 19, 728)   0           add_68[0][0]                     
____________________________________________________________________________________________________
conv2d_437 (Conv2D)              (None, 17, 17, 160)   122880      mixed4[0][0]                     
____________________________________________________________________________________________________
block6_sepconv1 (SeparableConv2D (None, 19, 19, 728)   536536      block6_sepconv1_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_437 (BatchNo (None, 17, 17, 160)   480         conv2d_437[0][0]                 
____________________________________________________________________________________________________
block6_sepconv1_bn (BatchNormali (None, 19, 19, 728)   2912        block6_sepconv1[0][0]            
____________________________________________________________________________________________________
activation_470 (Activation)      (None, 17, 17, 160)   0           batch_normalization_437[0][0]    
____________________________________________________________________________________________________
block6_sepconv2_act (Activation) (None, 19, 19, 728)   0           block6_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
conv2d_438 (Conv2D)              (None, 17, 17, 160)   179200      activation_470[0][0]             
____________________________________________________________________________________________________
block6_sepconv2 (SeparableConv2D (None, 19, 19, 728)   536536      block6_sepconv2_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_438 (BatchNo (None, 17, 17, 160)   480         conv2d_438[0][0]                 
____________________________________________________________________________________________________
block6_sepconv2_bn (BatchNormali (None, 19, 19, 728)   2912        block6_sepconv2[0][0]            
____________________________________________________________________________________________________
activation_471 (Activation)      (None, 17, 17, 160)   0           batch_normalization_438[0][0]    
____________________________________________________________________________________________________
block6_sepconv3_act (Activation) (None, 19, 19, 728)   0           block6_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
conv2d_434 (Conv2D)              (None, 17, 17, 160)   122880      mixed4[0][0]                     
____________________________________________________________________________________________________
conv2d_439 (Conv2D)              (None, 17, 17, 160)   179200      activation_471[0][0]             
____________________________________________________________________________________________________
block6_sepconv3 (SeparableConv2D (None, 19, 19, 728)   536536      block6_sepconv3_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_434 (BatchNo (None, 17, 17, 160)   480         conv2d_434[0][0]                 
____________________________________________________________________________________________________
batch_normalization_439 (BatchNo (None, 17, 17, 160)   480         conv2d_439[0][0]                 
____________________________________________________________________________________________________
block6_sepconv3_bn (BatchNormali (None, 19, 19, 728)   2912        block6_sepconv3[0][0]            
____________________________________________________________________________________________________
activation_467 (Activation)      (None, 17, 17, 160)   0           batch_normalization_434[0][0]    
____________________________________________________________________________________________________
activation_472 (Activation)      (None, 17, 17, 160)   0           batch_normalization_439[0][0]    
____________________________________________________________________________________________________
add_69 (Add)                     (None, 19, 19, 728)   0           block6_sepconv3_bn[0][0]         
                                                                   add_68[0][0]                     
____________________________________________________________________________________________________
conv2d_435 (Conv2D)              (None, 17, 17, 160)   179200      activation_467[0][0]             
____________________________________________________________________________________________________
conv2d_440 (Conv2D)              (None, 17, 17, 160)   179200      activation_472[0][0]             
____________________________________________________________________________________________________
block7_sepconv1_act (Activation) (None, 19, 19, 728)   0           add_69[0][0]                     
____________________________________________________________________________________________________
batch_normalization_435 (BatchNo (None, 17, 17, 160)   480         conv2d_435[0][0]                 
____________________________________________________________________________________________________
batch_normalization_440 (BatchNo (None, 17, 17, 160)   480         conv2d_440[0][0]                 
____________________________________________________________________________________________________
block7_sepconv1 (SeparableConv2D (None, 19, 19, 728)   536536      block7_sepconv1_act[0][0]        
____________________________________________________________________________________________________
activation_468 (Activation)      (None, 17, 17, 160)   0           batch_normalization_435[0][0]    
____________________________________________________________________________________________________
activation_473 (Activation)      (None, 17, 17, 160)   0           batch_normalization_440[0][0]    
____________________________________________________________________________________________________
average_pooling2d_41 (AveragePoo (None, 17, 17, 768)   0           mixed4[0][0]                     
____________________________________________________________________________________________________
block7_sepconv1_bn (BatchNormali (None, 19, 19, 728)   2912        block7_sepconv1[0][0]            
____________________________________________________________________________________________________
conv2d_433 (Conv2D)              (None, 17, 17, 192)   147456      mixed4[0][0]                     
____________________________________________________________________________________________________
conv2d_436 (Conv2D)              (None, 17, 17, 192)   215040      activation_468[0][0]             
____________________________________________________________________________________________________
conv2d_441 (Conv2D)              (None, 17, 17, 192)   215040      activation_473[0][0]             
____________________________________________________________________________________________________
conv2d_442 (Conv2D)              (None, 17, 17, 192)   147456      average_pooling2d_41[0][0]       
____________________________________________________________________________________________________
block7_sepconv2_act (Activation) (None, 19, 19, 728)   0           block7_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_433 (BatchNo (None, 17, 17, 192)   576         conv2d_433[0][0]                 
____________________________________________________________________________________________________
batch_normalization_436 (BatchNo (None, 17, 17, 192)   576         conv2d_436[0][0]                 
____________________________________________________________________________________________________
batch_normalization_441 (BatchNo (None, 17, 17, 192)   576         conv2d_441[0][0]                 
____________________________________________________________________________________________________
batch_normalization_442 (BatchNo (None, 17, 17, 192)   576         conv2d_442[0][0]                 
____________________________________________________________________________________________________
block7_sepconv2 (SeparableConv2D (None, 19, 19, 728)   536536      block7_sepconv2_act[0][0]        
____________________________________________________________________________________________________
activation_466 (Activation)      (None, 17, 17, 192)   0           batch_normalization_433[0][0]    
____________________________________________________________________________________________________
activation_469 (Activation)      (None, 17, 17, 192)   0           batch_normalization_436[0][0]    
____________________________________________________________________________________________________
activation_474 (Activation)      (None, 17, 17, 192)   0           batch_normalization_441[0][0]    
____________________________________________________________________________________________________
activation_475 (Activation)      (None, 17, 17, 192)   0           batch_normalization_442[0][0]    
____________________________________________________________________________________________________
block7_sepconv2_bn (BatchNormali (None, 19, 19, 728)   2912        block7_sepconv2[0][0]            
____________________________________________________________________________________________________
mixed5 (Concatenate)             (None, 17, 17, 768)   0           activation_466[0][0]             
                                                                   activation_469[0][0]             
                                                                   activation_474[0][0]             
                                                                   activation_475[0][0]             
____________________________________________________________________________________________________
block7_sepconv3_act (Activation) (None, 19, 19, 728)   0           block7_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
conv2d_447 (Conv2D)              (None, 17, 17, 160)   122880      mixed5[0][0]                     
____________________________________________________________________________________________________
block7_sepconv3 (SeparableConv2D (None, 19, 19, 728)   536536      block7_sepconv3_act[0][0]        
____________________________________________________________________________________________________
batch_normalization_447 (BatchNo (None, 17, 17, 160)   480         conv2d_447[0][0]                 
____________________________________________________________________________________________________
block7_sepconv3_bn (BatchNormali (None, 19, 19, 728)   2912        block7_sepconv3[0][0]            
____________________________________________________________________________________________________
activation_480 (Activation)      (None, 17, 17, 160)   0           batch_normalization_447[0][0]    
____________________________________________________________________________________________________
add_70 (Add)                     (None, 19, 19, 728)   0           block7_sepconv3_bn[0][0]         
                                                                   add_69[0][0]                     
____________________________________________________________________________________________________
conv2d_448 (Conv2D)              (None, 17, 17, 160)   179200      activation_480[0][0]             
____________________________________________________________________________________________________
block8_sepconv1_act (Activation) (None, 19, 19, 728)   0           add_70[0][0]                     
____________________________________________________________________________________________________
batch_normalization_448 (BatchNo (None, 17, 17, 160)   480         conv2d_448[0][0]                 
____________________________________________________________________________________________________
block8_sepconv1 (SeparableConv2D (None, 19, 19, 728)   536536      block8_sepconv1_act[0][0]        
____________________________________________________________________________________________________
activation_481 (Activation)      (None, 17, 17, 160)   0           batch_normalization_448[0][0]    
____________________________________________________________________________________________________
block8_sepconv1_bn (BatchNormali (None, 19, 19, 728)   2912        block8_sepconv1[0][0]            
____________________________________________________________________________________________________
conv2d_444 (Conv2D)              (None, 17, 17, 160)   122880      mixed5[0][0]                     
____________________________________________________________________________________________________
conv2d_449 (Conv2D)              (None, 17, 17, 160)   179200      activation_481[0][0]             
____________________________________________________________________________________________________
block8_sepconv2_act (Activation) (None, 19, 19, 728)   0           block8_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_444 (BatchNo (None, 17, 17, 160)   480         conv2d_444[0][0]                 
____________________________________________________________________________________________________
batch_normalization_449 (BatchNo (None, 17, 17, 160)   480         conv2d_449[0][0]                 
____________________________________________________________________________________________________
block8_sepconv2 (SeparableConv2D (None, 19, 19, 728)   536536      block8_sepconv2_act[0][0]        
____________________________________________________________________________________________________
activation_477 (Activation)      (None, 17, 17, 160)   0           batch_normalization_444[0][0]    
____________________________________________________________________________________________________
activation_482 (Activation)      (None, 17, 17, 160)   0           batch_normalization_449[0][0]    
____________________________________________________________________________________________________
block8_sepconv2_bn (BatchNormali (None, 19, 19, 728)   2912        block8_sepconv2[0][0]            
____________________________________________________________________________________________________
conv2d_445 (Conv2D)              (None, 17, 17, 160)   179200      activation_477[0][0]             
____________________________________________________________________________________________________
conv2d_450 (Conv2D)              (None, 17, 17, 160)   179200      activation_482[0][0]             
____________________________________________________________________________________________________
block8_sepconv3_act (Activation) (None, 19, 19, 728)   0           block8_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_445 (BatchNo (None, 17, 17, 160)   480         conv2d_445[0][0]                 
____________________________________________________________________________________________________
batch_normalization_450 (BatchNo (None, 17, 17, 160)   480         conv2d_450[0][0]                 
____________________________________________________________________________________________________
block8_sepconv3 (SeparableConv2D (None, 19, 19, 728)   536536      block8_sepconv3_act[0][0]        
____________________________________________________________________________________________________
activation_478 (Activation)      (None, 17, 17, 160)   0           batch_normalization_445[0][0]    
____________________________________________________________________________________________________
activation_483 (Activation)      (None, 17, 17, 160)   0           batch_normalization_450[0][0]    
____________________________________________________________________________________________________
average_pooling2d_42 (AveragePoo (None, 17, 17, 768)   0           mixed5[0][0]                     
____________________________________________________________________________________________________
block8_sepconv3_bn (BatchNormali (None, 19, 19, 728)   2912        block8_sepconv3[0][0]            
____________________________________________________________________________________________________
conv2d_443 (Conv2D)              (None, 17, 17, 192)   147456      mixed5[0][0]                     
____________________________________________________________________________________________________
conv2d_446 (Conv2D)              (None, 17, 17, 192)   215040      activation_478[0][0]             
____________________________________________________________________________________________________
conv2d_451 (Conv2D)              (None, 17, 17, 192)   215040      activation_483[0][0]             
____________________________________________________________________________________________________
conv2d_452 (Conv2D)              (None, 17, 17, 192)   147456      average_pooling2d_42[0][0]       
____________________________________________________________________________________________________
add_71 (Add)                     (None, 19, 19, 728)   0           block8_sepconv3_bn[0][0]         
                                                                   add_70[0][0]                     
____________________________________________________________________________________________________
batch_normalization_443 (BatchNo (None, 17, 17, 192)   576         conv2d_443[0][0]                 
____________________________________________________________________________________________________
batch_normalization_446 (BatchNo (None, 17, 17, 192)   576         conv2d_446[0][0]                 
____________________________________________________________________________________________________
batch_normalization_451 (BatchNo (None, 17, 17, 192)   576         conv2d_451[0][0]                 
____________________________________________________________________________________________________
batch_normalization_452 (BatchNo (None, 17, 17, 192)   576         conv2d_452[0][0]                 
____________________________________________________________________________________________________
block9_sepconv1_act (Activation) (None, 19, 19, 728)   0           add_71[0][0]                     
____________________________________________________________________________________________________
activation_476 (Activation)      (None, 17, 17, 192)   0           batch_normalization_443[0][0]    
____________________________________________________________________________________________________
activation_479 (Activation)      (None, 17, 17, 192)   0           batch_normalization_446[0][0]    
____________________________________________________________________________________________________
activation_484 (Activation)      (None, 17, 17, 192)   0           batch_normalization_451[0][0]    
____________________________________________________________________________________________________
activation_485 (Activation)      (None, 17, 17, 192)   0           batch_normalization_452[0][0]    
____________________________________________________________________________________________________
block9_sepconv1 (SeparableConv2D (None, 19, 19, 728)   536536      block9_sepconv1_act[0][0]        
____________________________________________________________________________________________________
mixed6 (Concatenate)             (None, 17, 17, 768)   0           activation_476[0][0]             
                                                                   activation_479[0][0]             
                                                                   activation_484[0][0]             
                                                                   activation_485[0][0]             
____________________________________________________________________________________________________
block9_sepconv1_bn (BatchNormali (None, 19, 19, 728)   2912        block9_sepconv1[0][0]            
____________________________________________________________________________________________________
conv2d_457 (Conv2D)              (None, 17, 17, 192)   147456      mixed6[0][0]                     
____________________________________________________________________________________________________
block9_sepconv2_act (Activation) (None, 19, 19, 728)   0           block9_sepconv1_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_457 (BatchNo (None, 17, 17, 192)   576         conv2d_457[0][0]                 
____________________________________________________________________________________________________
block9_sepconv2 (SeparableConv2D (None, 19, 19, 728)   536536      block9_sepconv2_act[0][0]        
____________________________________________________________________________________________________
activation_490 (Activation)      (None, 17, 17, 192)   0           batch_normalization_457[0][0]    
____________________________________________________________________________________________________
block9_sepconv2_bn (BatchNormali (None, 19, 19, 728)   2912        block9_sepconv2[0][0]            
____________________________________________________________________________________________________
conv2d_458 (Conv2D)              (None, 17, 17, 192)   258048      activation_490[0][0]             
____________________________________________________________________________________________________
block9_sepconv3_act (Activation) (None, 19, 19, 728)   0           block9_sepconv2_bn[0][0]         
____________________________________________________________________________________________________
batch_normalization_458 (BatchNo (None, 17, 17, 192)   576         conv2d_458[0][0]                 
____________________________________________________________________________________________________
block9_sepconv3 (SeparableConv2D (None, 19, 19, 728)   536536      block9_sepconv3_act[0][0]        
____________________________________________________________________________________________________
activation_491 (Activation)      (None, 17, 17, 192)   0           batch_normalization_458[0][0]    
____________________________________________________________________________________________________
block9_sepconv3_bn (BatchNormali (None, 19, 19, 728)   2912        block9_sepconv3[0][0]            
____________________________________________________________________________________________________
conv2d_454 (Conv2D)              (None, 17, 17, 192)   147456      mixed6[0][0]                     
____________________________________________________________________________________________________
conv2d_459 (Conv2D)              (None, 17, 17, 192)   258048      activation_491[0][0]             
____________________________________________________________________________________________________
add_72 (Add)                     (None, 19, 19, 728)   0           block9_sepconv3_bn[0][0]         
                                                                   add_71[0][0]                     
____________________________________________________________________________________________________
batch_normalization_454 (BatchNo (None, 17, 17, 192)   576         conv2d_454[0][0]                 
____________________________________________________________________________________________________
batch_normalization_459 (BatchNo (None, 17, 17, 192)   576         conv2d_459[0][0]                 
____________________________________________________________________________________________________
block10_sepconv1_act (Activation (None, 19, 19, 728)   0           add_72[0][0]                     
____________________________________________________________________________________________________
activation_487 (Activation)      (None, 17, 17, 192)   0           batch_normalization_454[0][0]    
____________________________________________________________________________________________________
activation_492 (Activation)      (None, 17, 17, 192)   0           batch_normalization_459[0][0]    
____________________________________________________________________________________________________
block10_sepconv1 (SeparableConv2 (None, 19, 19, 728)   536536      block10_sepconv1_act[0][0]       
____________________________________________________________________________________________________
conv2d_455 (Conv2D)              (None, 17, 17, 192)   258048      activation_487[0][0]             
____________________________________________________________________________________________________
conv2d_460 (Conv2D)              (None, 17, 17, 192)   258048      activation_492[0][0]             
____________________________________________________________________________________________________
block10_sepconv1_bn (BatchNormal (None, 19, 19, 728)   2912        block10_sepconv1[0][0]           
____________________________________________________________________________________________________
batch_normalization_455 (BatchNo (None, 17, 17, 192)   576         conv2d_455[0][0]                 
____________________________________________________________________________________________________
batch_normalization_460 (BatchNo (None, 17, 17, 192)   576         conv2d_460[0][0]                 
____________________________________________________________________________________________________
block10_sepconv2_act (Activation (None, 19, 19, 728)   0           block10_sepconv1_bn[0][0]        
____________________________________________________________________________________________________
activation_488 (Activation)      (None, 17, 17, 192)   0           batch_normalization_455[0][0]    
____________________________________________________________________________________________________
activation_493 (Activation)      (None, 17, 17, 192)   0           batch_normalization_460[0][0]    
____________________________________________________________________________________________________
average_pooling2d_43 (AveragePoo (None, 17, 17, 768)   0           mixed6[0][0]                     
____________________________________________________________________________________________________
block10_sepconv2 (SeparableConv2 (None, 19, 19, 728)   536536      block10_sepconv2_act[0][0]       
____________________________________________________________________________________________________
conv2d_453 (Conv2D)              (None, 17, 17, 192)   147456      mixed6[0][0]                     
____________________________________________________________________________________________________
conv2d_456 (Conv2D)              (None, 17, 17, 192)   258048      activation_488[0][0]             
____________________________________________________________________________________________________
conv2d_461 (Conv2D)              (None, 17, 17, 192)   258048      activation_493[0][0]             
____________________________________________________________________________________________________
conv2d_462 (Conv2D)              (None, 17, 17, 192)   147456      average_pooling2d_43[0][0]       
____________________________________________________________________________________________________
block10_sepconv2_bn (BatchNormal (None, 19, 19, 728)   2912        block10_sepconv2[0][0]           
____________________________________________________________________________________________________
batch_normalization_453 (BatchNo (None, 17, 17, 192)   576         conv2d_453[0][0]                 
____________________________________________________________________________________________________
batch_normalization_456 (BatchNo (None, 17, 17, 192)   576         conv2d_456[0][0]                 
____________________________________________________________________________________________________
batch_normalization_461 (BatchNo (None, 17, 17, 192)   576         conv2d_461[0][0]                 
____________________________________________________________________________________________________
batch_normalization_462 (BatchNo (None, 17, 17, 192)   576         conv2d_462[0][0]                 
____________________________________________________________________________________________________
block10_sepconv3_act (Activation (None, 19, 19, 728)   0           block10_sepconv2_bn[0][0]        
____________________________________________________________________________________________________
activation_486 (Activation)      (None, 17, 17, 192)   0           batch_normalization_453[0][0]    
____________________________________________________________________________________________________
activation_489 (Activation)      (None, 17, 17, 192)   0           batch_normalization_456[0][0]    
____________________________________________________________________________________________________
activation_494 (Activation)      (None, 17, 17, 192)   0           batch_normalization_461[0][0]    
____________________________________________________________________________________________________
activation_495 (Activation)      (None, 17, 17, 192)   0           batch_normalization_462[0][0]    
____________________________________________________________________________________________________
block10_sepconv3 (SeparableConv2 (None, 19, 19, 728)   536536      block10_sepconv3_act[0][0]       
____________________________________________________________________________________________________
mixed7 (Concatenate)             (None, 17, 17, 768)   0           activation_486[0][0]             
                                                                   activation_489[0][0]             
                                                                   activation_494[0][0]             
                                                                   activation_495[0][0]             
____________________________________________________________________________________________________
block10_sepconv3_bn (BatchNormal (None, 19, 19, 728)   2912        block10_sepconv3[0][0]           
____________________________________________________________________________________________________
conv2d_465 (Conv2D)              (None, 17, 17, 192)   147456      mixed7[0][0]                     
____________________________________________________________________________________________________
add_73 (Add)                     (None, 19, 19, 728)   0           block10_sepconv3_bn[0][0]        
                                                                   add_72[0][0]                     
____________________________________________________________________________________________________
batch_normalization_465 (BatchNo (None, 17, 17, 192)   576         conv2d_465[0][0]                 
____________________________________________________________________________________________________
block11_sepconv1_act (Activation (None, 19, 19, 728)   0           add_73[0][0]                     
____________________________________________________________________________________________________
activation_498 (Activation)      (None, 17, 17, 192)   0           batch_normalization_465[0][0]    
____________________________________________________________________________________________________
block11_sepconv1 (SeparableConv2 (None, 19, 19, 728)   536536      block11_sepconv1_act[0][0]       
____________________________________________________________________________________________________
conv2d_466 (Conv2D)              (None, 17, 17, 192)   258048      activation_498[0][0]             
____________________________________________________________________________________________________
block11_sepconv1_bn (BatchNormal (None, 19, 19, 728)   2912        block11_sepconv1[0][0]           
____________________________________________________________________________________________________
batch_normalization_466 (BatchNo (None, 17, 17, 192)   576         conv2d_466[0][0]                 
____________________________________________________________________________________________________
block11_sepconv2_act (Activation (None, 19, 19, 728)   0           block11_sepconv1_bn[0][0]        
____________________________________________________________________________________________________
activation_499 (Activation)      (None, 17, 17, 192)   0           batch_normalization_466[0][0]    
____________________________________________________________________________________________________
block11_sepconv2 (SeparableConv2 (None, 19, 19, 728)   536536      block11_sepconv2_act[0][0]       
____________________________________________________________________________________________________
conv2d_463 (Conv2D)              (None, 17, 17, 192)   147456      mixed7[0][0]                     
____________________________________________________________________________________________________
conv2d_467 (Conv2D)              (None, 17, 17, 192)   258048      activation_499[0][0]             
____________________________________________________________________________________________________
block11_sepconv2_bn (BatchNormal (None, 19, 19, 728)   2912        block11_sepconv2[0][0]           
____________________________________________________________________________________________________
batch_normalization_463 (BatchNo (None, 17, 17, 192)   576         conv2d_463[0][0]                 
____________________________________________________________________________________________________
batch_normalization_467 (BatchNo (None, 17, 17, 192)   576         conv2d_467[0][0]                 
____________________________________________________________________________________________________
block11_sepconv3_act (Activation (None, 19, 19, 728)   0           block11_sepconv2_bn[0][0]        
____________________________________________________________________________________________________
activation_496 (Activation)      (None, 17, 17, 192)   0           batch_normalization_463[0][0]    
____________________________________________________________________________________________________
activation_500 (Activation)      (None, 17, 17, 192)   0           batch_normalization_467[0][0]    
____________________________________________________________________________________________________
block11_sepconv3 (SeparableConv2 (None, 19, 19, 728)   536536      block11_sepconv3_act[0][0]       
____________________________________________________________________________________________________
conv2d_464 (Conv2D)              (None, 8, 8, 320)     552960      activation_496[0][0]             
____________________________________________________________________________________________________
conv2d_468 (Conv2D)              (None, 8, 8, 192)     331776      activation_500[0][0]             
____________________________________________________________________________________________________
block11_sepconv3_bn (BatchNormal (None, 19, 19, 728)   2912        block11_sepconv3[0][0]           
____________________________________________________________________________________________________
batch_normalization_464 (BatchNo (None, 8, 8, 320)     960         conv2d_464[0][0]                 
____________________________________________________________________________________________________
batch_normalization_468 (BatchNo (None, 8, 8, 192)     576         conv2d_468[0][0]                 
____________________________________________________________________________________________________
add_74 (Add)                     (None, 19, 19, 728)   0           block11_sepconv3_bn[0][0]        
                                                                   add_73[0][0]                     
____________________________________________________________________________________________________
activation_497 (Activation)      (None, 8, 8, 320)     0           batch_normalization_464[0][0]    
____________________________________________________________________________________________________
activation_501 (Activation)      (None, 8, 8, 192)     0           batch_normalization_468[0][0]    
____________________________________________________________________________________________________
max_pooling2d_21 (MaxPooling2D)  (None, 8, 8, 768)     0           mixed7[0][0]                     
____________________________________________________________________________________________________
block12_sepconv1_act (Activation (None, 19, 19, 728)   0           add_74[0][0]                     
____________________________________________________________________________________________________
mixed8 (Concatenate)             (None, 8, 8, 1280)    0           activation_497[0][0]             
                                                                   activation_501[0][0]             
                                                                   max_pooling2d_21[0][0]           
____________________________________________________________________________________________________
block12_sepconv1 (SeparableConv2 (None, 19, 19, 728)   536536      block12_sepconv1_act[0][0]       
____________________________________________________________________________________________________
conv2d_473 (Conv2D)              (None, 8, 8, 448)     573440      mixed8[0][0]                     
____________________________________________________________________________________________________
block12_sepconv1_bn (BatchNormal (None, 19, 19, 728)   2912        block12_sepconv1[0][0]           
____________________________________________________________________________________________________
batch_normalization_473 (BatchNo (None, 8, 8, 448)     1344        conv2d_473[0][0]                 
____________________________________________________________________________________________________
block12_sepconv2_act (Activation (None, 19, 19, 728)   0           block12_sepconv1_bn[0][0]        
____________________________________________________________________________________________________
activation_506 (Activation)      (None, 8, 8, 448)     0           batch_normalization_473[0][0]    
____________________________________________________________________________________________________
block12_sepconv2 (SeparableConv2 (None, 19, 19, 728)   536536      block12_sepconv2_act[0][0]       
____________________________________________________________________________________________________
conv2d_470 (Conv2D)              (None, 8, 8, 384)     491520      mixed8[0][0]                     
____________________________________________________________________________________________________
conv2d_474 (Conv2D)              (None, 8, 8, 384)     1548288     activation_506[0][0]             
____________________________________________________________________________________________________
block12_sepconv2_bn (BatchNormal (None, 19, 19, 728)   2912        block12_sepconv2[0][0]           
____________________________________________________________________________________________________
batch_normalization_470 (BatchNo (None, 8, 8, 384)     1152        conv2d_470[0][0]                 
____________________________________________________________________________________________________
batch_normalization_474 (BatchNo (None, 8, 8, 384)     1152        conv2d_474[0][0]                 
____________________________________________________________________________________________________
block12_sepconv3_act (Activation (None, 19, 19, 728)   0           block12_sepconv2_bn[0][0]        
____________________________________________________________________________________________________
activation_503 (Activation)      (None, 8, 8, 384)     0           batch_normalization_470[0][0]    
____________________________________________________________________________________________________
activation_507 (Activation)      (None, 8, 8, 384)     0           batch_normalization_474[0][0]    
____________________________________________________________________________________________________
block12_sepconv3 (SeparableConv2 (None, 19, 19, 728)   536536      block12_sepconv3_act[0][0]       
____________________________________________________________________________________________________
conv2d_471 (Conv2D)              (None, 8, 8, 384)     442368      activation_503[0][0]             
____________________________________________________________________________________________________
conv2d_472 (Conv2D)              (None, 8, 8, 384)     442368      activation_503[0][0]             
____________________________________________________________________________________________________
conv2d_475 (Conv2D)              (None, 8, 8, 384)     442368      activation_507[0][0]             
____________________________________________________________________________________________________
conv2d_476 (Conv2D)              (None, 8, 8, 384)     442368      activation_507[0][0]             
____________________________________________________________________________________________________
average_pooling2d_44 (AveragePoo (None, 8, 8, 1280)    0           mixed8[0][0]                     
____________________________________________________________________________________________________
block12_sepconv3_bn (BatchNormal (None, 19, 19, 728)   2912        block12_sepconv3[0][0]           
____________________________________________________________________________________________________
conv2d_469 (Conv2D)              (None, 8, 8, 320)     409600      mixed8[0][0]                     
____________________________________________________________________________________________________
batch_normalization_471 (BatchNo (None, 8, 8, 384)     1152        conv2d_471[0][0]                 
____________________________________________________________________________________________________
batch_normalization_472 (BatchNo (None, 8, 8, 384)     1152        conv2d_472[0][0]                 
____________________________________________________________________________________________________
batch_normalization_475 (BatchNo (None, 8, 8, 384)     1152        conv2d_475[0][0]                 
____________________________________________________________________________________________________
batch_normalization_476 (BatchNo (None, 8, 8, 384)     1152        conv2d_476[0][0]                 
____________________________________________________________________________________________________
conv2d_477 (Conv2D)              (None, 8, 8, 192)     245760      average_pooling2d_44[0][0]       
____________________________________________________________________________________________________
add_75 (Add)                     (None, 19, 19, 728)   0           block12_sepconv3_bn[0][0]        
                                                                   add_74[0][0]                     
____________________________________________________________________________________________________
batch_normalization_469 (BatchNo (None, 8, 8, 320)     960         conv2d_469[0][0]                 
____________________________________________________________________________________________________
activation_504 (Activation)      (None, 8, 8, 384)     0           batch_normalization_471[0][0]    
____________________________________________________________________________________________________
activation_505 (Activation)      (None, 8, 8, 384)     0           batch_normalization_472[0][0]    
____________________________________________________________________________________________________
activation_508 (Activation)      (None, 8, 8, 384)     0           batch_normalization_475[0][0]    
____________________________________________________________________________________________________
activation_509 (Activation)      (None, 8, 8, 384)     0           batch_normalization_476[0][0]    
____________________________________________________________________________________________________
batch_normalization_477 (BatchNo (None, 8, 8, 192)     576         conv2d_477[0][0]                 
____________________________________________________________________________________________________
block13_sepconv1_act (Activation (None, 19, 19, 728)   0           add_75[0][0]                     
____________________________________________________________________________________________________
activation_502 (Activation)      (None, 8, 8, 320)     0           batch_normalization_469[0][0]    
____________________________________________________________________________________________________
mixed9_0 (Concatenate)           (None, 8, 8, 768)     0           activation_504[0][0]             
                                                                   activation_505[0][0]             
____________________________________________________________________________________________________
concatenate_13 (Concatenate)     (None, 8, 8, 768)     0           activation_508[0][0]             
                                                                   activation_509[0][0]             
____________________________________________________________________________________________________
activation_510 (Activation)      (None, 8, 8, 192)     0           batch_normalization_477[0][0]    
____________________________________________________________________________________________________
block13_sepconv1 (SeparableConv2 (None, 19, 19, 728)   536536      block13_sepconv1_act[0][0]       
____________________________________________________________________________________________________
mixed9 (Concatenate)             (None, 8, 8, 2048)    0           activation_502[0][0]             
                                                                   mixed9_0[0][0]                   
                                                                   concatenate_13[0][0]             
                                                                   activation_510[0][0]             
____________________________________________________________________________________________________
block13_sepconv1_bn (BatchNormal (None, 19, 19, 728)   2912        block13_sepconv1[0][0]           
____________________________________________________________________________________________________
conv2d_482 (Conv2D)              (None, 8, 8, 448)     917504      mixed9[0][0]                     
____________________________________________________________________________________________________
block13_sepconv2_act (Activation (None, 19, 19, 728)   0           block13_sepconv1_bn[0][0]        
____________________________________________________________________________________________________
batch_normalization_482 (BatchNo (None, 8, 8, 448)     1344        conv2d_482[0][0]                 
____________________________________________________________________________________________________
block13_sepconv2 (SeparableConv2 (None, 19, 19, 1024)  752024      block13_sepconv2_act[0][0]       
____________________________________________________________________________________________________
activation_515 (Activation)      (None, 8, 8, 448)     0           batch_normalization_482[0][0]    
____________________________________________________________________________________________________
block13_sepconv2_bn (BatchNormal (None, 19, 19, 1024)  4096        block13_sepconv2[0][0]           
____________________________________________________________________________________________________
conv2d_490 (Conv2D)              (None, 10, 10, 1024)  745472      add_75[0][0]                     
____________________________________________________________________________________________________
conv2d_479 (Conv2D)              (None, 8, 8, 384)     786432      mixed9[0][0]                     
____________________________________________________________________________________________________
conv2d_483 (Conv2D)              (None, 8, 8, 384)     1548288     activation_515[0][0]             
____________________________________________________________________________________________________
block13_pool (MaxPooling2D)      (None, 10, 10, 1024)  0           block13_sepconv2_bn[0][0]        
____________________________________________________________________________________________________
batch_normalization_490 (BatchNo (None, 10, 10, 1024)  4096        conv2d_490[0][0]                 
____________________________________________________________________________________________________
batch_normalization_479 (BatchNo (None, 8, 8, 384)     1152        conv2d_479[0][0]                 
____________________________________________________________________________________________________
batch_normalization_483 (BatchNo (None, 8, 8, 384)     1152        conv2d_483[0][0]                 
____________________________________________________________________________________________________
add_76 (Add)                     (None, 10, 10, 1024)  0           block13_pool[0][0]               
                                                                   batch_normalization_490[0][0]    
____________________________________________________________________________________________________
activation_512 (Activation)      (None, 8, 8, 384)     0           batch_normalization_479[0][0]    
____________________________________________________________________________________________________
activation_516 (Activation)      (None, 8, 8, 384)     0           batch_normalization_483[0][0]    
____________________________________________________________________________________________________
block14_sepconv1 (SeparableConv2 (None, 10, 10, 1536)  1582080     add_76[0][0]                     
____________________________________________________________________________________________________
conv2d_480 (Conv2D)              (None, 8, 8, 384)     442368      activation_512[0][0]             
____________________________________________________________________________________________________
conv2d_481 (Conv2D)              (None, 8, 8, 384)     442368      activation_512[0][0]             
____________________________________________________________________________________________________
conv2d_484 (Conv2D)              (None, 8, 8, 384)     442368      activation_516[0][0]             
____________________________________________________________________________________________________
conv2d_485 (Conv2D)              (None, 8, 8, 384)     442368      activation_516[0][0]             
____________________________________________________________________________________________________
average_pooling2d_45 (AveragePoo (None, 8, 8, 2048)    0           mixed9[0][0]                     
____________________________________________________________________________________________________
block14_sepconv1_bn (BatchNormal (None, 10, 10, 1536)  6144        block14_sepconv1[0][0]           
____________________________________________________________________________________________________
conv2d_478 (Conv2D)              (None, 8, 8, 320)     655360      mixed9[0][0]                     
____________________________________________________________________________________________________
batch_normalization_480 (BatchNo (None, 8, 8, 384)     1152        conv2d_480[0][0]                 
____________________________________________________________________________________________________
batch_normalization_481 (BatchNo (None, 8, 8, 384)     1152        conv2d_481[0][0]                 
____________________________________________________________________________________________________
batch_normalization_484 (BatchNo (None, 8, 8, 384)     1152        conv2d_484[0][0]                 
____________________________________________________________________________________________________
batch_normalization_485 (BatchNo (None, 8, 8, 384)     1152        conv2d_485[0][0]                 
____________________________________________________________________________________________________
conv2d_486 (Conv2D)              (None, 8, 8, 192)     393216      average_pooling2d_45[0][0]       
____________________________________________________________________________________________________
block14_sepconv1_act (Activation (None, 10, 10, 1536)  0           block14_sepconv1_bn[0][0]        
____________________________________________________________________________________________________
batch_normalization_478 (BatchNo (None, 8, 8, 320)     960         conv2d_478[0][0]                 
____________________________________________________________________________________________________
activation_513 (Activation)      (None, 8, 8, 384)     0           batch_normalization_480[0][0]    
____________________________________________________________________________________________________
activation_514 (Activation)      (None, 8, 8, 384)     0           batch_normalization_481[0][0]    
____________________________________________________________________________________________________
activation_517 (Activation)      (None, 8, 8, 384)     0           batch_normalization_484[0][0]    
____________________________________________________________________________________________________
activation_518 (Activation)      (None, 8, 8, 384)     0           batch_normalization_485[0][0]    
____________________________________________________________________________________________________
batch_normalization_486 (BatchNo (None, 8, 8, 192)     576         conv2d_486[0][0]                 
____________________________________________________________________________________________________
block14_sepconv2 (SeparableConv2 (None, 10, 10, 2048)  3159552     block14_sepconv1_act[0][0]       
____________________________________________________________________________________________________
activation_511 (Activation)      (None, 8, 8, 320)     0           batch_normalization_478[0][0]    
____________________________________________________________________________________________________
mixed9_1 (Concatenate)           (None, 8, 8, 768)     0           activation_513[0][0]             
                                                                   activation_514[0][0]             
____________________________________________________________________________________________________
concatenate_14 (Concatenate)     (None, 8, 8, 768)     0           activation_517[0][0]             
                                                                   activation_518[0][0]             
____________________________________________________________________________________________________
activation_519 (Activation)      (None, 8, 8, 192)     0           batch_normalization_486[0][0]    
____________________________________________________________________________________________________
block14_sepconv2_bn (BatchNormal (None, 10, 10, 2048)  8192        block14_sepconv2[0][0]           
____________________________________________________________________________________________________
mixed10 (Concatenate)            (None, 8, 8, 2048)    0           activation_511[0][0]             
                                                                   mixed9_1[0][0]                   
                                                                   concatenate_14[0][0]             
                                                                   activation_519[0][0]             
____________________________________________________________________________________________________
block14_sepconv2_act (Activation (None, 10, 10, 2048)  0           block14_sepconv2_bn[0][0]        
____________________________________________________________________________________________________
global_average_pooling2d_10 (Glo (None, 2048)          0           mixed10[0][0]                    
____________________________________________________________________________________________________
global_average_pooling2d_11 (Glo (None, 2048)          0           block14_sepconv2_act[0][0]       
____________________________________________________________________________________________________
concatenate_15 (Concatenate)     (None, 4096)          0           global_average_pooling2d_10[0][0]
                                                                   global_average_pooling2d_11[0][0]
____________________________________________________________________________________________________
dropout_7 (Dropout)              (None, 4096)          0           concatenate_15[0][0]             
____________________________________________________________________________________________________
dense_8 (Dense)                  (None, 120)           491640      dropout_7[0][0]                  
====================================================================================================
Total params: 43,155,904
Trainable params: 491,640
Non-trainable params: 42,664,264
____________________________________________________________________________________________________

In [18]:
train_datagen = ImageDataGenerator(
        rescale=1./255,
        zoom_range=0.2,
        horizontal_flip=True,
        shear_range=0.2,
        width_shift_range=0.2,
        height_shift_range=0.2,
        rotation_range=30
)

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        directory=TRAIN_TEMP_BASEDIR,
        target_size=(IMG_HEIGHT, IMG_WIDTH),
        batch_size=BATCH_SIZE,
        classes=all_breeds)

val_generator = test_datagen.flow_from_directory(
        directory=VALID_TEMP_BASEDIR,
        target_size=(IMG_HEIGHT, IMG_WIDTH),
        batch_size=BATCH_SIZE,
        classes=all_breeds)


Found 9199 images belonging to 120 classes.
Found 1023 images belonging to 120 classes.

In [27]:
callbacks_list = [
    EarlyStopping(monitor = 'val_acc', patience = 3, verbose = 1),
    TensorBoard(log_dir='./logs'),
    ModelCheckpoint('./checkpoints/{epoch:02d}-{val_acc:.2f}.hdf5',
                    monitor='val_acc',
                    verbose=0,
                    save_best_only=True, 
                    mode='auto', period=1)
]


model.fit_generator(
        train_generator,
        steps_per_epoch=len(X_train) // BATCH_SIZE + 1 ,
        epochs=NUM_EPOCHS,
        validation_data=val_generator,
        validation_steps=len(X_val) // BATCH_SIZE + 1,
        callbacks=callbacks_list
)


Epoch 1/20
36/36 [==============================] - 113s - loss: 3.2969 - acc: 0.3539 - val_loss: 1.3402 - val_acc: 0.7949
Epoch 2/20
36/36 [==============================] - 70s - loss: 1.3365 - acc: 0.7011 - val_loss: 0.6459 - val_acc: 0.8395
Epoch 3/20
36/36 [==============================] - 72s - loss: 0.9045 - acc: 0.7756 - val_loss: 0.4943 - val_acc: 0.8787
Epoch 4/20
36/36 [==============================] - 71s - loss: 0.8423 - acc: 0.7738 - val_loss: 0.3979 - val_acc: 0.9043
Epoch 5/20
36/36 [==============================] - 71s - loss: 0.7442 - acc: 0.7921 - val_loss: 0.4318 - val_acc: 0.8789
Epoch 6/20
36/36 [==============================] - 70s - loss: 0.6520 - acc: 0.8197 - val_loss: 0.4154 - val_acc: 0.8885
Epoch 7/20
36/36 [==============================] - 71s - loss: 0.6298 - acc: 0.8164 - val_loss: 0.3954 - val_acc: 0.8924
Epoch 8/20
36/36 [==============================] - 71s - loss: 0.6331 - acc: 0.8070 - val_loss: 0.4072 - val_acc: 0.8770
Epoch 00007: early stopping
Out[27]:
<keras.callbacks.History at 0x7f38897ec3c8>

Run prediction on test images


In [28]:
# Reload model
from keras.models import load_model
model = load_model('./checkpoints/03-0.90.hdf5')

In [29]:
def predict_images(model, file_paths, target_size=None, batch_size=32, rescale=True):

    # Load image and run prediction from file_paths in batches
    all_images = []
    print("Load test images into memory...")
    for file_path in tqdm(file_paths):
        img = load_img(file_path, target_size=target_size)
        if rescale:
            img = img_to_array(img) / 255.0
        else:
            img = img_to_array(img)
        x = np.expand_dims(img, axis=0)
        all_images.append(x)
        
    X = np.concatenate(all_images, axis=0)
    print("Completed loading test images")
    return model.predict(X, batch_size, verbose=1)

In [30]:
test_file_paths = sorted(test_file_paths)
file_paths = [file[1] for file in test_file_paths]
file_ids = [file[0] for file in test_file_paths]

In [31]:
pred = predict_images(model, file_paths, target_size=(IMG_HEIGHT, IMG_WIDTH), batch_size=64)


  0%|          | 26/10357 [00:00<00:40, 257.72it/s]
Load test images into memory...
100%|██████████| 10357/10357 [00:45<00:00, 228.27it/s]
Completed loading test images
10357/10357 [==============================] - 165s   

In [33]:
# Find the predicted classes for each sample
top_classes = np.argmax(pred, axis=1).tolist()

In [35]:
# Preview test images with the predicted class

fig, axes = plt.subplots(figsize=(20, 20), nrows=10, ncols=1)
plt.tight_layout() # Increases space between subplots

test_file_paths_classes = []

for ix,(file_id, file_path) in enumerate(test_file_paths):
    
    test_file_paths_classes.append((file_id, file_path, top_classes[ix]))


# Randomly select and display images
for ax in axes.flat:
    file_id, file_path, top_class = random.choice(test_file_paths_classes)
    img=mpimg.imread(file_path)
    ax.imshow(img)
    ax.set_title("{}, predicted class: {}".format(file_id, all_breeds[top_class]))
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)



In [37]:
# Create submissions.csv
df_submissions = pd.DataFrame(index=file_ids, data=pred, columns=all_breeds)
df_submissions = df_submissions.reset_index()
df_submissions = df_submissions.rename(columns={'index': 'id'})
df_submissions.to_csv('./input/submissions.csv', index=False)