Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DEPRECATION WARNING: How to remove tf.keras warning "calling VarianceScaling.__init__ with dtype is deprecated..."

The following code generates the warning in tensorflow r1.12 python API:

#!/usr/bin/python3
import tensorflow as tf

M = tf.keras.models.Sequential();
M.add(tf.keras.layers.Dense(2)); 

The complete warning text is this:

WARNING: Logging before flag parsing goes to stderr.
W0213 15:50:07.239809 140701996246848 deprecation.py:506] From /home/matias/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/init_ops.py:1253: 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

I have tried different approaches like initializing and calling a kernel initializer before adding Dense layer and passing it to Dense constructor, but it seems to not change anything. Is this warning inevitable? A 'yes' as an answer would be enough for me.

like image 725
Matias Haeussler Avatar asked Feb 13 '19 19:02

Matias Haeussler


2 Answers

The warning may be caused upstream by abseil-py, a dependency of tensorflow. See the details here. An easy fix may be to update abseil-py by running:

pip install --upgrade absl-py

(In my case, the conflicting version was 0.7.1 and the problem was fixed in the updated version, 0.8.1)

like image 81
dopexxx Avatar answered Sep 19 '22 18:09

dopexxx


You are running tensor flow 2.0 and it looks like VarianceScaling.init is deprecated. It might mean that Sequential will need to be more explicitly initialized in the future. for example:

model = tf.keras.Sequential([
# Adds a densely-connected layer with 64 units to the model:
layers.Dense(64, activation='relu', input_shape=(32,)),
# Add another:
layers.Dense(64, activation='relu'),
# Add a softmax layer with 10 output units:
layers.Dense(10, activation='softmax')])
like image 38
rigo Avatar answered Sep 17 '22 18:09

rigo