簡體   English   中英

示例中的錯字“使用Keras在Tensorflow中定制層”

[英]Typo in the example “custom layer in Tensorflow using 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_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])

  ...

初始化方法只需要:

super(MySimpleLayer, self).__init__()

如果沒有此行,將顯示缺少屬性的錯誤,例如:

AttributeError: 'MySimpleLayer' object has no attribute '_scope'

,它們是父類的一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM