I'm trying to build a model in tensorflow by extending the 'Model' class in tensorflow.keras. I need to pass two arguments in the 'call' function of this class, input images x (224,224,3) and output label y. But I get the following error while building the model:
ValueError: Currently, you cannot build your model if it has positional or keyword arguments that are not input to the model, but are required for its 'call' method.
class myCNN(Model):
def __init__(self):
super(myCNN, self).__init__()
base_model = tf.keras.applications.VGG16(input_shape=(224,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, 224, 224, 3, 1))