Yumi's Blog

Part 5 Object Detection using YOLOv2 on Pascal VOC2012 - training

In [1]:
import matplotlib.pyplot as plt
import numpy as np
import os, sys
import tensorflow as tf
print(sys.version)
%matplotlib inline
/Users/yumikondo/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
3.6.3 |Anaconda, Inc.| (default, Oct  6 2017, 12:04:38) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]

Define anchor box

ANCHORS defines the number of anchor boxes and the shape of each anchor box. The choice of the anchor box specialization is already discussed in Part 1 Object Detection using YOLOv2 on Pascal VOC2012 - anchor box clustering.

Based on the K-means analysis in the previous blog post, I will select 4 anchor boxes of following width and height. The width and heights are rescaled in the grid cell scale (Assuming that the number of grid size is 13 by 13.) See Part 2 Object Detection using YOLOv2 on Pascal VOC2012 - input and output encoding to learn how I rescal the anchor box shapes into the grid cell scale.

Here I choose 4 anchor boxes. With 13 by 13 grids, every frame gets 4 x 13 x 13 = 676 bouding box predictions.

In [2]:
ANCHORS = np.array([1.07709888,  1.78171903,  # anchor box 1, width , height
                    2.71054693,  5.12469308,  # anchor box 2, width,  height
                   10.47181473, 10.09646365,  # anchor box 3, width,  height
                    5.48531347,  8.11011331]) # anchor box 4, width,  height

Define Label vector containing 20 object classe names.

In [3]:
LABELS = ['aeroplane',  'bicycle', 'bird',  'boat',      'bottle', 
          'bus',        'car',      'cat',  'chair',     'cow',
          'diningtable','dog',    'horse',  'motorbike', 'person',
          'pottedplant','sheep',  'sofa',   'train',   'tvmonitor']

Read images and annotations into memory

Use the pre-processing code for parsing annotation at experiencor/keras-yolo2. This parse_annoation function is already used in Part 1 Object Detection using YOLOv2 on Pascal VOC2012 - anchor box clustering and saved in my python script. This script can be downloaded at my Github repository, FairyOnIce/ObjectDetectionYolo/backend.

In [4]:
### The location where the VOC2012 data is saved.
train_image_folder = "../ObjectDetectionRCNN/VOCdevkit/VOC2012/JPEGImages/"
train_annot_folder = "../ObjectDetectionRCNN/VOCdevkit/VOC2012/Annotations/"

np.random.seed(1)
from backend import parse_annotation
train_image, seen_train_labels = parse_annotation(train_annot_folder,
                                                  train_image_folder, 
                                                  labels=LABELS)
print("N train = {}".format(len(train_image)))
Using TensorFlow backend.
N train = 17125

Instantiate batch generator object

SimpleBatchGenerator is discussed and used in Part 2 Object Detection using YOLOv2 on Pascal VOC2012 - input and output encoding. This script can be downloaded at my Github repository, FairyOnIce/ObjectDetectionYolo/backend.

In [5]:
from backend import SimpleBatchGenerator

BATCH_SIZE        = 200
IMAGE_H, IMAGE_W  = 416, 416
GRID_H,  GRID_W   = 13 , 13
TRUE_BOX_BUFFER   = 50
BOX               = int(len(ANCHORS)/2)

generator_config = {
    'IMAGE_H'         : IMAGE_H, 
    'IMAGE_W'         : IMAGE_W,
    'GRID_H'          : GRID_H,  
    'GRID_W'          : GRID_W,
    'LABELS'          : LABELS,
    'ANCHORS'         : ANCHORS,
    'BATCH_SIZE'      : BATCH_SIZE,
    'TRUE_BOX_BUFFER' : TRUE_BOX_BUFFER,
}


def normalize(image):
    return image / 255.
train_batch_generator = SimpleBatchGenerator(train_image, generator_config,
                                             norm=normalize, shuffle=True)

Define model

We define a YOLO model. The model defenition function is already discussed in Part 3 Object Detection using YOLOv2 on Pascal VOC2012 - model and all the codes are available at my Github.

