title: Output dimension from transfer learning model incompatible
body: <p>I have loaded the <code>cifar10</code> dataset in keras for r and have images of shape 32x32x3 with 10 labels.</p>
  <pre><code>library(keras)
  
  c(train_images, train_labels) %&lt;-% cifar$train
  c(test_images, test_labels) %&lt;-% cifar$test
  
  train_images %&gt;% dim # 50000    32    32     3
  train_labels %&gt;% dim # 50000    1
  test_images %&gt;% dim  # 50000    32    32     3
  test_labels %&gt;% dim  # 50000    1
  length(unique(train_labels)) # 10
  </code></pre>
  <p>Now I have also loaded a pre-trained imagenet model and everything is cool up until training, I even confirm that I have exactly 10 labels, which are the number of classes I have.</p>
  <pre><code>conv_base &lt;- keras::application_resnet101(weights = &quot;imagenet&quot;,
                                            include_top = FALSE, 
                                            input_shape = c(32,32,3))
  
  
  freeze_weights(conv_base)
  
  model &lt;- keras_model_sequential() %&gt;%
    conv_base %&gt;%
    layer_flatten() %&gt;%
    layer_dense(units = 256, activation = &quot;relu&quot;) %&gt;%
    layer_dense(units = 10, activation = &quot;softmax&quot;)
  
  
  model %&gt;% compile(
    optimizer = &quot;adam&quot;,
    loss = &quot;categorical_crossentropy&quot;,
    metrics = &quot;accuracy&quot;
  )
  
  # unfreeze_weights(conv_base, from = &quot;block5_conv1&quot;)
  
  history &lt;- model %&gt;% fit(
    x=train_images, y=train_labels, 
    validation_split = 0.3,
    epochs=10, 
    verbose = 2
  )
  </code></pre>
  <p>the <code>summary(model)</code> tells me that the output is <code>10</code> as expected.</p>
  <pre><code>Model: &quot;sequential_10&quot;
  __________________________________________________________________________________
  Layer (type)                        Output Shape                     Param #      
  ==================================================================================
  resnet101 (Functional)              (None, 1, 1, 2048)               42658176     
  __________________________________________________________________________________
  flatten_5 (Flatten)                 (None, 2048)                     0            
  __________________________________________________________________________________
  dense_24 (Dense)                    (None, 256)                      524544       
  __________________________________________________________________________________
  dense_23 (Dense)                    (None, 10)                       2570         
  ==================================================================================
  Total params: 43,185,290
  Trainable params: 527,114
  Non-trainable params: 42,658,176
  </code></pre>
  <p>But once I train, I get errors an error saying 1 isn't the same shape as the expected 10 on the output. The error is:</p>
  <pre><code>Epoch 1/10
  Error in py_call_impl(callable, dots$args, dots$keywords) : 
    ValueError: in user code:
  &lt;... omitted ...&gt; C:\Users\blake\ANACON~1\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper
          return target(*args, **kwargs)
      C:\Users\blake\ANACON~1\lib\site-packages\tensorflow\python\keras\losses.py:1537 categorical_crossentropy
          return K.categorical_crossentropy(y_true, y_pred, from_logits=from_logits)
      C:\Users\blake\ANACON~1\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper
          return target(*args, **kwargs)
      C:\Users\blake\ANACON~1\lib\site-packages\tensorflow\python\keras\backend.py:4833 categorical_crossentropy
          target.shape.assert_is_compatible_with(output.shape)
      C:\Users\blake\ANACON~1\lib\site-packages\tensorflow\python\framework\tensor_shape.py:1134 assert_is_compatible_with
          raise ValueError(&quot;Shapes %s and %s are incompatible&quot; % (self, other))
  
      ValueError: Shapes (None, 1) and (None, 10) are incompatible
  
  See `reticulate::py_last_error()` for details
  </code></pre>