From 5893d4483e1e9647f1583714d844984af4a497d1 Mon Sep 17 00:00:00 2001 From: Johnny Date: Mon, 11 Mar 2024 12:02:23 +0100 Subject: [PATCH] Update `fraction` arg to employ a random selection (#8234) Co-authored-by: Glenn Jocher --- ultralytics/data/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ultralytics/data/base.py b/ultralytics/data/base.py index ddfce6ee..6af8d3cc 100644 --- a/ultralytics/data/base.py +++ b/ultralytics/data/base.py @@ -120,7 +120,9 @@ class BaseDataset(Dataset): except Exception as e: raise FileNotFoundError(f"{self.prefix}Error loading data from {img_path}\n{HELP_URL}") from e if self.fraction < 1: - im_files = im_files[: round(len(im_files) * self.fraction)] + # im_files = im_files[: round(len(im_files) * self.fraction)] + num_elements_to_select = round(len(im_files) * self.fraction) + im_files = random.sample(im_files, num_elements_to_select) return im_files def update_labels(self, include_class: Optional[list]):