I passed the assignment, but I got the following message for my split_data function:
Failed test case: incorrect number of (training, validation) images when using a split of 0.5 and 12 images (6 are zero-sized).
Expected:
(3, 3),
but got:
(4, 5).
I don’t understand why my function would not work for this case. Below are my code for the function:
def split_data(SOURCE_DIR, TRAINING_DIR, VALIDATION_DIR, SPLIT_SIZE):
file_list = os.listdir(SOURCE_DIR)
for file in file_list:
path = os.path.join(SOURCE_DIR, file)
if os.path.getsize(path) == 0:
print(f'{file} is zero length, so ignoring.')
file_list.remove(file)
file_list = random.sample(file_list, len(file_list))
target = int(len(file_list)*SPLIT_SIZE)
for train_file in file_list[0:target]:
copyfile(os.path.join(SOURCE_DIR, train_file), os.path.join(TRAINING_DIR, train_file))
for val_file in file_list[target :len(file_list)]:
copyfile(os.path.join(SOURCE_DIR, val_file), os.path.join(VALIDATION_DIR, val_file))
Thanks!