title: How to fix Keras ValueError: Shapes (None, 3, 2) and (None, 2) are incompatible?
body: <p>The following code gives me error <code>ValueError: Shapes (None, 3, 2) and (None, 2) are incompatible</code>. What I want to do is to construct a multi-task network. How should I resolve it? I am using Tensorflow 2.3.0.</p>
  <pre><code>import numpy as np
  import tensorflow as tf
  from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Dropout
  from tensorflow.keras import Model
  
  
  base_model = tf.keras.applications.EfficientNetB7(input_shape=(32,32, 3), weights='imagenet',
                                                    include_top=False)  # or weights='noisy-student'
  
  for layer in base_model.layers[:]:
      layer.trainable = False
  
  x = GlobalAveragePooling2D()(base_model.output)
  dropout_rate = 0.3
  
  
  x = Dense(256, activation='relu')(x)
  x = Dropout(dropout_rate)(x)
  x = Dense(256, activation='relu')(x)
  x = Dropout(dropout_rate)(x)
  
  
  all_target = []
  loss_list = []
  test_metrics = {}
  for name, node in  [(&quot;task1&quot;, 2), (&quot;task2&quot;, 2), (&quot;task3&quot;, 2)]:
      y1 = Dense(128, activation='relu')(x)
      y1 = Dropout(dropout_rate)(y1)
      y1 = Dense(64, activation='relu')(y1)
      y1 = Dropout(dropout_rate)(y1)
      # y1 = Dense(64, activation='relu')(y1)
      # y1 = Dropout(dropout_rate)(y1)
      y1 = Dense(node, activation='softmax', name=name)(y1)
      all_target.append(y1)
      loss_list.append('categorical_crossentropy')
      test_metrics[name] = &quot;accuracy&quot;
  
  #    model = Model(inputs=model_input, outputs=[y1, y2, y3])
  model = Model(inputs=base_model.input, outputs=all_target)
  
  model.compile(loss=loss_list, optimizer='adam', metrics=test_metrics)
  
  res=np.random.randint(2, size=3072).reshape(32, 32, 3)
  res=np.expand_dims(res, 0)
  
  lab=np.array([[[0,1], [0,1], [0,1]]])
  
  history = model.fit(res, y=lab, epochs=1, verbose=1)
  </code></pre>