title: Error: When subclassing the `Model` class, you should implement a `call` method. on tensorflow custom model
body: <p>I am trying to train my custom model on Cifar 10 dataset.
   My model's code is below: -</p>
  
  <pre><code>class cifar10Model(keras.Model):
    def __init__(self):
      super(cifar10Model, self).__init__()
      self.conv1 = keras.layers.Conv2D(32, 3, activation='relu', input_shape=(32, 32, 3))
      self.pool1 = keras.layers.MaxPool2D((3, 3))
      self.batch_norm1 = keras.layers.BatchNormalization()
      self.dropout1 = keras.layers.Dropout(0.1)
  
      self.conv2 = keras.layers.Conv2D(64, 3, activation='relu')
      self.pool2 = keras.layers.MaxPool2D((3, 3))
      self.batch_norm2 = keras.layers.BatchNormalization()
      self.dropout2 = keras.layers.Dropout(0.2)
  
      self.conv3 = keras.layers.Conv2D(128, 3, activation='relu')
      self.pool3 = keras.layers.MaxPool2D((3, 3))
      self.batch_norm3 = keras.layers.BatchNormalization()
      self.dropout3 = keras.layers.Dropout(0.3)
  
      self.flatten = keras.layers.Flatten()
      self.dense1 = keras.layers.Dense(128, activation='relu')
      self.dense2 = keras.layers.Dense(10)
  
      def call(self, x):
        x = self.conv1(x)
        x = self.pool1(x)
        x = self.batch_norm1(X)
        x = self.dropout1(x)
  
        x = self.conv2(x)
        x = self.pool2(x)
        x = self.batch_norm2(X)
        x = self.dropout2(x)
  
        x = self.conv3(x)
        x = self.pool3(x)
        x = self.batch_norm3(x)
        x = self.dropout3(x)
  
        x = self.flatten(x)
        x = self.dense1(x)
        return self.dense2(x)
  
  model = cifar10Model()
  </code></pre>
  
  <p>When i run this code this gives me no error.</p>
  
  <p>Then i defined my training loop</p>
  
  <pre><code>loss_object = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
  
  optimizer = keras.optimizers.Adam()
  
  train_loss = tf.keras.metrics.Mean(name='train_loss')
  train_accuracy = tf.keras.metrics.SparseCategoricalAccuracy(name='train_accuracy')
  
  test_loss = tf.keras.metrics.Mean(name='test_loss')
  test_accuracy = tf.keras.metrics.SparseCategoricalAccuracy(name='test_accuracy')
  
  @tf.function
  def train_step(images, labels):
    with tf.GradientTape() as tape:
      predictions = model(images, training=True)
      loss = loss_object(labels, predictions)
    grad = tape.gradient(loss, model.trainable_variables)
    optimizer.apply_gradients(zip(grad, model.trainable_variables))
    train_loss(loss)
    train_accuracy(labels, predictions)
  
  @tf.function
  def test_step(images, labels):
    predictions = model(images)
    t_loss = loss_object(labels, predictions)
  
    test_loss(t_loss)
    test_accuracy(labels, predictions)
  
  epochs = 10
  
  for epoch in range(epochs):
    train_loss.reset_states()
    train_accuracy.reset_states()
    test_loss.reset_states()
    test_accuracy.reset_states()
  
    for images, labels in train_dataset:
      train_step(images, labels)
  
    for images, labels in test_dataset:
      test_step(images, labels)
  
    template = 'Epoch {}, Loss: {}, Accuracy: {}, Test Loss: {}, Test Accuracy: {}'
    print(template.format(epoch + 1,
                          train_loss.result(),
                          train_accuracy.result() * 100,
                          test_loss.result(),
                          test_accuracy.result() * 100))
  </code></pre>
  
  <p>When i run this code, i get the following error</p>
  
  <pre><code>NotImplementedError: When subclassing the `Model` class, you should implement a `call` method.
  </code></pre>
  
  <p>I am currently running my code on google colab.</p>
  
  <p>My colab link is <a href="https://colab.research.google.com/drive/1sOlbRpPRdyOCJI0zRFfIA-Trj1vrIbWY?usp=sharing" rel="nofollow noreferrer">https://colab.research.google.com/drive/1sOlbRpPRdyOCJI0zRFfIA-Trj1vrIbWY?usp=sharing</a></p>
  
  <p>My tensorflow version on colab is 2.2.0</p>
  
  <p>Also, when i tried to predict labels from untrained model by this code :-</p>
  
  <pre><code>print(model(train_images))
  </code></pre>
  
  <p>This also gives me the same error.
  The error is saying that i have not implemented the call method on model.
  but, i have defined the call method.</p>
  
  <p>I also tried by changing the call method to <code>__call__</code> method.</p>
  
  <p>But still, it gives me the same error.</p>
  
  <p>Thanks in advance :-</p>