我不太明白这个代码是什么意思:
# instantiate the input layer
x = Input(batch_shape=batch_input_shape,
dtype=input_dtype, name=name)
# this will build the current layer
# and create the node connecting the current layer
# to the input layer we just created.
self(x)此代码位于一个类的成员函数中,请参考https://github.com/fchollet/keras/blob/master/keras/engine/topology.py第341行。当我步入self(x)时,它跳转到这个类的另一个成员函数__call__。这一切为什么要发生?谢谢。
发布于 2016-06-03 00:30:17
__call__()是Python语言中的一种特殊方法。它允许类模拟函数类型。
按照惯例,self可能是成员函数的第一个参数,即方法被调用的对象的实例。
因此,self()使用当前实例对象作为函数。根据定义,这意味着对象上的__call__()方法将被调用,这正是发生的事情。
https://stackoverflow.com/questions/37597268
复制相似问题