Skip to content

Commit

Permalink
shuffle dataset at the beginning
Browse files Browse the repository at this point in the history
Former-commit-id: 6a5770419d9e87823190b234062f6debc068d27c
  • Loading branch information
Javier Ribera committed Oct 19, 2018
1 parent 8c687dd commit 8d6c015
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions object-locator/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def __init__(self,
listfiles = [f for f in listfiles
if any(f.lower().endswith(ext) for ext in IMG_EXTENSIONS)]

# Shuffle list of files
random.shuffle(listfiles)

if len(listfiles) == 0:
raise ValueError(f"There are no images in '{directory}'")

Expand All @@ -73,13 +76,16 @@ def __init__(self,
self.listfiles = listfiles

# Make dataset smaller
self.listfiles = self.listfiles[0:min(
len(self.listfiles), max_dataset_size)]
self.listfiles = self.listfiles[0:min(len(self.listfiles),
max_dataset_size)]

# CSV does exist (GT is available)
else:
self.csv_df = pd.read_csv(os.path.join(directory, csv_filename))

# Shuffle CSV dataframe
self.csv_df = self.csv_df.sample(frac=1).reset_index(drop=True)

# Make dataset smaller
self.csv_df = self.csv_df[0:min(
len(self.csv_df), max_dataset_size)]
Expand All @@ -96,7 +102,7 @@ def __getitem__(self, idx):
The second element is a dictionary where the keys are the columns of the CSV.
If the CSV did not exist in the dataset directory,
the dictionary will only contain the filename of the image.
_
:param idx: Index of the image in the dataset to get.
"""

Expand Down Expand Up @@ -333,6 +339,9 @@ def __init__(self,
listfiles = [f for f in listfiles
if any(f.lower().endswith(ext) for ext in IMG_EXTENSIONS)]

# Shuffle list of files
random.shuffle(listfiles)

if len(listfiles) == 0:
raise ValueError(f"There are no images in '{directory}'")

Expand Down

0 comments on commit 8d6c015

Please sign in to comment.