keras/src/trainers/data_adapters/generator_data_adapter.py/GeneratorDataAdapter/get_tf_dataset
class GeneratorDataAdapter:    def get_tf_dataset(self):
        from keras.src.utils.module_utils import tensorflow as tf

        def convert_to_tf(x, spec):
            if data_adapter_utils.is_scipy_sparse(x):
                x = data_adapter_utils.scipy_sparse_to_tf_sparse(x)
            elif data_adapter_utils.is_jax_sparse(x):
                x = data_adapter_utils.jax_sparse_to_tf_sparse(x)
            if not spec.shape.is_compatible_with(x.shape):
                raise TypeError(
                    f"Generator yielded an element of shape {x.shape} where "
                    f"an element of shape {spec.shape} was expected. Your "
                    "generator provides tensors with variable input "
                    "dimensions other than the batch size. Make sure that the "
                    "generator's first two batches do not have the same "
                    "dimension value wherever there is a variable input "
                    "dimension."
                )
            return x

        def get_tf_iterator():
            for batch in self.generator:
                batch = tree.map_structure(
                    convert_to_tf, batch, self._output_signature
                )
                yield batch

        if self._output_signature is None:
            self._output_signature = data_adapter_utils.get_tensor_spec(
                self._first_batches
            )
        ds = tf.data.Dataset.from_generator(
            get_tf_iterator,
            output_signature=self._output_signature,
        )
        ds = ds.prefetch(tf.data.AUTOTUNE)
        return ds