Skip to content

Instantly share code, notes, and snippets.

@NickShargan
Last active October 20, 2017 22:07
Show Gist options
  • Save NickShargan/eb84ab21993a64e4c7939e3b1d53b5c3 to your computer and use it in GitHub Desktop.
Save NickShargan/eb84ab21993a64e4c7939e3b1d53b5c3 to your computer and use it in GitHub Desktop.
import os
data_dir = "./data/"
train_dir = "./train/"
val_dir = "./val/"
breed_names = os.listdir(data_dir)
for breed_name in breed_names:
if not os.path.isdir(train_dir + breed_name):
os.mkdir(train_dir + breed_name)
if not os.path.isdir(val_dir + breed_name):
os.mkdir(val_dir + breed_name)
curr_breed_path = data_dir + breed_name + "/"
filenames = os.listdir(curr_breed_path)
for idx, filename in enumerate(filenames):
if idx < len(filenames) / 5:
cmd = "cp " + curr_breed_path + filename + " " + val_dir + breed_name + "/"
os.system(cmd)
else:
cmd = "cp " + curr_breed_path + filename + " " + train_dir + breed_name + "/"
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment