The repeat() function in tensorflow datasets is not necessary when steps_per_epochs is not specified

Viewed 75

I'm new on tensorflow datasets, and trying to understand why the repeat() function is not necessary in the code below

    AUTOTUNE = tf.data.experimental.AUTOTUNE
    BATCH_SIZE = 64

    ds_train = ds_train.map(normalize_img, num_parallel_calls=AUTOTUNE)
    ds_train = ds_train.cache()
    ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples)
    # ds_train = ds_train.repeat()
    ds_train = ds_train.batch(BATCH_SIZE)
    ds_train = ds_train.prefetch(AUTOTUNE)

    model.compile(
        loss=tf.keras.losses.SparseCategoricalCrossentropy(),
        optimizer=tf.keras.optimizers.Adam(lr=1e-3),
        metrics=['accuracy'],

    )

    model.fit(
        ds_train,
        epochs=10,
        verbose=2
    )

If I add steps_per_epoch as an argument of the fit() function, then I need to specify ds_train = ds_train.repeat().

Thanks!

0 Answers
Related