BenedictGrain
BenedictGrain

Reputation: 111

conv-autoencoder that val_loss doesn't decrease

I build a anomaly detection model using conv-autoencoder on UCSD_ped2 dataset. What puzzles me is that after very few epochs ,the val_loss don't decrease. It seem that the model couldn't learn any longer. I have done some research to improve my model,but it doesn't getting better. what should i do to fix it?

Here's my model's struct:

x=144;y=224
input_img = Input(shape = (x, y, inChannel))

bn1= BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(input_img)
conv1 = Conv2D(256, (11, 11), strides=(4,4),activation='relu',
               kernel_regularizer=regularizers.l2(0.0005),
               kernel_initializer=initializers.glorot_normal(seed=None),
               padding='same')(bn1)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

bn2= BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(pool1)
conv2 = Conv2D(128, (5, 5),activation='relu',
               kernel_regularizer=regularizers.l2(0.0005),
               kernel_initializer=initializers.glorot_normal(seed=None),
               padding='same')(bn2)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

bn3= BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(pool2)
conv3 = Conv2D(64, (3, 3), activation='relu',
               kernel_regularizer=regularizers.l2(0.0005),
               kernel_initializer=initializers.glorot_normal(seed=None),
               padding='same')(bn3)


ubn3=BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(conv3)
uconv3=Conv2DTranspose(128, (3,3),activation='relu',
                      kernel_regularizer=regularizers.l2(0.0005),
                      kernel_initializer=initializers.glorot_normal(seed=None),
                      padding='same')(ubn3)
upool3=UpSampling2D(size=(2, 2))(uconv3)


ubn2=BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(upool3)
uconv2=Conv2DTranspose(256, (3, 3),activation='relu',
                       kernel_regularizer=regularizers.l2(0.0005),
                       kernel_initializer=initializers.glorot_normal(seed=None),
                       padding='same')(ubn2)
upool2=UpSampling2D(size=(2, 2))(uconv2)

ubn1=BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001)(upool2)
decoded = Conv2DTranspose(1, (11, 11), strides=(4, 4),
                          kernel_regularizer=regularizers.l2(0.0005),
                          kernel_initializer=initializers.glorot_normal(seed=None),
                          activation='sigmoid', padding='same')(ubn1)

autoencoder = Model(input_img, decoded)
autoencoder.compile(loss = 'mean_squared_error', optimizer ='Adadelta',metrics=['accuracy'])
history=autoencoder.fit(X_train, Y_train,validation_split=0.3,
                batch_size = batch_size, epochs = epochs, verbose = 0,
                shuffle=True,
                callbacks=[earlystopping,checkpointer,reduce_lr])
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 144, 224, 1)       0         
_________________________________________________________________
batch_normalization_1 (Batch (None, 144, 224, 1)       4         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 36, 56, 256)       31232     
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 18, 28, 256)       0         
_________________________________________________________________
batch_normalization_2 (Batch (None, 18, 28, 256)       1024      
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 18, 28, 128)       819328    
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 9, 14, 128)        0         
_________________________________________________________________
batch_normalization_3 (Batch (None, 9, 14, 128)        512       
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 9, 14, 64)         73792     
_________________________________________________________________
batch_normalization_4 (Batch (None, 9, 14, 64)         256       
_________________________________________________________________
conv2d_transpose_1 (Conv2DTr (None, 9, 14, 128)        73856     
_________________________________________________________________
up_sampling2d_1 (UpSampling2 (None, 18, 28, 128)       0         
_________________________________________________________________
batch_normalization_5 (Batch (None, 18, 28, 128)       512       
_________________________________________________________________
conv2d_transpose_2 (Conv2DTr (None, 18, 28, 256)       295168    
_________________________________________________________________
up_sampling2d_2 (UpSampling2 (None, 36, 56, 256)       0         
_________________________________________________________________
batch_normalization_6 (Batch (None, 36, 56, 256)       1024      
_________________________________________________________________
conv2d_transpose_3 (Conv2DTr (None, 144, 224, 1)       30977     
=================================================================
Total params: 1,327,685
Trainable params: 1,326,019
Non-trainable params: 1,666

the batch size=30;epoch=100 training data has 1785 pic; validation data has 765 pic. I have tried :

  1. delete kernel_regularizer;
  2. adding ReduceLROnPlateau.

,but it only get a little improve.

Epoch 00043: ReduceLROnPlateau reducing learning rate to 9.99999874573554e-12.

Epoch 00044: val_loss did not improve from 0.00240

Epoch 00045: val_loss did not improve from 0.00240

As the val_loss get 0.00240, it didn't decrease...

The following figure was loss with epoch.

reconstruction result The following figure show model's reconstruction result which are truly poor.How can I making my model more workful?

Upvotes: 1

Views: 121

Answers (1)

TF_Support
TF_Support

Reputation: 1836

Based on your screenshot, It seems that it is not an issue of overfitting or underfitting.

On my understanding:

Underfitting – Validation and training error high

Overfitting – Validation error is high, training error low

Good fit – Validation error low, slightly higher than the training error

Generally speaking, the dataset should be split properly for training and validation. Typically the training set should be 4 times (80/20) the number of your validation set. My suggestion is that you can try to increase the number of your datasets by doing data augmentation and continue the training.

Kindly refer to the documentation for data augmentation.

Upvotes: 0

Related Questions