Skip to content

Instantly share code, notes, and snippets.

@rcgalbo
Created August 8, 2018 14:20
Show Gist options
  • Save rcgalbo/103a1fb3e5ecac7d47d99c6e13e7860a to your computer and use it in GitHub Desktop.
Save rcgalbo/103a1fb3e5ecac7d47d99c6e13e7860a to your computer and use it in GitHub Desktop.
move images into sub directories for keras ImageDataGenerator
import os
with open('../data/labels.csv','r') as labels:
lines = [line.split(',') for line in labels.readlines()][1:]
for line in lines:
image = line[0]
label = line[1].split('/')[-1].replace('\n','')
if not os.path.exists('../data/train/'+label):
os.mkdir('../data/train/'+label)
os.rename('../data/train/'+image+'.jpg', '../data/train/'+label+'/'+image+'.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment