Python 示例中的打字错误“;使用Keras在Tensorflow中自定义图层;
我认为Tensorflow中有一个使用Keras构建自定义层的错误。本教程介绍如何使用渴望模式。唯一缺失的部分是Python 示例中的打字错误“;使用Keras在Tensorflow中自定义图层;,python,tensorflow,keras,Python,Tensorflow,Keras,我认为Tensorflow中有一个使用Keras构建自定义层的错误。本教程介绍如何使用渴望模式。唯一缺失的部分是 super(MySimpleLayer, self).__init__() 在init方法中: class MySimpleLayer(tf.keras.layers.Layer): def __init__(self, output_units): **super(MySimpleLayer, self).__init__()** self.output_u
super(MySimpleLayer, self).__init__()
在init方法中:
class MySimpleLayer(tf.keras.layers.Layer):
def __init__(self, output_units):
**super(MySimpleLayer, self).__init__()**
self.output_units = output_units
def build(self, input):
# The build method gets called the first time your layer is used.
# Creating variables on build() allows you to make their shape depend
# on the input shape and hence remove the need for the user to specify
# full shapes. It is possible to create variables during __init__() if
# you already know their full shapes.
self.kernel = self.add_variable(
"kernel", [input.shape[-1], self.output_units])
...
init方法只需要:
super(MySimpleLayer, self).__init__()
如果没有此行,将显示缺少属性的错误,例如:
AttributeError: 'MySimpleLayer' object has no attribute '_scope'
,它们是父类的一部分