From 4bcb5cc41a4549fdc3ca594e27c721aee7d31d45 Mon Sep 17 00:00:00 2001 From: lijialin03 <124568209+lijialin03@users.noreply.github.com> Date: Tue, 30 May 2023 14:43:03 +0800 Subject: [PATCH] add assert of BatchSampler (#53778) --- python/paddle/io/dataloader/batch_sampler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/paddle/io/dataloader/batch_sampler.py b/python/paddle/io/dataloader/batch_sampler.py index 190e9240900..2f235f408d6 100644 --- a/python/paddle/io/dataloader/batch_sampler.py +++ b/python/paddle/io/dataloader/batch_sampler.py @@ -133,6 +133,11 @@ class BatchSampler(Sampler): ), "batch_size should be a positive integer, but got {}".format( batch_size ) + assert batch_size <= len( + self.sampler + ), "batch_size should not bigger than num of samples, but got {}".format( + batch_size + ) self.batch_size = batch_size assert isinstance( drop_last, bool -- GitLab