超级成就了什么

时间:2019-05-16 05:05:28

标签: python keras-layer

这是用于构建自定义keras层的代码

class MyLayer(Layer):

    def __init__(self, output_dim, **kwargs):
        self.output_dim = output_dim
        super(MyLayer, self).__init__(**kwargs)

超级在这里做什么,这绝对必要吗? 我不明白什么是继承

1 个答案:

答案 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

您可以在

上阅读有关超级和继承的更多信息。

https://realpython.com/python-super/