title: problems to compile and fit the model in tensorflow/keras
body: <p>I'm trying to compile and fit a model but, this error is occurring:</p>
  <p>ValueError: Shapes (None, 10, 10, 10) and (None, 10) are incompatible</p>
  <p>code:</p>
  <pre><code>from tensorflow.keras.layers import Conv2D
  
  model = Sequential()
  model.add(Conv2D(filters=32, kernel_size=3, activation=&quot;relu&quot;, input_shape=(28, 28, 1)))
  model.add(Conv2D(filters=32, kernel_size=3, activation=&quot;relu&quot;))
  model.add(Flatten())
  model.add(Dense(128, activation=&quot;relu&quot;))
  model.add(Dense(10, activation=&quot;softmax&quot;))
  
  # Compile the model
  model.compile(loss=&quot;categorical_crossentropy&quot;, metrics=[&quot;accuracy&quot;], optimizer=&quot;adam&quot;)
  
  # Fit the model
  model.fit( x=X_train, y=y_train, batch_size=32, epochs=10, validation_split = 0.3)
  </code></pre>
  <p>Output:</p>
  <pre><code>Epoch 1/10
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-18-a118e2826a10&gt; in &lt;module&gt;()
        3 
        4 # Fit the model
  ----&gt; 5 model.fit( x=X_train, y=y_train, batch_size=32, epochs=10, validation_split = 0.3)
  
      1 frames
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs) 
         1145           except Exception as e:  # pylint:disable=broad-except  
         1146             if hasattr(e, &quot;ag_error_metadata&quot;):  
      -&gt; 1147               raise e.ag_error_metadata.to_exception(e)  
         1148             else:  
         1149               raise  
  
  ValueError: in user code:
  
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1021, in train_function  *
          return step_function(self, iterator)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1010, in step_function  **
          outputs = model.distribute_strategy.run(run_step, args=(data,))
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1000, in run_step  **
          outputs = model.train_step(data)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 860, in train_step
          loss = self.compute_loss(x, y, y_pred, sample_weight)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 919, in compute_loss
          y, y_pred, sample_weight, regularization_losses=self.losses)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py&quot;, line 201, in __call__
          loss_value = loss_obj(y_t, y_p, sample_weight=sw)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/losses.py&quot;, line 141, in __call__
          losses = call_fn(y_true, y_pred)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/losses.py&quot;, line 245, in call  **
          return ag_fn(y_true, y_pred, **self._fn_kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/losses.py&quot;, line 1790, in categorical_crossentropy
          y_true, y_pred, from_logits=from_logits, axis=axis)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/backend.py&quot;, line 5083, in categorical_crossentropy
          target.shape.assert_is_compatible_with(output.shape)
  
      ValueError: Shapes (None, 10, 10, 10) and (None, 10) are incompatible
  </code></pre>
  <p>I'm using tensorflow 2.8.2</p>
  <p>How can i put it to work ?<br />
  What am i doing wrong ?</p>
  <p>edit :
  the problem was that I ran this part of the program twice (dumb mistake):</p>
  <pre><code>from tensorflow.keras.utils import to_categorical
  
  y_train = to_categorical(y_train, num_classes=10)
  y_test = to_categorical(y_test, num_classes=10)
  
  print(&quot;Shape of y_train:&quot;, y_train.shape)
  print(&quot;One value of y_train:&quot;, y_train[0])
  </code></pre>
  <p>I restarted the environment, and the problem was fixed.</p>