Answers.Body: <p>VGG16 is not trained to be used as an encoder for image reconstruction, it is trained to extract features from an image using which we can do classification task on the image.<br />
  This is why, you cannot use VGG16 as the encoder part of your denoise autoencoder.<br />
  However, if you want, you can use that architecture of VGG16 as the encoder part of your autoencoder, by just retraining those layers of VGG16,</p>
  <pre><code>vggmodel = keras.applications.vgg16.VGG16()
  model_encoder = Sequential() 
  num = 0
  for i, layer in enumerate(vggmodel.layers):
      if i&lt;19:
        model_encoder.add(layer)
  
  model_encoder.summary()
  for layer in model_encoder.layers:
    layer.trainable=True # Set encoder to trainable, and your autoencoder should work.
  </code></pre>
  <p>Again, there is a problem with your current architecture of autoencoder -it downsamples too much, leading to a significant loss of data. A smaller architecture would work better. For example:</p>
  <pre><code>model = Sequential()
  model.add(Input(shape=(224,224,3)))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(MaxPool2D((2,2)))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(MaxPool2D((2,2)))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(UpSampling2D((2,2)))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(UpSampling2D((2,2)))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(3, (3,3), activation='relu', padding='same'))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-28T11:45:21.313Z
Answers.Text: thank you so much for your comment! Just a quick question, if now i go on train my network using vgg16 by obviously training it again would it be a good choice for something to modify/increase performance in denoise autoencoders?? Because my main aim was to increase the accuracy and denoise autoencoders performance. Or there could be any different approach that is thereb which i can follow.
Answers.UserDisplayName: arizona_3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-28T11:52:58.880Z
Answers.Text: I will build a denoise autoencoder by today, and will share a link to the code.
Answers.UserDisplayName: MD Mushfirat Mohaimin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-28T11:57:19.557Z
Answers.Text: thank you! please do let me know...although i have tried making a basic denoise autoencoder the results were good but i'm expecting a better result because of which i jumped to transfer learning using vgg16
Answers.UserDisplayName: arizona_3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-29T12:23:18.223Z
Answers.Text: @arizona_3 I've made a notebook on this, here is the link: https://www.kaggle.com/code/mushfirat/denoise-images-with-convolutional-autoencoders/
  The explanations may not be so good, so I'll update it if you face any problem understanding it.
Answers.UserDisplayName: MD Mushfirat Mohaimin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-29T19:53:35.747Z
Answers.Text: thanks a ton!! Really appreciate  this_/ \_
Answers.UserDisplayName: arizona_3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-29T20:04:00.470Z
Answers.Text: just a doubt would mean_squared_error be a good choice above binary cross entropy??
Answers.UserDisplayName: arizona_3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-29T21:45:02.760Z
Answers.Text: @arizona_3 yes, MSE can be used, but binary crossentropy is like the standard loss function for calculating loss between images. 
  And It would be better if you could ask your doubts at kaggle, not here.
Answers.UserDisplayName: MD Mushfirat Mohaimin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-30T08:05:40.277Z
Answers.Text: Alright!! sure will clear doubts there. Thanks again.
Answers.UserDisplayName: arizona_3
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-28T10:02:30.377Z
Answers.LastActivityDate: 2022-04-28T10:02:30.377Z
Answers.UserDisplayName: MD Mushfirat Mohaimin
Body: <p>I'm trying to make a denoise autoencoder wherein the <strong>encoder part is vgg16</strong> and decoder is opposite of vgg16(encoder) network. My dataset consists of 5K images in grayscale.</p>
  <p>Now while training, the loss and accuracy doesn't changes. I can think of reducing filters in the initial decoder layers but i fear that's going to affect the autoencoder. Here, i'm really clueless about what approach to follow.</p>
  
Tags: <convolutional-neural-networks><keras><autoencoders><vgg><denoising-autoencoder>
Title: Denoise autoencoder not training properly
UserDisplayName: arizona_3
ThreadText: # Denoise autoencoder not training properly
  
  (Asked by: username_0 on 2022-04-27)
  
  I'm trying to make a denoise autoencoder wherein the **encoder part is vgg16** and decoder is opposite of vgg16(encoder) network. My dataset consists of 5K images in grayscale.
  
  Now while training, the loss and accuracy doesn't changes. I can think of reducing filters in the initial decoder layers but i fear that's going to affect the autoencoder. Here, i'm really clueless about what approach to follow.
  
  **Tags:** convolutional-neural-networks, keras, autoencoders, vgg, denoising-autoencoder
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-28. Score: 1
  
  VGG16 is not trained to be used as an encoder for image reconstruction, it is trained to extract features from an image using which we can do classification task on the image.
  This is why, you cannot use VGG16 as the encoder part of your denoise autoencoder.
  However, if you want, you can use that architecture of VGG16 as the encoder part of your autoencoder, by just retraining those layers of VGG16,
  vggmodel = keras.applications.vgg16.VGG16()
  model_encoder = Sequential() 
  num = 0
  for i, layer in enumerate(vggmodel.layers):
      if i<19:
        model_encoder.add(layer)
  
  model_encoder.summary()
  for layer in model_encoder.layers:
    layer.trainable=True # Set encoder to trainable, and your autoencoder should work.
  
  Again, there is a problem with your current architecture of autoencoder -it downsamples too much, leading to a significant loss of data. A smaller architecture would work better. For example:
  model = Sequential()
  model.add(Input(shape=(224,224,3)))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(MaxPool2D((2,2)))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(MaxPool2D((2,2)))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(256, (3,3), activation='relu', padding='same'))
  model.add(UpSampling2D((2,2)))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(128, (3,3), activation='relu', padding='same'))
  model.add(UpSampling2D((2,2)))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(64, (3,3), activation='relu', padding='same'))
  model.add(Conv2D(3, (3,3), activation='relu', padding='same'))
  
  > **Comments:**
  > **username_0**: thank you so much for your comment! Just a quick question, if now i go on train my network using vgg16 by obviously training it again would it be a good choice for something to modify/increase performance in denoise autoencoders?? Because my main aim was to increase the accuracy and denoise autoencoders performance. Or there could be any different approach that is thereb which i can follow.  
  > **username_1**: I will build a denoise autoencoder by today, and will share a link to the code.  
  > **username_0**: thank you! please do let me know...although i have tried making a basic denoise autoencoder the results were good but i'm expecting a better result because of which i jumped to transfer learning using vgg16  
  > **username_1**: @arizona_3 I've made a notebook on this, here is the link: https://www.kaggle.com/code/mushfirat/denoise-images-with-convolutional-autoencoders/ The explanations may not be so good, so I'll update it if you face any problem understanding it.  
  > **username_0**: thanks a ton!! Really appreciate  this_/ \_  
  > **username_0**: just a doubt would mean_squared_error be a good choice above binary cross entropy??  
  > **username_1**: @arizona_3 yes, MSE can be used, but binary crossentropy is like the standard loss function for calculating loss between images.  And It would be better if you could ask your doubts at kaggle, not here.  
  > **username_0**: Alright!! sure will clear doubts there. Thanks again.  
  
  ---
  
  