Skip to content

Instantly share code, notes, and snippets.

@Timopheym
Last active November 9, 2017 00:25
Show Gist options
  • Save Timopheym/0f4c17d8bb8e9a5460ecdb2fd026df03 to your computer and use it in GitHub Desktop.
Save Timopheym/0f4c17d8bb8e9a5460ecdb2fd026df03 to your computer and use it in GitHub Desktop.
kaggle2fastai dataset conventer
import pandas as pd
import os
from shutil import copyfile,move
labels = pd.read_csv('data/dogbreed/labels.csv')
classes = list(labels['breed'].unique())
source_path = 'data/dogbreed/old_train/'
path = 'data/dogbreed/train/'
valid_path = 'data/dogbreed/valid/'
for index, row in labels.iterrows():
dst = path + row['breed'] + "/"
fname = row['id'] + '.jpg'
if not os.path.exists(dst):
os.makedirs(dst)
copyfile(source_path + fname, dst + fname)
for cls in classes:
parent_list = os.listdir(path + cls)
count =0
dst = valid_path + cls + "/"
if not os.path.exists(dst):
os.makedirs(dst)
for child in parent_list:
if count < 20:
move(path + cls + "/" + child, dst + child)
else:
break
count = count+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment