python函数在Tensorflow中不起作用:tf.B.层.应用正则化

2024-05-13 04:11:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的职能是:

def groupl1(x):
    return tf.reduce_sum(tf.sqrt(tf.to_float(x.get_shape()[1])) * tf.sqrt(tf.reduce_sum(x ** 2, axis=1)))

当我把它放进我的代码里:

elif loss == 'rmse,gl':
weightss=tf.trainable_variables()
reg=tf.contrib.layers.apply_regularization(groupl1,weightss)
loss =  tf.sqrt(tf.reduce_mean(tf.square(tf.subtract(x_, decoded)))
                        )+reg*0.0001

它不适用于错误:

Traceback (most recent call last):
File "L1_02.py", line 45, in <module>
train_X_=model.fit_transform(train_X)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 93, in fit_transform
self.fit(x)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 70, in fit
print_step=self.print_step, lambda_=self.lambda_)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 138, in run
reg=tf.contrib.layers.apply_regularization(groupl1,weightss)
NameError: global name 'groupl1' is not defined

我很困惑,因为我在代码中清楚地说明了groupl1函数。 我有什么问题?你知道吗


Tags: inpyreducehometflinesqrtreg