Python 弃用警告:如何删除tf.keras警告“;调用VarianceScaling。不推荐使用带有数据类型的“uuu init”…“;

Python 弃用警告:如何删除tf.keras警告“;调用VarianceScaling。不推荐使用带有数据类型的“uuu init”…“;,python,tensorflow,keras,Python,Tensorflow,Keras,以下代码在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 1407019962

以下代码在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

我尝试过不同的方法,比如在添加稠密层并将其传递给稠密构造函数之前初始化并调用内核初始值设定项,但它似乎并没有改变任何事情。这一警告不可避免吗?回答“是”就足够了。

您运行的是tensor flow 2.0,看起来像是VarianceScaling。init不推荐使用。这可能意味着Sequential将来需要更明确地初始化。 例如:

model=tf.keras.Sequential([
#将具有64个单元的密集连接层添加到模型中:
密集层(64,激活=relu',输入_形状=(32,),
#添加另一个:
层。致密(64,活化='relu'),
#添加具有10个输出单元的softmax层:
层。致密(10,活化='softmax'))

这只是一个基于警告的警告

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

pip install tensorflow==2.0.0-beta1

该警告可能由上游的
abseil py
引起,这是一种
tensorflow
的依赖关系。 请参阅详细信息。 一个简单的修复方法是通过运行以下命令来更新
abseil py

pip安装--升级absl py


(在我的例子中,冲突版本是
0.7.1
,问题在更新版本
0.8.1
中得到解决)

在tensorflow 1.12上,我没有收到此类错误。此外,您的格式设置也很混乱(末尾有分号?),这不是一个错误,而是一个警告。是的,我在结尾使用分号。也许有一点很重要,那就是我从源代码安装了tensorflow。我也从源代码安装了tensorflow 1.12,但我也没有收到这样的警告。请查看是否要抑制该警告