Update fraction arg to employ a random selection (#8234)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Johnny 2024-03-11 12:02:23 +01:00 committed by GitHub
parent 7451ca1f54
commit 5893d4483e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,7 +120,9 @@ class BaseDataset(Dataset):
except Exception as e: except Exception as e:
raise FileNotFoundError(f"{self.prefix}Error loading data from {img_path}\n{HELP_URL}") from e raise FileNotFoundError(f"{self.prefix}Error loading data from {img_path}\n{HELP_URL}") from e
if self.fraction < 1: 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 return im_files
def update_labels(self, include_class: Optional[list]): def update_labels(self, include_class: Optional[list]):