2

The example code

model = tf.keras.Sequential()
# Adds a densely-connected layer with 64 units to the model:
model.add(layers.Dense(64, activation='relu'))
# Add another:
model.add(layers.Dense(64, activation='relu'))
# Add a softmax layer with 10 output units:
model.add(layers.Dense(10, activation='softmax'))

in the official Tensorflow website results in a warning in the output as seen in that page itself.

calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.

What is the reason of the warning? How should the code be changed to avoid such warnings?

Valentas
  • 2,014
  • 20
  • 24

2 Answers2

2

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

Manoj Mohan
  • 5,654
  • 1
  • 17
  • 21
1

Welcome to the club :) I mean tensorflow is notorious for not being backward compatible and worse yet there are warnings like this now for a long time.

See here: https://github.com/tensorflow/tensorflow/issues/25996

So your best bet is just ignore those warnings and, if you wish to be proactive, then contribute with a fix. Otherwise, make sure they do not distract you from your main task. Warnings now are normal in tensorflow.

eugen
  • 1,249
  • 9
  • 15