[Python] Order of batch, prefetch, shuffle and cache in a Tensorflow dataset

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    When creating a dataset from a generator, what would be the correct order of the following dataset methods? Or does the order not matter here?

    ds = tf.data.Dataset.from_generator(my_generator)
    ds = ds.prefetch(tf.data.AUTOTUNE).shuffle(1000).batch(128).cache()


    Here I use prefetch to speed up data generation and cache to avoid calculating after every epoch.

    Continue reading...

Compartilhe esta Página