Custom keras dataset generator not accepted by fit_generator
I was following the instructions on a tutorial but it seems that there was a mistake or that the internal code of TensorFlow has changed since it was written. I was defining my class like this:

class DataGenerator(tf.keras.utils.Sequence):


and later on I tried also this:

class DataGenerator(tf.keras.models.Sequential):


(which, by the way, is completely different and is totally wrong)

Inspecting the code for some of the adapters, I saw this:

class KerasSequenceAdapter(GeneratorDataAdapter):
  """Adapter that handles `keras.utils.Sequence`."""

  @staticmethod
  def can_handle(x, y=None):
    return isinstance(x, data_utils.Sequence)


and also for my other suspect adapter:

class GeneratorDataAdapter(DataAdapter):
  """Adapter that handles python generators and iterators."""

  @staticmethod
  def can_handle(x, y=None):
    return ((hasattr(x, "__next__") or hasattr(x, "next"))
            and hasattr(x, "__iter__")
            and not isinstance(x, data_utils.Sequence))


where data_utils is defined as:

from tensorflow.python.keras.utils import data_utils


So, I changed the definition of my class to this:

from tensorflow.python.keras.utils import data_utils
class RandomFramesFromPathsToVideos(data_utils.Sequence):


and now it works.

I've got, so, two options. Using a subclass from data_utils.Sequence is one of them. In that case, we are talking about a "Keras generator" (handled in TensorFlow by KerasSequenceAdapter) in which you need to define two methods: __len__ and __getitem__

The other one is building a new class NOT DERIVED from data_utils.Sequence, and defining the methods __iter__ and __next__ (or simply next). In that case we are defining an standard Python generator, which will be handled by GeneratorDataAdapter inside TensorFlow

Please, bear in mind that a Keras generator is not the same thing as a Python generator. At first, that confused me a lot.