Skip to content

Commit a228f3c

Browse files
committed
fix making train val folders if not existent
1 parent 8b3360e commit a228f3c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

SwissKnife/dataprep.py

+20
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ def prepareData(
161161
# annotations = annotations[:20]
162162
# TODO: make one/cv_fold
163163
if cv_folds == 0:
164+
165+
if not os.path.exists(os.path.join(frames_path, "train")):
166+
# get all frames from folder
167+
frames = glob(frames_path + "/*.png")
168+
# number of frames
169+
num_imgs = len(frames)
170+
# split into train and val (0.8/0.2) randomly
171+
num_train_imgs = int(num_imgs * 0.8)
172+
train_frames = random.sample(frames, num_train_imgs)
173+
val_frames = list(set(frames) - set(train_frames))
174+
175+
# make train and val folders
176+
os.makedirs(os.path.join(frames_path, "train"), exist_ok=True)
177+
os.makedirs(os.path.join(frames_path, "val"), exist_ok=True)
178+
# move frames to folders
179+
for frame in train_frames:
180+
os.rename(frame, os.path.join(frames_path, "train", frame.split("/")[-1]))
181+
for frame in val_frames:
182+
os.rename(frame, os.path.join(frames_path, "val", frame.split("/")[-1]))
183+
164184
#
165185
# Training dataset
166186
dataset_train = Dataset(species)

0 commit comments

Comments
 (0)