title: Invalid Argument Error / Graph Execution Error
body: <p>I'm having multiple errors while running this VGG training code (code and errors shown below). I don't know if its because of my dataset or is it something else.</p>
  <pre><code>import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import tensorflow as tf
  from tensorflow.keras.preprocessing import image
  from tensorflow.keras.applications.vgg16 import preprocess_input
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
  from sklearn.metrics.pairwise import cosine_similarity
  import os
  import scipy
  
  train_directory = 'sign_data/train' #To be changed
  test_directory = 'sign_data/test' #To be changed
  
  train_datagen = ImageDataGenerator(
      rescale = 1./255,
      rotation_range = 0.1,
      width_shift_range = 0.2,
      height_shift_range = 0.2,
      shear_range = 0.1
  )
  
  train_generator = train_datagen.flow_from_directory(
      train_directory,
      target_size = (224, 224),
      color_mode = 'rgb',
      shuffle = True,
      batch_size=32
      
  )
  
  
  test_datagen = ImageDataGenerator(
      rescale = 1./255,
  )
  
  test_generator = test_datagen.flow_from_directory(
      test_directory,
      target_size = (224, 224),
      color_mode = 'rgb',
      shuffle = True,
      batch_size=32
  )
  
  from tensorflow.keras.applications.vgg16 import VGG16   
  vgg_basemodel = VGG16(include_top=True)
  
  from tensorflow.keras.callbacks import ReduceLROnPlateau, ModelCheckpoint, EarlyStopping
  
  early_stopping = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=5)
  
  vgg_model = tf.keras.Sequential(vgg_basemodel.layers[:-1])
  vgg_model.add(tf.keras.layers.Dense(10, activation = 'softmax'))
  
  # Freezing original layers
  for layer in vgg_model.layers[:-1]:
      layer.trainable = False
  
  vgg_model.compile(loss='categorical_crossentropy',
                    optimizer=tf.keras.optimizers.SGD(momentum=0.9, learning_rate=0.001, decay=0.01),
                    metrics=['accuracy'])
  
  history = vgg_model.fit(train_generator,
                epochs=30,
                batch_size=64,
                validation_data=test_generator,
                callbacks=[early_stopping])
  
  # finetuning with all layers set trainable
  
  for layer in vgg_model.layers:
      layer.trainable = True
  
  vgg_model.compile(loss='categorical_crossentropy',
                    optimizer=tf.keras.optimizers.SGD(momentum=0.9, lr=0.0001),
                    metrics=['accuracy'])
  
  history2 = vgg_model.fit(train_generator,
                epochs=5,
                batch_size=64,
                validation_data=test_generator,
                callbacks=[early_stopping])
  
  vgg_model.save('saved_models/vgg_finetuned_model')
  </code></pre>
  <p>First error: Invalid Argument Error</p>
  <pre><code>    InvalidArgumentError                      Traceback (most recent call last)
  &lt;ipython-input-13-292bf57ef59f&gt; in &lt;module&gt;()
       14               batch_size=64,
       15               validation_data=test_generator,
  ---&gt; 16               callbacks=[early_stopping])
       17 
       18 # finetuning with all layers set trainable
  
      /usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
       65     except Exception as e:  # pylint: disable=broad-except
       66       filtered_tb = _process_traceback_frames(e.__traceback__)
  ---&gt; 67       raise e.with_traceback(filtered_tb) from None
       68     finally:
       69       del filtered_tb
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
       53     ctx.ensure_initialized()
       54     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
  ---&gt; 55                                         inputs, attrs, num_outputs)
       56   except core._NotOkStatusException as e:
       57     if name is not None:
  </code></pre>
  <p>Second Error: Graph Execution Error</p>
  <pre><code>    InvalidArgumentError: Graph execution error:
  Detected at node 'categorical_crossentropy/softmax_cross_entropy_with_logits' defined at (most recent call last):
      File &quot;/usr/lib/python3.7/runpy.py&quot;, line 193, in _run_module_as_main
        &quot;__main__&quot;, mod_spec)
      File &quot;/usr/lib/python3.7/runpy.py&quot;, line 85, in _run_code
        exec(code, run_globals)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py&quot;, line 16, in &lt;module&gt;
        app.launch_new_instance()
      File &quot;/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py&quot;, line 846, in launch_instance
        app.start()
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/kernelapp.py&quot;, line 499, in start
        self.io_loop.start()
      File &quot;/usr/local/lib/python3.7/dist-packages/tornado/platform/asyncio.py&quot;, line 132, in start
        self.asyncio_loop.run_forever()
      File &quot;/usr/lib/python3.7/asyncio/base_events.py&quot;, line 541, in run_forever
        self._run_once()
      File &quot;/usr/lib/python3.7/asyncio/base_events.py&quot;, line 1786, in _run_once
        handle._run()
      File &quot;/usr/lib/python3.7/asyncio/events.py&quot;, line 88, in _run
        self._context.run(self._callback, *self._args)
      File &quot;/usr/local/lib/python3.7/dist-packages/tornado/platform/asyncio.py&quot;, line 122, in _handle_events
        handler_func(fileobj, events)
      File &quot;/usr/local/lib/python3.7/dist-packages/tornado/stack_context.py&quot;, line 300, in null_wrapper
        return fn(*args, **kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py&quot;, line 452, in _handle_events
        self._handle_recv()
      File &quot;/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py&quot;, line 481, in _handle_recv
        self._run_callback(callback, msg)
      File &quot;/usr/local/lib/python3.7/dist-packages/zmq/eventloop/zmqstream.py&quot;, line 431, in _run_callback
        callback(*args, **kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/tornado/stack_context.py&quot;, line 300, in null_wrapper
        return fn(*args, **kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py&quot;, line 283, in dispatcher
        return self.dispatch_shell(stream, msg)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py&quot;, line 233, in dispatch_shell
        handler(stream, idents, msg)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/kernelbase.py&quot;, line 399, in execute_request
        user_expressions, allow_stdin)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/ipkernel.py&quot;, line 208, in do_execute
        res = shell.run_cell(code, store_history=store_history, silent=silent)
      File &quot;/usr/local/lib/python3.7/dist-packages/ipykernel/zmqshell.py&quot;, line 537, in run_cell
        return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py&quot;, line 2718, in run_cell
        interactivity=interactivity, compiler=compiler, result=result)
      File &quot;/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py&quot;, line 2822, in run_ast_nodes
        if self.run_code(code, result):
      File &quot;/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py&quot;, line 2882, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File &quot;&lt;ipython-input-13-292bf57ef59f&gt;&quot;, line 16, in &lt;module&gt;
        callbacks=[early_stopping])
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py&quot;, line 64, in error_handler
        return fn(*args, **kwargs)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1384, in fit
        tmp_logs = self.train_function(iterator)
      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 5099, in categorical_crossentropy
        labels=target, logits=output, axis=axis)
  Node: 'categorical_crossentropy/softmax_cross_entropy_with_logits'
  logits and labels must be broadcastable: logits_size=[32,10] labels_size=[32,128]
       [[{{node categorical_crossentropy/softmax_cross_entropy_with_logits}}]] [Op:__inference_train_function_11227]
  </code></pre>
  <p>I'm running this on google colaboratory. Is there a module that I should install? Or is it purely an error on the code itself?</p>