1
$\begingroup$

I've tried to make transfer learning via keras.applications like here (https://keras.io/applications/) for binary classification of images (crocodiles and clocks).

load model without top layers

1: upload model

add my dense layer at the top of resnet50

enter image description here

prepare data (resize (32,32,3) -> (224, 224,3)) and split into train & test

enter image description here

TRAIN

enter image description here

EVALUATE ON TRAIN

Descpite loss' decrease and accuracy' increase during fit() method, the model always predicted the one class for every instance. There was class balance 50\50 (in test and train) hence on train\test accuracy was 0.5

enter image description here

EVALUATE ON TEST

There was the same result.

enter image description here

I've tried a lot of different things:

  • Change learning_rate
  • Change optimizer (RMSProp\SGD)
  • Use fit_generator() inster fit()
  • Use another losses such as 'categorical_crossentropy' with one-hotted target
  • Use another activation: 'softmax'.

Eventually i've decided to use tensorflow and write CNN from scratch using Keras layers:

enter image description here

I've found out that if i use K.learning_phase() = 1 (train phase):

i'll recieve expected result:

accuracy on train ~ 0.99 accuracy on test ~ 0.82

If K.learning_phase() = 0 (test phase):

It's still something strange:

accuracy on train ~ 0.5 accuracy on test ~ 0.5

I have no idea why it happens and how to manage it. I hope somebody would help me. Thanks in advance.

$\endgroup$

closed as off-topic by Michael Chernick, kjetil b halvorsen, Peter Flom May 5 '18 at 11:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, kjetil b halvorsen, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ not sure if this is the only issue but batch norm and dropout don't play well together $\endgroup$ – shimao May 4 '18 at 20:30
  • $\begingroup$ i am keen to help, please message me your email (mine is htmldeveloper@gmail.com) $\endgroup$ – Peter Teoh May 5 '18 at 13:12