Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch_normalization 为啥不传入training字段啊, #36

Open
lihairui1990 opened this issue May 16, 2020 · 8 comments
Open

batch_normalization 为啥不传入training字段啊, #36

lihairui1990 opened this issue May 16, 2020 · 8 comments

Comments

@lihairui1990
Copy link

tf.layers.batch_normalization(inputs=in_, name='bn1' + stag, reuse=tf.AUTO_REUSE)

这里为啥不传入training 这个字段啊,之前看batch_normalization都需要传入training字段啊,训练时传入True 测试时传入False

training: Either a Python boolean, or a TensorFlow boolean scalar tensor
  (e.g. a placeholder). Whether to return the output in training mode
  (normalized with statistics of the current batch) or in inference mode
  (normalized with moving statistics). **NOTE**: make sure to set this
  parameter correctly, or else your training/inference will not work
  properly.
@WLCOOLONGS
Copy link

bn1 = tf.layers.batch_normalization(inputs=inp, name='bn1', training=train_or_test)
self.update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(self.update_ops):
self.optimizer = tf.train.AdamOptimizer(learning_rate=self.lr).minimize(self.loss)

@lihairui1990
Copy link
Author

我知道这个,我的问题是作者给出的源码中没有你写的这些代码啊,正常在训练的时候,
主要是没有这个 with tf.control_dependencies(self.update_ops):

@codefish1990
Copy link

@WangLianChen 请问添加完这些代码后,是否能正常运行? 我这添加了这几行代码,出现Segmentation fault。

@yeren1989
Copy link

应该是写错了,不加入is_training,用了测试集真实的特征分布,效果会比真实效果好一些;
此外,既然没有设置 is_training,那么update_ops的执行也就没区别了~

@Waydrow
Copy link

Waydrow commented Mar 2, 2021

应该是写错了,不加入is_training,用了测试集真实的特征分布,效果会比真实效果好一些;
此外,既然没有设置 is_training,那么update_ops的执行也就没区别了~

确实。。我加上training=true后,结果反而下降了。很迷惑

@liyangliu
Copy link

@lihairui1990 If the training argument is not set, its default value is False. Then in this repo, the BN layer always has mean=0 and variance=1 which can not be updated. This problem also exists in the original DIN repo https://github.com/zhougr1993/DeepInterestNetwork/blob/master/din/model.py#L49.

@liyangliu
Copy link

@Waydrow Have you reproduced results in the DIEN paper or README.md (of https://github.com/zhougr1993/DeepInterestNetwork)? Using the original DIN code https://github.com/zhougr1993/DeepInterestNetwork, I only got 0.8677 GAUC for DIN on Amazon Electronics dataset, a bit less than the reported 0.8698 (please refer to zhougr1993/DeepInterestNetwork#92).

@Waydrow
Copy link

Waydrow commented Jan 16, 2023

@liyangliu I failed too...lol
However, I reproduced results in the DSIN paper with the released code https://github.com/shenweichen/DSIN. Maybe you can try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants