Open caocuong0306 opened 5 years ago
Hi @caocuong0306 !
When do you set the learning phase
? Before or after the model is created? We use tf.keras.backend.set_learning_phase
at the beginning of script in our other project and don't have any problem with it. Also, be aware that set_learning_phase
expect integers as inputs https://www.tensorflow.org/api_docs/python/tf/keras/backend/set_learning_phase. I hope it helps. Let us know if you solved your problem.
Cheers, Martin
Hi @martinkersner ,
Thank you very much for your answer. I've read your reply yesterday, but I've been working on a small example using Colab so I can explain in detail.
I've been using TF so far, and I'm new to Keras. It seems to me that we cannot perform training & validation at the same time (within a session) when using Keras as model definition similar to what we usually do with TF, because we need to set_learning_phase
at the beginning of scripts.
Dear @martinkersner ,
This is a question rather than an issue. I'd be grateful if you could give your thought.
I'm using your code to test a small (but old) project. The project was developed based on Queue-based and feed_dict mechanism of
Session.
That means I can only use your Model (build_mobilenetv3
function) without other Keras-based functions (model.compile
,model.fit
,model.evaluate
, etc.)The problem is that I need to set Keras's
learning_phase
totrue
during training, andfalse
during evaluation or inference. I tried several ways like:tf.keras.backend.set_learning_phase(True)
/tf.keras.backend.set_learning_phase(False)
feed_dict = {tf.keras.backend.learning_phase() : 1}
/feed_dict = {tf.keras.backend.learning_phase() : 0}
And use,
model(input_tensor, training=True
) /model(input_tensor, training=False)
However, none of the aforementioned methods works. The training cost and accuracy look good, but the validation accuracy's never been improved. I guess this is because of BN and dropout layers, but what else should I do beyond the above 3 approaches.
Thank you for your great work. I'm looking forward to discussing with you about the question.
Thanks. Cuong