Hi, I am getting strange errors for split_data questsions: FileNotFoundError: [Errno 2] No such file or directory: '918.jpg'
Here is my code:
def split_data(SOURCE, TRAINING, TESTING, SPLIT_SIZE):
### START CODE HERE
images= os.listdir(SOURCE)
new_images = []
for i in range(len(images)):
size = os.path.getsize(images[i])
if size == 0 or size < 0:
print('filename is zero length, so ignoring.')
else:
new_images.append(images[i])
trn_images= random.sample(new_images, len(new_images)*SPLIT_SIZE)
copyfile(trn_images, TRAINING)
copyfile(images[~trn_images], TESTING)
The os.path.getsize() works with a path so it needs to be: op.path.getsize(SOURCE/“name of the image”). It is confusing the error said ‘No such file or directory’ because it’s actually asking for the exact path of the file.