In [6]:
from backend import define_YOLOv2, set_pretrained_weight, initialize_weight
CLASS             = len(LABELS)
model, true_boxes = define_YOLOv2(IMAGE_H,IMAGE_W,GRID_H,GRID_W,TRUE_BOX_BUFFER,BOX,CLASS, 
                                  trainable=False)
model.summary()
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_image (InputLayer)        (None, 416, 416, 3)  0                                            
__________________________________________________________________________________________________
conv_1 (Conv2D)                 (None, 416, 416, 32) 864         input_image[0][0]                
__________________________________________________________________________________________________
norm_1 (BatchNormalization)     (None, 416, 416, 32) 128         conv_1[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_1 (LeakyReLU)       (None, 416, 416, 32) 0           norm_1[0][0]                     
__________________________________________________________________________________________________
maxpool1_416to208 (MaxPooling2D (None, 208, 208, 32) 0           leaky_re_lu_1[0][0]              
__________________________________________________________________________________________________
conv_2 (Conv2D)                 (None, 208, 208, 64) 18432       maxpool1_416to208[0][0]          
__________________________________________________________________________________________________
norm_2 (BatchNormalization)     (None, 208, 208, 64) 256         conv_2[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_2 (LeakyReLU)       (None, 208, 208, 64) 0           norm_2[0][0]                     
__________________________________________________________________________________________________
maxpool1_208to104 (MaxPooling2D (None, 104, 104, 64) 0           leaky_re_lu_2[0][0]              
__________________________________________________________________________________________________
conv_3 (Conv2D)                 (None, 104, 104, 128 73728       maxpool1_208to104[0][0]          
__________________________________________________________________________________________________
norm_3 (BatchNormalization)     (None, 104, 104, 128 512         conv_3[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_3 (LeakyReLU)       (None, 104, 104, 128 0           norm_3[0][0]                     
__________________________________________________________________________________________________
conv_4 (Conv2D)                 (None, 104, 104, 64) 8192        leaky_re_lu_3[0][0]              
__________________________________________________________________________________________________
norm_4 (BatchNormalization)     (None, 104, 104, 64) 256         conv_4[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU)       (None, 104, 104, 64) 0           norm_4[0][0]                     
__________________________________________________________________________________________________
conv_5 (Conv2D)                 (None, 104, 104, 128 73728       leaky_re_lu_4[0][0]              
__________________________________________________________________________________________________
norm_5 (BatchNormalization)     (None, 104, 104, 128 512         conv_5[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_5 (LeakyReLU)       (None, 104, 104, 128 0           norm_5[0][0]                     
__________________________________________________________________________________________________
maxpool1_104to52 (MaxPooling2D) (None, 52, 52, 128)  0           leaky_re_lu_5[0][0]              
__________________________________________________________________________________________________
conv_6 (Conv2D)                 (None, 52, 52, 256)  294912      maxpool1_104to52[0][0]           
__________________________________________________________________________________________________
norm_6 (BatchNormalization)     (None, 52, 52, 256)  1024        conv_6[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_6 (LeakyReLU)       (None, 52, 52, 256)  0           norm_6[0][0]                     
__________________________________________________________________________________________________
conv_7 (Conv2D)                 (None, 52, 52, 128)  32768       leaky_re_lu_6[0][0]              
__________________________________________________________________________________________________
norm_7 (BatchNormalization)     (None, 52, 52, 128)  512         conv_7[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_7 (LeakyReLU)       (None, 52, 52, 128)  0           norm_7[0][0]                     
__________________________________________________________________________________________________
conv_8 (Conv2D)                 (None, 52, 52, 256)  294912      leaky_re_lu_7[0][0]              
__________________________________________________________________________________________________
norm_8 (BatchNormalization)     (None, 52, 52, 256)  1024        conv_8[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_8 (LeakyReLU)       (None, 52, 52, 256)  0           norm_8[0][0]                     
__________________________________________________________________________________________________
maxpool1_52to26 (MaxPooling2D)  (None, 26, 26, 256)  0           leaky_re_lu_8[0][0]              
__________________________________________________________________________________________________
conv_9 (Conv2D)                 (None, 26, 26, 512)  1179648     maxpool1_52to26[0][0]            
__________________________________________________________________________________________________
norm_9 (BatchNormalization)     (None, 26, 26, 512)  2048        conv_9[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_9 (LeakyReLU)       (None, 26, 26, 512)  0           norm_9[0][0]                     
__________________________________________________________________________________________________
conv_10 (Conv2D)                (None, 26, 26, 256)  131072      leaky_re_lu_9[0][0]              
__________________________________________________________________________________________________
norm_10 (BatchNormalization)    (None, 26, 26, 256)  1024        conv_10[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_10 (LeakyReLU)      (None, 26, 26, 256)  0           norm_10[0][0]                    
__________________________________________________________________________________________________
conv_11 (Conv2D)                (None, 26, 26, 512)  1179648     leaky_re_lu_10[0][0]             
__________________________________________________________________________________________________
norm_11 (BatchNormalization)    (None, 26, 26, 512)  2048        conv_11[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_11 (LeakyReLU)      (None, 26, 26, 512)  0           norm_11[0][0]                    
__________________________________________________________________________________________________
conv_12 (Conv2D)                (None, 26, 26, 256)  131072      leaky_re_lu_11[0][0]             
__________________________________________________________________________________________________
norm_12 (BatchNormalization)    (None, 26, 26, 256)  1024        conv_12[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_12 (LeakyReLU)      (None, 26, 26, 256)  0           norm_12[0][0]                    
__________________________________________________________________________________________________
conv_13 (Conv2D)                (None, 26, 26, 512)  1179648     leaky_re_lu_12[0][0]             
__________________________________________________________________________________________________
norm_13 (BatchNormalization)    (None, 26, 26, 512)  2048        conv_13[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_13 (LeakyReLU)      (None, 26, 26, 512)  0           norm_13[0][0]                    
__________________________________________________________________________________________________
maxpool1_26to13 (MaxPooling2D)  (None, 13, 13, 512)  0           leaky_re_lu_13[0][0]             
__________________________________________________________________________________________________
conv_14 (Conv2D)                (None, 13, 13, 1024) 4718592     maxpool1_26to13[0][0]            
__________________________________________________________________________________________________
norm_14 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_14[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_14 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_14[0][0]                    
__________________________________________________________________________________________________
conv_15 (Conv2D)                (None, 13, 13, 512)  524288      leaky_re_lu_14[0][0]             
__________________________________________________________________________________________________
norm_15 (BatchNormalization)    (None, 13, 13, 512)  2048        conv_15[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_15 (LeakyReLU)      (None, 13, 13, 512)  0           norm_15[0][0]                    
__________________________________________________________________________________________________
conv_16 (Conv2D)                (None, 13, 13, 1024) 4718592     leaky_re_lu_15[0][0]             
__________________________________________________________________________________________________
norm_16 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_16[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_16 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_16[0][0]                    
__________________________________________________________________________________________________
conv_17 (Conv2D)                (None, 13, 13, 512)  524288      leaky_re_lu_16[0][0]             
__________________________________________________________________________________________________
norm_17 (BatchNormalization)    (None, 13, 13, 512)  2048        conv_17[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_17 (LeakyReLU)      (None, 13, 13, 512)  0           norm_17[0][0]                    
__________________________________________________________________________________________________
conv_18 (Conv2D)                (None, 13, 13, 1024) 4718592     leaky_re_lu_17[0][0]             
__________________________________________________________________________________________________
norm_18 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_18[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_18 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_18[0][0]                    
__________________________________________________________________________________________________
conv_19 (Conv2D)                (None, 13, 13, 1024) 9437184     leaky_re_lu_18[0][0]             
__________________________________________________________________________________________________
norm_19 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_19[0][0]                    
__________________________________________________________________________________________________
conv_21 (Conv2D)                (None, 26, 26, 64)   32768       leaky_re_lu_13[0][0]             
__________________________________________________________________________________________________
leaky_re_lu_19 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_19[0][0]                    
__________________________________________________________________________________________________
norm_21 (BatchNormalization)    (None, 26, 26, 64)   256         conv_21[0][0]                    
__________________________________________________________________________________________________
conv_20 (Conv2D)                (None, 13, 13, 1024) 9437184     leaky_re_lu_19[0][0]             
__________________________________________________________________________________________________
leaky_re_lu_21 (LeakyReLU)      (None, 26, 26, 64)   0           norm_21[0][0]                    
__________________________________________________________________________________________________
norm_20 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_20[0][0]                    
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 13, 13, 256)  0           leaky_re_lu_21[0][0]             
__________________________________________________________________________________________________
leaky_re_lu_20 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_20[0][0]                    
__________________________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 13, 13, 1280) 0           lambda_1[0][0]                   
                                                                 leaky_re_lu_20[0][0]             
__________________________________________________________________________________________________
conv_22 (Conv2D)                (None, 13, 13, 1024) 11796480    concatenate_1[0][0]              
__________________________________________________________________________________________________
norm_22 (BatchNormalization)    (None, 13, 13, 1024) 4096        conv_22[0][0]                    
__________________________________________________________________________________________________
leaky_re_lu_22 (LeakyReLU)      (None, 13, 13, 1024) 0           norm_22[0][0]                    
__________________________________________________________________________________________________
conv_23 (Conv2D)                (None, 13, 13, 100)  102500      leaky_re_lu_22[0][0]             
__________________________________________________________________________________________________
final_output (Reshape)          (None, 13, 13, 4, 25 0           conv_23[0][0]                    
__________________________________________________________________________________________________
input_hack (InputLayer)         (None, 1, 1, 1, 50,  0                                            
__________________________________________________________________________________________________
hack_layer (Lambda)             (None, 13, 13, 4, 25 0           final_output[0][0]               
                                                                 input_hack[0][0]                 
==================================================================================================
Total params: 50,650,436
Trainable params: 102,500
Non-trainable params: 50,547,936
__________________________________________________________________________________________________

Initialize the weights

The initialization of weights are already discussed in Part 3 Object Detection using YOLOv2 on Pascal VOC2012 - model. All the codes from Part 3 are stored at my Github.

In [7]:
path_to_weight = "./yolov2.weights"
nb_conv        = 22
model          = set_pretrained_weight(model,nb_conv, path_to_weight)
layer          = model.layers[-4] # the last convolutional layer
initialize_weight(layer,sd=1/(GRID_H*GRID_W))

Loss function

We already discussed the loss function of YOLOv2 implemented by experiencor/keras-yolo2 in Part 4 Object Detection using YOLOv2 on Pascal VOC2012 - loss. I modified the codes and the codes are available at my Github.

In [8]:
from backend import custom_loss_core 
help(custom_loss_core)
Help on function custom_loss_core in module backend:

custom_loss_core(y_true, y_pred, true_boxes, GRID_W, GRID_H, BATCH_SIZE, ANCHORS, LAMBDA_COORD, LAMBDA_CLASS, LAMBDA_NO_OBJECT, LAMBDA_OBJECT)
    y_true : (N batch, N grid h, N grid w, N anchor, 4 + 1 + N classes)
    y_true[irow, i_gridh, i_gridw, i_anchor, :4] = center_x, center_y, w, h
    
        center_x : The x coordinate center of the bounding box.
                   Rescaled to range between 0 and N gird  w (e.g., ranging between [0,13)
        center_y : The y coordinate center of the bounding box.
                   Rescaled to range between 0 and N gird  h (e.g., ranging between [0,13)
        w        : The width of the bounding box.
                   Rescaled to range between 0 and N gird  w (e.g., ranging between [0,13)
        h        : The height of the bounding box.
                   Rescaled to range between 0 and N gird  h (e.g., ranging between [0,13)
                   
    y_true[irow, i_gridh, i_gridw, i_anchor, 4] = ground truth confidence
        
        ground truth confidence is 1 if object exists in this (anchor box, gird cell) pair
    
    y_true[irow, i_gridh, i_gridw, i_anchor, 5 + iclass] = 1 if the object is in category  else 0
    
    =====================================================
    tensor that connect to the YOLO model's hack input 
    =====================================================    
    
    true_boxes    
    
    =========================================
    training parameters specification example 
    =========================================
    GRID_W             = 13
    GRID_H             = 13
    BATCH_SIZE         = 34
    ANCHORS = np.array([1.07709888,  1.78171903,  # anchor box 1, width , height
                        2.71054693,  5.12469308,  # anchor box 2, width,  height
                       10.47181473, 10.09646365,  # anchor box 3, width,  height
                        5.48531347,  8.11011331]) # anchor box 4, width,  height
    LAMBDA_NO_OBJECT = 1.0
    LAMBDA_OBJECT    = 5.0
    LAMBDA_COORD     = 1.0
    LAMBDA_CLASS     = 1.0

Notice that this custom function custom_loss_core depends not only on y_true and y_pred but also the various hayperparameters. Unfortunately, Keras's loss function API does not accept any parameters except y_true and y_pred. Therefore, these hyperparameters need to be defined globaly. To do this, I will define a wrapper function custom_loss.

In [9]:
GRID_W             = 13
GRID_H             = 13
BATCH_SIZE         = 34
LAMBDA_NO_OBJECT = 1.0
LAMBDA_OBJECT    = 5.0
LAMBDA_COORD     = 1.0
LAMBDA_CLASS     = 1.0
    
def custom_loss(y_true, y_pred):
    return(custom_loss_core(
                     y_true,
                     y_pred,
                     true_boxes,
                     GRID_W,
                     GRID_H,
                     BATCH_SIZE,
                     ANCHORS,
                     LAMBDA_COORD,
                     LAMBDA_CLASS,
                     LAMBDA_NO_OBJECT, 
                     LAMBDA_OBJECT))
    

Training starts here!

Finally, we start the training here. We only train the final 23rd layer and freeze the other weights. This is because I am unfortunately using CPU environment.

In [10]:
from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.optimizers import SGD, Adam, RMSprop

dir_log = "logs/"
try:
    os.makedirs(dir_log)
except:
    pass


BATCH_SIZE   = 32
generator_config['BATCH_SIZE'] = BATCH_SIZE

early_stop = EarlyStopping(monitor='loss', 
                           min_delta=0.001, 
                           patience=3, 
                           mode='min', 
                           verbose=1)

checkpoint = ModelCheckpoint('weights_yolo_on_voc2012.h5', 
                             monitor='loss', 
                             verbose=1, 
                             save_best_only=True, 
                             mode='min', 
                             period=1)


optimizer = Adam(lr=0.5e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
#optimizer = SGD(lr=1e-4, decay=0.0005, momentum=0.9)
#optimizer = RMSprop(lr=1e-4, rho=0.9, epsilon=1e-08, decay=0.0)

model.compile(loss=custom_loss, optimizer=optimizer)
WARNING:tensorflow:From /Users/yumikondo/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1349: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
In [ ]:
model.fit_generator(generator        = train_batch_generator, 
                    steps_per_epoch  = len(train_batch_generator), 
                    epochs           = 50, 
                    verbose          = 1,
                    #validation_data  = valid_batch,
                    #validation_steps = len(valid_batch),
                    callbacks        = [early_stop, checkpoint], 
                    max_queue_size   = 3)
WARNING:tensorflow:From /Users/yumikondo/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1349: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
Epoch 1/50
535/536 [============================>.] - ETA: 24s - loss: 3.4066Epoch 00001: loss improved from inf to 3.40433, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 13142s 25s/step - loss: 3.4043
Epoch 2/50
535/536 [============================>.] - ETA: 20s - loss: 2.2446Epoch 00002: loss improved from 3.40433 to 2.24404, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 11008s 21s/step - loss: 2.2440
Epoch 3/50
535/536 [============================>.] - ETA: 19s - loss: 1.8147Epoch 00003: loss improved from 2.24404 to 1.81350, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10618s 20s/step - loss: 1.8135
Epoch 4/50
535/536 [============================>.] - ETA: 19s - loss: 1.5694Epoch 00004: loss improved from 1.81350 to 1.56886, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10390s 19s/step - loss: 1.5689
Epoch 5/50
535/536 [============================>.] - ETA: 19s - loss: 1.4156Epoch 00005: loss improved from 1.56886 to 1.41503, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10414s 19s/step - loss: 1.4150
Epoch 6/50
535/536 [============================>.] - ETA: 19s - loss: 1.3039Epoch 00006: loss improved from 1.41503 to 1.30439, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10340s 19s/step - loss: 1.3044
Epoch 7/50
535/536 [============================>.] - ETA: 19s - loss: 1.2295Epoch 00007: loss improved from 1.30439 to 1.22947, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10236s 19s/step - loss: 1.2295
Epoch 8/50
535/536 [============================>.] - ETA: 19s - loss: 1.1702Epoch 00008: loss improved from 1.22947 to 1.16959, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10268s 19s/step - loss: 1.1696
Epoch 9/50
535/536 [============================>.] - ETA: 19s - loss: 1.1217Epoch 00009: loss improved from 1.16959 to 1.12201, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10243s 19s/step - loss: 1.1220
Epoch 10/50
535/536 [============================>.] - ETA: 18s - loss: 1.0834Epoch 00010: loss improved from 1.12201 to 1.08334, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10162s 19s/step - loss: 1.0833
Epoch 11/50
535/536 [============================>.] - ETA: 19s - loss: 1.0535Epoch 00011: loss improved from 1.08334 to 1.05358, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10433s 19s/step - loss: 1.0536
Epoch 12/50
535/536 [============================>.] - ETA: 18s - loss: 1.0263Epoch 00012: loss improved from 1.05358 to 1.02609, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10143s 19s/step - loss: 1.0261
Epoch 13/50
535/536 [============================>.] - ETA: 19s - loss: 1.0024Epoch 00013: loss improved from 1.02609 to 1.00246, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10600s 20s/step - loss: 1.0025
Epoch 14/50
535/536 [============================>.] - ETA: 18s - loss: 0.9837Epoch 00014: loss improved from 1.00246 to 0.98375, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10167s 19s/step - loss: 0.9837
Epoch 15/50
535/536 [============================>.] - ETA: 19s - loss: 0.9699Epoch 00015: loss improved from 0.98375 to 0.97007, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10219s 19s/step - loss: 0.9701
Epoch 16/50
535/536 [============================>.] - ETA: 19s - loss: 0.9485Epoch 00016: loss improved from 0.97007 to 0.94880, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10260s 19s/step - loss: 0.9488
Epoch 17/50
535/536 [============================>.] - ETA: 19s - loss: 0.9345Epoch 00017: loss improved from 0.94880 to 0.93443, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10259s 19s/step - loss: 0.9344
Epoch 18/50
535/536 [============================>.] - ETA: 19s - loss: 0.9226Epoch 00018: loss improved from 0.93443 to 0.92268, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10229s 19s/step - loss: 0.9227
Epoch 19/50
535/536 [============================>.] - ETA: 19s - loss: 0.9147Epoch 00019: loss improved from 0.92268 to 0.91463, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10367s 19s/step - loss: 0.9146
Epoch 20/50
535/536 [============================>.] - ETA: 18s - loss: 0.9043Epoch 00020: loss improved from 0.91463 to 0.90443, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10166s 19s/step - loss: 0.9044
Epoch 21/50
535/536 [============================>.] - ETA: 18s - loss: 0.8929Epoch 00021: loss improved from 0.90443 to 0.89287, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10132s 19s/step - loss: 0.8929
Epoch 22/50
535/536 [============================>.] - ETA: 20s - loss: 0.8905Epoch 00022: loss improved from 0.89287 to 0.89053, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 11085s 21s/step - loss: 0.8905
Epoch 23/50
535/536 [============================>.] - ETA: 18s - loss: 0.8810Epoch 00023: loss improved from 0.89053 to 0.88130, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10108s 19s/step - loss: 0.8813
Epoch 24/50
535/536 [============================>.] - ETA: 18s - loss: 0.8735Epoch 00024: loss improved from 0.88130 to 0.87398, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10076s 19s/step - loss: 0.8740
Epoch 25/50
535/536 [============================>.] - ETA: 18s - loss: 0.8667Epoch 00025: loss improved from 0.87398 to 0.86716, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10111s 19s/step - loss: 0.8672
Epoch 26/50
535/536 [============================>.] - ETA: 18s - loss: 0.8581Epoch 00026: loss improved from 0.86716 to 0.85846, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10102s 19s/step - loss: 0.8585
Epoch 27/50
535/536 [============================>.] - ETA: 21s - loss: 0.8519Epoch 00027: loss improved from 0.85846 to 0.85145, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 11597s 22s/step - loss: 0.8515
Epoch 28/50
 70/536 [==>...........................] - ETA: 2:45:17 - loss: 0.8663

FairyOnIce/ObjectDetectionYolo contains this ipython notebook and all the functions that I defined in this notebook.

By accident, I stopped a notebook. Here, let's resume the training..

In [ ]:
model.load_weights('weights_yolo_on_voc2012.h5')
model.fit_generator(generator        = train_batch_generator, 
                    steps_per_epoch  = len(train_batch_generator), 
                    epochs           = 50, 
                    verbose          = 1,
                    #validation_data  = valid_batch,
                    #validation_steps = len(valid_batch),
                    callbacks        = [early_stop, checkpoint], 
                    max_queue_size   = 3)
Epoch 1/50
535/536 [============================>.] - ETA: 18s - loss: 0.8487Epoch 00001: loss improved from inf to 0.84864, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10093s 19s/step - loss: 0.8486
Epoch 2/50
535/536 [============================>.] - ETA: 18s - loss: 0.8407Epoch 00002: loss improved from 0.84864 to 0.84071, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 9974s 19s/step - loss: 0.8407
Epoch 3/50
535/536 [============================>.] - ETA: 19s - loss: 0.8348Epoch 00003: loss improved from 0.84071 to 0.83478, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10325s 19s/step - loss: 0.8348
Epoch 4/50
535/536 [============================>.] - ETA: 19s - loss: 0.8326Epoch 00004: loss improved from 0.83478 to 0.83307, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10211s 19s/step - loss: 0.8331
Epoch 5/50
535/536 [============================>.] - ETA: 19s - loss: 0.8289Epoch 00005: loss improved from 0.83307 to 0.82875, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10407s 19s/step - loss: 0.8287
Epoch 6/50
535/536 [============================>.] - ETA: 18s - loss: 0.8233Epoch 00006: loss improved from 0.82875 to 0.82336, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10118s 19s/step - loss: 0.8234
Epoch 7/50
535/536 [============================>.] - ETA: 18s - loss: 0.8226Epoch 00007: loss improved from 0.82336 to 0.82245, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10116s 19s/step - loss: 0.8225
Epoch 8/50
535/536 [============================>.] - ETA: 18s - loss: 0.8165Epoch 00008: loss improved from 0.82245 to 0.81658, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10114s 19s/step - loss: 0.8166
Epoch 9/50
535/536 [============================>.] - ETA: 19s - loss: 0.8120Epoch 00009: loss improved from 0.81658 to 0.81197, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10435s 19s/step - loss: 0.8120
Epoch 10/50
535/536 [============================>.] - ETA: 18s - loss: 0.8085Epoch 00010: loss improved from 0.81197 to 0.80853, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10108s 19s/step - loss: 0.8085
Epoch 11/50
535/536 [============================>.] - ETA: 29s - loss: 0.8038 Epoch 00011: loss improved from 0.80853 to 0.80450, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 16065s 30s/step - loss: 0.8045
Epoch 12/50
535/536 [============================>.] - ETA: 19s - loss: 0.8010Epoch 00012: loss improved from 0.80450 to 0.80065, saving model to weights_yolo_on_voc2012.h5
536/536 [==============================] - 10262s 19s/step - loss: 0.8006
Epoch 13/50
106/536 [====>.........................] - ETA: 2:27:29 - loss: 0.7866

Comments