Hot questions for Using Neural networks in tf.keras

Question:

I am Using Keras Library For my Neural Network error. While using Dropout I got the 3 following warning

WARNING:tensorflow: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer.

WARNING:tensorflow: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`. 

WARNING:tensorflow: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.

This How i use the dropout in the model

model.add(Dropout(rate=0.2))

Although it is a warning, I am worried about it. Previously, I got another warning when I use dropout like the following

model.add(Dropout(0.2))

What should I do to get rid of these warnings? can anyone help me


Answer:

You cannot really get rid of these warnings, they are not generated from your code, but from internal keras code that calls tf.nn.dropout. These warnings are not meant for you but to the keras team, they have to update the tensorflow backend to remove the warnings.

The only way to get rid of the warnings is to edit keras' source code.

Question:

I was using TensorFlow 1.13 and Keras for my research projects. Nowadays, due to some future warnings, I installed TensorFlow 2.0 and tried to use it.

Instead of using Keras as I did before, I used tf.keras and built the same RNN model. i.e.

from keras.layers import Dense (I used before)

v.s.

from tf.keras.layers import Dense (I tried now)

All other codes are the same. However, I get some worse results for using import from tf.keras.layers one. And I am pretty sure it's not a coincidence, I tried cross-validation and run the models many times.

Does anyone have some ideas about why it happens? Are there any differences from the tf.keras.layers and keras.layers? If so, how can we be careful in case we got some "wrose" results?


Answer:

tf.keras is tensorflow's implementation of the keras api. Ideally, using tf.keras should not provide you worse results. However, there might be a mismatch in the versions of both the keras which may/may not give you different results. You can check the version using tf.keras.version function and see if that is the same version of keras that you had used before. For more details refer: https://www.tensorflow.org/guide/keras/overview