问题描述
我正在研究Tensorflow BasicLSTMCell 发现该类中有两种类似的方法:__call__
和call
.两种方法具有相同的参数,文档中没有说明不同之处.引用源代码不给我任何线索.但是我猜想__call__
方法是从某个地方继承的,而call
会覆盖__call__
.如果是这种情况,为什么不直接在源代码中使用__call__
而不是call
?
I am studying Tensorflow BasicLSTMCell while I found that there are two similar methods within the class: __call__
and call
. The two methods has the same parameters and the documentation does not say the difference. Refering the source code does not give me any clue of this. But I am guessing that the the __call__
method is inherited from somewhere, and call
overrides __call__
. If this is the case, why not just use __call__
instead of call
in the source code?
推荐答案
我在研究 RNNCell 时遇到了类似的问题.
I ran into similar problem when studying RNNCell.
__ call __ 是在 base_layer.py 的类 Layer 中包装的,在 call 中,应用pre-和后处理步骤".
It is in Class Layer in base_layer.py that __call__ wraps in call, "applying pre- and post-processing steps".
这篇关于TensorFlow BasicLSTMCell实现中的'call'和'__call__'有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!