Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 示例中的打字错误“;使用Keras在Tensorflow中自定义图层;_Python_Tensorflow_Keras - Fatal编程技术网

Python 示例中的打字错误“;使用Keras在Tensorflow中自定义图层;

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

我认为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])

  ...

init方法只需要:

super(MySimpleLayer, self).__init__()
如果没有此行,将显示缺少属性的错误,例如:

AttributeError: 'MySimpleLayer' object has no attribute '_scope'
,它们是父类的一部分