0
$\begingroup$

I am trying to duplicate and learn from example given on this website . With my little modification, I am trying to simple exchange color for example like red to orange in an image. The original code does not work. I have 1500 sample of different simple images. So far I have accuracy stuck or converging to at 50%. So far the learning rate is 0.008 for optimizer adam. I noticed that if I increase the steps per epoch say 400, the accuracy and loss goes to close of 100%. If I go for steps of 30 per epoch, the loss goes down accordingly but accuracy converges to 50%. Below is my python set up code.

X_,y_ = ExtractInput(ImagePath)
K.clear_session()
def InstantiateModel(in_):
model_ = Conv2D(16,(3,3),padding='same',strides=1)(in_)
model_ = LeakyReLU()(model_)
#model_ = Conv2D(64,(3,3), activation='relu',strides=1)(model_)
model_ = Conv2D(32,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)
model_ = MaxPooling2D(pool_size=(2,2),padding='same')(model_)

model_ = Conv2D(64,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)
model_ = MaxPooling2D(pool_size=(2,2),padding='same')(model_)

model_ = Conv2D(128,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)

model_ = Conv2D(256,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)

model_ = UpSampling2D((2, 2))(model_)
model_ = Conv2D(128,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)

model_ = UpSampling2D((2, 2))(model_)
model_ = Conv2D(64,(3,3), padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_) # it was commented

concat_ = concatenate([model_, in_]) 

model_ = Conv2D(64,(3,3), padding='same',strides=1)(concat_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_)

model_ = Conv2D(32,(3,3),padding='same',strides=1)(model_)
model_ = LeakyReLU()(model_)
model_ = BatchNormalization()(model_) # it was commented

model_ = Conv2D(2,(3,3), activation='tanh',padding='same',strides=1)(model_)

return model_
Input_Sample = Input(shape=(HEIGHT, WIDTH,1))
Output_ = InstantiateModel(Input_Sample)
Model_Colourization = Model(inputs=Input_Sample, outputs=Output_)

LEARNING_RATE = 0.008
Model_Colourization.compile(optimizer=Adam(lr=LEARNING_RATE),loss='mean_squared_error',metrics=  ['accuracy'])
Model_Colourization.summary()
def GenerateInputs(X_,y_):
for i in range(len(X_)):
    X_input = X_[i].reshape(1,224,224,1)
    y_input = y_[i].reshape(1,224,224,2)
    yield (X_input,y_input)
    
history = Model_Colourization.fit_generator(GenerateInputs(X_,y_),epochs=10,verbose=1,
                                        steps_per_epoch=24,shuffle=True)

