Failed test case: incorrect number of (training, testing) images when using a split of 0.5 and 12 images (6 are zero-sized).
Expected:
(3, 3),
but got:
(6, 0).
Here is my code:
def split_data(SOURCE, TRAINING, TESTING, SPLIT_SIZE):
### START CODE HERE
# Shuffle list
shuffled_source = random.sample(os.listdir(SOURCE), len(os.listdir(SOURCE)))
# Find total number of files in training dir
training_number = int(len(shuffled_source) * SPLIT_SIZE)
i = 0
target = TRAINING
for item in shuffled_source:
item_source = os.path.join(SOURCE, item)
if os.path.getsize(item_source) == 0:
print(f'{item} is zero length, so ignoring.')
else:
copyfile(item_source, os.path.join(target, item))
i += 1
# Switch copy target to TESTING
if i == training_number:
target = TESTING
Don’t really understand what went wrong here, any help appreciated.