这是用于构建自定义keras层的代码
class MyLayer(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
super(MyLayer, self).__init__(**kwargs)
超级在这里做什么,这绝对必要吗? 我不明白什么是继承
答案 0 :(得分:2)
欢迎来到stackoverflow。超级-
“.. returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.”
特别是在Keras的情况下,基本层执行该类的所有基本操作,如源代码中一样,
https://github.com/keras-team/keras/blob/master/keras/engine/base_layer.py#L21
您可以在
上阅读有关超级和继承的更多信息。