Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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 使用tf.keras.layers.concatenate()作为tensorflow中的自定义层_Python_Tensorflow_Keras_Neural Network - Fatal编程技术网

Python 使用tf.keras.layers.concatenate()作为tensorflow中的自定义层

Python 使用tf.keras.layers.concatenate()作为tensorflow中的自定义层,python,tensorflow,keras,neural-network,Python,Tensorflow,Keras,Neural Network,我想使用tensorflow中的自定义层制作U-net。我需要使用tf.keras.layers.concatenate,这就是我的问题。为我可以在方法调用中添加到层的所有其他层输入张量。但是连接层的语法是tf.keras.layers.concatenate(输入,axis),我需要类似于tf.keras.layers.concatenate(axis)(输入)的东西,但它不起作用。有人能帮我吗? 多谢各位 我的代码是这样的: class MyModel(tf.keras.Model):

我想使用tensorflow中的自定义层制作U-net。我需要使用tf.keras.layers.concatenate,这就是我的问题。为我可以在方法调用中添加到层的所有其他层输入张量。但是连接层的语法是tf.keras.layers.concatenate(输入,axis),我需要类似于tf.keras.layers.concatenate(axis)(输入)的东西,但它不起作用。有人能帮我吗?
多谢各位

我的代码是这样的:

class MyModel(tf.keras.Model):
  def __init__(self):
    super(MyModel, self).__init__()
    self.block1 = Conv2D(.....)
    self.block2 = BatchNormalization()
    ....etc.....
    self.decoder_concat = tf.keras.layers.concatenate(axis=-1) #that i need but it does not work

  def call(self, inputs):
     x = self.block1(inputs)
     x = self.block2(x)
     ....etc......
     x = self.decoder_concat([x, concatLayer]) #that i need but it does not work

在这里提供解决方案(答案部分),即使它出现在评论部分,也是为了社区的利益

tf.keras.layers.concatenate
更改为
tf.keras.layers.concatenate
后,该问题已得到解决

tf.keras.layers.Concatenate
用作连接Tensorflow中输入列表的层,其中as
tf.keras.layers.Concatenate
充当连接层的功能接口。请参阅更多详情

请参阅下面更新的代码

class MyModel(tf.keras.Model):
  def __init__(self):
    super(MyModel, self).__init__()
    self.block1 = Conv2D(.....)
    self.block2 = BatchNormalization()
    ....etc.....
    self.decoder_concat = tf.keras.layers.Concatenate(axis=-1) #that i need but it does not work

  def call(self, inputs):
     x = self.block1(inputs)
     x = self.block2(x)
     ....etc......
     x = self.decoder_concat([x, concatLayer]) #that i need but it does not work

您只需使用
与大写字母C串联即可。谢谢,它解决了问题。注意:方法调用中的连接参数(在[]括号中)必须是方法调用中的层的输出(在我的例子中,这些是x-es)。它不能被构造函数阻塞(在我的例子中,例如self.block1),因为我们想要连接张量(x-es)而不是层(block1)。