如何在张量流模型调用函数中给出多个参数?

我试图通过在tensorflow.keras中扩展'Model'类来在tensorflow中构建模型。我需要在此类的“调用”函数中传递两个参数,即输入图像x(224,224,3)和输出标签y。但是在构建模型时出现以下错误:

  

ValueError:当前,如果具有   不是输入模型的位置参数或关键字参数   是其“通话”方法所必需的。

class mycnn(Model):
  def __init__(self):
    super(mycnn,self).__init__()

    base_model = tf.keras.applications.VGG16(input_shape=(224,3),weights='imagenet')
    layer_name = 'block5_conv3'
    self.conv_1 = Model(inputs=base_model.input,outputs=base_model.get_layer(layer_name).output)
    self.flatten = L.flatten(name='flatten')
    self.fc1 = L.Dense(1000,activation='relu',name='fc1')
    self.final = L.activation('softmax')

  # The problem is because I need y
  def call(self,x,y):
    x = self.conv_1(x)
    x = self.flatten(x)
    x = self.fc1(x)
    return self.final(x)

model = mycnn()
model.build((None,3,1))
hoho1141 回答:如何在张量流模型调用函数中给出多个参数?

调用方法的输入参数可以是input tensorlist/tuple of input tensors

你可以像这样传递两个参数:

def call(self,inputs):
    x = inputs[0]
    y = inputs[1]
    x = self.conv_1(x)
    x = self.flatten(x)
    x = self.fc1(x)
    return self.final(x)  
本文链接:https://www.f2er.com/3154002.html

大家都在问