弃用警告:如何删除tf.keras警告“不建议使用dtype调用VarianceScaling .__ init __...”

Mat*_*ler 7 python keras tensorflow

以下代码在tensorflow r1.12 python API中生成警告:

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

M = tf.keras.models.Sequential();
M.add(tf.keras.layers.Dense(2)); 
Run Code Online (Sandbox Code Playgroud)

完整的警告文本是这样的:

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
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法,例如在添加Dense层并将其传递给Dense构造函数之前初始化和调用内核初始化程序,但是它似乎没有任何改变。这是不可避免的警告吗?对我来说,回答“是”就足够了。

rig*_*igo 3

您正在运行张量流 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')])
Run Code Online (Sandbox Code Playgroud)