What is the reason of the warning? How should the code be changed to
avoid such warnings?
This warning is applicable only for pre-Tensorflow 2.0. The warning is there because starting from Tensorflow 2.0, dtype
argument should be passed when calling the initializer instance and not to the constructor.
Code snippet to reproduce the warning in pre-tensorflow2.0:
from tensorflow.keras.layers import Dense
dense = Dense(64, activation='relu')
Output:
calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
It is not immediately apparent why the code snippet would cause this warning because no initializer is created. What happens is that internally Tensorflow creates the initializer when a Dense
layer is initiated, since the default kernel initializer is glorot_uniform
. Something like this:
from tensorflow.keras import initializers
initializer = initializers.get('glorot_uniform')
https://github.com/tensorflow/tensorflow/blob/024675edc62dddab17bc439b69eb9bd71f1a1a9a/tensorflow/python/keras/layers/core.py#L997
https://github.com/tensorflow/tensorflow/blob/024675edc62dddab17bc439b69eb9bd71f1a1a9a/tensorflow/python/keras/layers/core.py#L1014