警告:如何解决tf.keras警告“调用VarianceScaling.__init__时使用dtype已被弃用...”

12

以下代码在tensorflow r1.12的Python API中会产生警告:

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

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

完整的警告文本如下:

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

我尝试过不同的方法,比如在添加密集层前初始化并调用内核初始化程序,然后将其传递给 Dense 构造函数,但似乎没有改变任何东西。 这个警告是不可避免的吗? 如果答案是“是”,那对我来说就足够了。


在tensorflow 1.12上,我没有收到任何错误。此外,您的格式混乱不堪(您在末尾有分号?) - IanQ
这不是一个错误,而是一个警告。是的,在结尾处我使用分号。也许值得一提的是,我是从源代码安装了tensorflow。 - Matias Haeussler
我也从源代码安装了tensorflow 1.12,而且我也没有收到任何这样的警告。 - Manualmsdos
如果您想要禁止警告,请参见https://dev59.com/cqDia4cB1Zd3GeqPJcx2 - Fra
3个回答

4
警告可能是由于 abseil-py 引起的,它是 tensorflow 的一个依赖项。在这里查看详细信息 一个简单的解决方法可能是通过运行以下命令更新abseil-py

pip install --upgrade absl-py

(在我的情况下,版本冲突为0.7.1,问题已在更新的版本0.8.1中得到解决)

3
你正在运行TensorFlow 2.0,看起来是用了VarianceScaling。 init已经被弃用,这可能意味着将来需要更明确地初始化Sequential模型。例如:
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')])

0

这只是基于TensorFlow 2.0更改的警告。

如果你不想看到这些警告,请升级到TensorFlow 2.0。您可以通过pip安装beta版本:

pip install tensorflow==2.0.0-beta1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接