Why is tf.keras.Model accept 'inputs' and 'outputs' but derived doesn't?

Hi,

Looking at Making new layers and models via subclassing I see that the derived class:

class VariationalAutoEncoder(keras.Model):
...

does not accept the ‘inputs’ keyword argument. I wondered why that is? I see that the code keras/generic_utils.py at v2.6.0 · keras-team/keras · GitHub

forbids it, but then, why would inputs and outputs need to be defined for the plain tf.keras.Model, but not for a derived class?

Hi @hrbigelow

Welcome to the TensorFlow Forum!

Model subclasses do not accepts inputs as Model does because these are not actual the models. These are sub classes of the actual model and defined for the specific functionality. Subclassed model will create its own input layer which will be defined inside the call function to take the inputs and generate the outputs based on the call function defined. So no need to provide the inputs explicitly.

Whereas the inputs and outputs need to be defined for the actual model (tf.keras.Model) because these models are made for general-purpose and can be used to build variety of models. Here, user need to specify the input and output layer of the model by providing inputs and outputs args to the model.