首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python函数在Tensorflow中不起作用: tf.contrib.layers.apply_regularization

python函数在Tensorflow中不起作用: tf.contrib.layers.apply_regularization
EN

Stack Overflow用户
提问于 2017-06-28 15:15:36
回答 1查看 180关注 0票数 0

我的功能是:

代码语言:javascript
复制
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)))

当我把它放到我的代码中时:

代码语言:javascript
复制
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

它在出现错误时不起作用:

代码语言:javascript
复制
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函数。我的问题出在哪里?

EN

回答 1

Stack Overflow用户

发布于 2017-06-28 15:18:01

只是猜测一下,您是否在调用之前定义了函数

代码语言:javascript
复制
def groupl1(x):
    return ...

.
.
.

groupl1(example_input)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44795910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档