And the output is

 Layer (type)                    Output Shape         Param #     Connected to                     
 =========================================================================================
 input_1 (InputLayer)            (None, 224, 224, 1)  0                                            
 __________________________________________________________________________________________
 conv2d_1 (Conv2D)               (None, 224, 224, 16) 160         input_1[0][0]                    
 ____________________________________________________________________________________________
 leaky_re_lu_1 (LeakyReLU)       (None, 224, 224, 16) 0           conv2d_1[0][0]                   
 _____________________________________________________________________________________________
 conv2d_2 (Conv2D)               (None, 224, 224, 32) 4640        leaky_re_lu_1[0][0]              
 _____________________________________________________________________________________________
 leaky_re_lu_2 (LeakyReLU)       (None, 224, 224, 32) 0           conv2d_2[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_1 (BatchNor (None, 224, 224, 32) 128         leaky_re_lu_2[0][0]              
 _____________________________________________________________________________________________
 max_pooling2d_1 (MaxPooling2D)  (None, 112, 112, 32) 0           batch_normalization_1[0][0]      
 ______________________________________________________________________________________________
 conv2d_3 (Conv2D)               (None, 112, 112, 64) 18496       max_pooling2d_1[0][0]            
 _____________________________________________________________________________________________
 leaky_re_lu_3 (LeakyReLU)       (None, 112, 112, 64) 0           conv2d_3[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_2 (BatchNor (None, 112, 112, 64) 256         leaky_re_lu_3[0][0]              
 _____________________________________________________________________________________________
 max_pooling2d_2 (MaxPooling2D)  (None, 56, 56, 64)   0           batch_normalization_2[0][0]      
 _____________________________________________________________________________________________
 conv2d_4 (Conv2D)               (None, 56, 56, 128)  73856       max_pooling2d_2[0][0]            
 _____________________________________________________________________________________________
 leaky_re_lu_4 (LeakyReLU)       (None, 56, 56, 128)  0           conv2d_4[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_3 (BatchNor (None, 56, 56, 128)  512         leaky_re_lu_4[0][0]              
 _____________________________________________________________________________________________
 conv2d_5 (Conv2D)               (None, 56, 56, 256)  295168      batch_normalization_3[0][0]      
 _____________________________________________________________________________________________
 leaky_re_lu_5 (LeakyReLU)       (None, 56, 56, 256)  0           conv2d_5[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_4 (BatchNor (None, 56, 56, 256)  1024        leaky_re_lu_5[0][0]              
 _____________________________________________________________________________________________
 up_sampling2d_1 (UpSampling2D)  (None, 112, 112, 256 0           batch_normalization_4[0][0]      
 _____________________________________________________________________________________________
 conv2d_6 (Conv2D)               (None, 112, 112, 128 295040      up_sampling2d_1[0][0]            
 _____________________________________________________________________________________________
 leaky_re_lu_6 (LeakyReLU)       (None, 112, 112, 128 0           conv2d_6[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_5 (BatchNor (None, 112, 112, 128 512         leaky_re_lu_6[0][0]              
 _____________________________________________________________________________________________
 up_sampling2d_2 (UpSampling2D)  (None, 224, 224, 128 0           batch_normalization_5[0][0]      
 _____________________________________________________________________________________________
 conv2d_7 (Conv2D)               (None, 224, 224, 64) 73792       up_sampling2d_2[0][0]            
 _____________________________________________________________________________________________
 leaky_re_lu_7 (LeakyReLU)       (None, 224, 224, 64) 0           conv2d_7[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_6 (BatchNor (None, 224, 224, 64) 256         leaky_re_lu_7[0][0]              
 _____________________________________________________________________________________________
 concatenate_1 (Concatenate)     (None, 224, 224, 65) 0           batch_normalization_6[0][0]      
                                                             input_1[0][0]                    
 _____________________________________________________________________________________________
 conv2d_8 (Conv2D)               (None, 224, 224, 64) 37504       concatenate_1[0][0]              
 _____________________________________________________________________________________________
 leaky_re_lu_8 (LeakyReLU)       (None, 224, 224, 64) 0           conv2d_8[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_7 (BatchNor (None, 224, 224, 64) 256         leaky_re_lu_8[0][0]              
 _____________________________________________________________________________________________
 conv2d_9 (Conv2D)               (None, 224, 224, 32) 18464       batch_normalization_7[0][0]      
 _____________________________________________________________________________________________
 leaky_re_lu_9 (LeakyReLU)       (None, 224, 224, 32) 0           conv2d_9[0][0]                   
 _____________________________________________________________________________________________
 batch_normalization_8 (BatchNor (None, 224, 224, 32) 128         leaky_re_lu_9[0][0]              
 _____________________________________________________________________________________________
 conv2d_10 (Conv2D)              (None, 224, 224, 2)  578         batch_normalization_8[0][0]      
 =============================================================================================
 Total params: 820,770
 Trainable params: 819,234
 Non-trainable params: 1,536

  Epoch 1/10
  24/24 [==============================] - 520s 22s/step - loss: 0.1813 - acc: 0.5552
  Epoch 2/10
  24/24 [==============================] - 513s 21s/step - loss: 0.0125 - acc: 0.5076
  Epoch 3/10
  24/24 [==============================] - 517s 22s/step - loss: 0.0020 - acc: 0.5050
  Epoch 4/10
  24/24 [==============================] - 517s 22s/step - loss: 0.0016 - acc: 0.4796
  Epoch 5/10

During the experimenting with the code I did something that I cannot replicate it. I started with learning rate of 0.004, after two epochs, I interrupted kernel and started with 0.008. And I noticed that after two epoch, the acc was increasing. However, when I restarted the entire program at learning rate of 0.008, the accuracy is decreasing. Obviously it has something to do with the right amount of learning rate and steps per epochs. Any suggestions on improving the accuracy?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.