Answers.Body: <p>It's difficult to say without knowing what your data looks like but from the numbers it seems too less and the images might be too similar to one another or very different. In any case, I'd have checked using other networks like Inception and decreasing learning rate even further (say 0.0001) to not mess with the Imagenet weights if your data is not very different from Imagenet classes.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-28T10:48:46.000Z
Answers.Text: many thanks, my images are similar to one another, just like these [signal images](https://stackoverflow.com/questions/59476427/removing-background-noise-from-signal-images-rgb). Can you give any more updates?
Answers.UserDisplayName: bit_scientist
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-30T11:53:19.650Z
Answers.Text: In this case the number of images is highly inadequate imo. I'd try to make a custom network first with very few layers and see if there's any improvement. Huge architectures like Resnet, etc. don't generally work with small data.
Answers.UserDisplayName: deadcode
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-26T11:28:05.383Z
Answers.Text: how would you deal with weight initialization in case there is high similarity between the 2 classes and the number of images are around 1k for per class?
Answers.UserDisplayName: bit_scientist
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-28T10:45:27.327Z
Answers.LastActivityDate: 2019-12-28T10:45:27.327Z
Answers.UserDisplayName: deadcode
Body: <p>I am practicing with Resnet50 fine-tuning for a binary classification task. Here is my code snippet.</p>
  <pre><code>base_model = ResNet50(weights='imagenet', include_top=False)
  x = base_model.output
  x = keras.layers.GlobalAveragePooling2D(name='avg_pool')(x)
  x = Dropout(0.8)(x)
  model_prediction = keras.layers.Dense(1, activation='sigmoid', name='predictions')(x)
  model = keras.models.Model(inputs=base_model.input, outputs=model_prediction)
  opt = SGD(lr = 0.01, momentum = 0.9, nesterov = False)
   
  model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])  #
     
  train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=False)
    
  test_datagen = ImageDataGenerator(rescale=1./255)
  train_generator = train_datagen.flow_from_directory(
          './project_01/train',
          target_size=(input_size, input_size),  
          batch_size=batch_size,
          class_mode='binary')    
  
  validation_generator = test_datagen.flow_from_directory(
          './project_01/val',
          target_size=(input_size, input_size),
          batch_size=batch_size,
          class_mode='binary')
  
  hist = model.fit_generator(
          train_generator,
          steps_per_epoch= 1523 // batch_size, # 759 + 764 NON = 1523
          epochs=epochs,
          validation_data=validation_generator,
          validation_steps= 269 // batch_size)  # 134 + 135NON = 269
  </code></pre>
  <p>I plotted a figure of the model after training for 50 epochs:</p>
  <p><a href="https://i.sstatic.net/Jp2XH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jp2XH.png" alt="" /></a></p>
  <p>You may have noticed that <code>train_acc</code> and <code>val_acc</code> have highly fluctuated, and <code>train_acc</code> merely reaches 52%, which means that network isn't learning, let alone over-fitting the data.</p>
  <p>As for the losses, I haven't got any insights.</p>
  <p>Before training starts, network outputs:</p>
  <pre><code>Found 1523 images belonging to 2 classes.
  Found 269 images belonging to 2 classes.
  </code></pre>
  <p>Is my fine-tuned model learning anything at all?</p>
  <p>I'd appreciate if someone can guide me to solve this issue.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-29T10:06:26.907Z
Comments.Text: Are you basing this code on some existing script? How did you decide to use a dropout rate of `0.8`, and a learning rate of `0.01`? (Dropout rate is very high, learning rate probably too high). What is your batch size?
Comments.UserDisplayName: Mathias Müller
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-26T11:28:52.583Z
Comments.Text: @MathiasMüller those are from other model tests that I've been training. Actually I tried several hyper-parameters. For now, VGG16 model is performing quite well.
Comments.UserDisplayName: bit_scientist
Tags: <convolutional-neural-networks><training><keras><transfer-learning><fine-tuning>
Title: Is my fine-tuned model learning anything at all?
UserDisplayName: bit_scientist
ThreadText: # Is my fine-tuned model learning anything at all?
  
  (Asked by: username_0 on 2019-12-28)
  
  I am practicing with Resnet50 fine-tuning for a binary classification task. Here is my code snippet.
  base_model = ResNet50(weights='imagenet', include_top=False)
  x = base_model.output
  x = keras.layers.GlobalAveragePooling2D(name='avg_pool')(x)
  x = Dropout(0.8)(x)
  model_prediction = keras.layers.Dense(1, activation='sigmoid', name='predictions')(x)
  model = keras.models.Model(inputs=base_model.input, outputs=model_prediction)
  opt = SGD(lr = 0.01, momentum = 0.9, nesterov = False)
   
  model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])  #
     
  train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=False)
    
  test_datagen = ImageDataGenerator(rescale=1./255)
  train_generator = train_datagen.flow_from_directory(
          './project_01/train',
          target_size=(input_size, input_size),  
          batch_size=batch_size,
          class_mode='binary')    
  
  validation_generator = test_datagen.flow_from_directory(
          './project_01/val',
          target_size=(input_size, input_size),
          batch_size=batch_size,
          class_mode='binary')
  
  hist = model.fit_generator(
          train_generator,
          steps_per_epoch= 1523 // batch_size, # 759 + 764 NON = 1523
          epochs=epochs,
          validation_data=validation_generator,
          validation_steps= 269 // batch_size)  # 134 + 135NON = 269
  
  I plotted a figure of the model after training for 50 epochs:
  
  You may have noticed that train_acc and val_acc have highly fluctuated, and train_acc merely reaches 52%, which means that network isn't learning, let alone over-fitting the data.
  As for the losses, I haven't got any insights.
  Before training starts, network outputs:
  Found 1523 images belonging to 2 classes.
  Found 269 images belonging to 2 classes.
  
  Is my fine-tuned model learning anything at all?
  I'd appreciate if someone can guide me to solve this issue.
  
  **Tags:** convolutional-neural-networks, training, keras, transfer-learning, fine-tuning
  > **Comments:**
  > **username_1**: Are you basing this code on some existing script? How did you decide to use a dropout rate of `0.8`, and a learning rate of `0.01`? (Dropout rate is very high, learning rate probably too high). What is your batch size?  
  > **username_0**: @MathiasMüller those are from other model tests that I've been training. Actually I tried several hyper-parameters. For now, VGG16 model is performing quite well.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-12-28. Score: 0
  
  It's difficult to say without knowing what your data looks like but from the numbers it seems too less and the images might be too similar to one another or very different. In any case, I'd have checked using other networks like Inception and decreasing learning rate even further (say 0.0001) to not mess with the Imagenet weights if your data is not very different from Imagenet classes.
  
  > **Comments:**
  > **username_0**: many thanks, my images are similar to one another, just like these [signal images](https://stackoverflow.com/questions/59476427/removing-background-noise-from-signal-images-rgb). Can you give any more updates?  
  > **username_2**: In this case the number of images is highly inadequate imo. I'd try to make a custom network first with very few layers and see if there's any improvement. Huge architectures like Resnet, etc. don't generally work with small data.  
  > **username_0**: how would you deal with weight initialization in case there is high similarity between the 2 classes and the number of images are around 1k for per class?  
  
  ---
  
  