where is the dataset cardinality (size in terms of number of samples) and drop_last corresponds to the PyTorch DataLoader initialisation argument that determines if the final samples are discarded (True) or retained (False) if they are insufficient to populate a whole batch.

  • Note the term represents the number of iterations per epoch
def compute_iterations_per_epoch(dataset_size: int, batch_size: int, drop_last: bool) -> int:
    return dataset_size // batch_size if drop_last else -(-dataset_size // batch_size)
 
 
def compute_n_epochs(iterations: int, dataset_size: int, batch_size: int, drop_last: bool) -> int:
    iterations_per_epoch = compute_iterations_per_epoch(dataset_size, batch_size, drop_last)
    return -(-iterations // iterations_per_epoch)