Variation_scaling_initializer() 得到了一个意外的关键字参数“分布”

Posted

技术标签:

【中文标题】Variation_scaling_initializer() 得到了一个意外的关键字参数“分布”【英文标题】:variance_scaling_initializer() got an unexpected keyword argument 'distribution' 【发布时间】:2019-02-01 14:13:48 【问题描述】:

在这里,我想使用 python 预测随时间变化的相同值(回归神经网络)。在这里,我有两个输出和三个输入。当我运行代码时,它给了我一个错误“variance_scaling_initializer() got an unexpected keyword argument 'distribution'”。你能帮我解决问题吗? 这里我上传我的代码,

n_neurons_1 = 24
n_neurons_2 = 12
n_target = 2
softmax = 2
weight_initializer = tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax)
bias_initializer = tf.zeros_initializer()
w_hidden_1 = tf.Variable(weight_initializer([n_time_dimensions,n_neurons_1]))
bias_hidden_1= tf.Variable(bias_initializer([n_neurons_1]))
w_hidden_2= tf.Variable(weight_initializer([n_neurons_1,n_neurons_2]))
bias_hidden_2 = tf.Variable(bias_initializer([n_neurons_2]))
w_out = tf.Variable(weight_initializer([n_neurons_2,2]))
bias_out = tf.Variable(bias_initializer([2]))

                        
hidden_1 = tf.nn.relu(tf.add(tf.matmul(X, w_hidden_1),bias_hidden_1))
hidden_2 = tf.nn.relu(tf.add(tf.matmul(X, w_hidden_2),bias_hidden_2))

out = tf.transpose(tf.add(tf.matmul(hidden_2, w_out),bias_out))

我的数据集是,

date	       time g	   p	c	apparentg
6/8/2018	0:06:15	141	131	136	141
6/8/2018	0:09:25	95	117	95	95
6/8/2018	0:11:00	149	109	139	149
6/8/2018	0:13:50	120	103	95	120
6/8/2018	0:16:20	135	97	105	135
6/8/2018	0:19:00	63	NaN	97	63
6/8/2018	0:20:00	111	NaN	100	111
6/8/2018	0:22:10	115	NaN	115	115
6/8/2018	0:23:40	287	NaN	NaN	287
错误是,

TypeError                                 Traceback (most recent call last)
<ipython-input-26-9ceeb97429b1> in <module>()
     31 n_target = 2
     32 softmax = 2
---> 33 weight_initializer = tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax)
     34 bias_initializer = tf.zeros_initializer()
     35 w_hidden_1 = tf.Variable(weight_initializer([n_time_dimensions,n_neurons_1]))

TypeError: variance_scaling_initializer() got an unexpected keyword argument 'distribution'

【问题讨论】:

【参考方案1】:

查看文档https://www.tensorflow.org/api_docs/python/tf/contrib/layers/variance_scaling_initializer

tf.contrib.layers.variance_scaling_initializer(
    factor=2.0,
    mode='FAN_IN',
    uniform=False,
    seed=None,
    dtype=tf.float32
)

uniform: Whether to use uniform or normal distributed random initialization.

那就试试吧

uniform = True

而不是

distribution ="uniform"

在你的函数调用中

 tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax)

该函数中似乎也没有scale= 属性。

【讨论】:

以上是关于Variation_scaling_initializer() 得到了一个意外的关键字参数“分布”的主要内容,如果未能解决你的问题,请参考以下文章