示例中的拼写错误"custom layer in Tensorflow using Keras"



我认为Tensorflow示例中有一个拼写错误,用于使用Keras构建自定义层。本教程介绍如何使用热切模式。 唯一缺少的部分是

super(MySimpleLayer, self).__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'

,是父类的一部分。

最新更新