Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Dec 22, 2020
Embed
What would you like to do?
source = 'training_images'
if True:
for fold in [0]:
val_index = index[len(index)*fold//5:len(index)*(fold+1)//5]
for name,mini in tqdm(df.groupby('image_id')):
if name in val_index:
path2save = 'val2017/'
else:
path2save = 'train2017/'
if not os.path.exists('/tmp/convertor/fold{}/labels/'.format(fold)+path2save):
os.makedirs('/tmp/convertor/fold{}/labels/'.format(fold)+path2save)
with open('/tmp/convertor/fold{}/labels/'.format(fold)+path2save+name+".txt", 'w+') as f:
row = mini[['classes','x_center','y_center','w','h']].astype(float).values
row = row.astype(str)
for j in range(len(row)):
text = ' '.join(row[j])
f.write(text)
f.write("\n")
if not os.path.exists('/tmp/convertor/fold{}/images/{}'.format(fold,path2save)):
os.makedirs('/tmp/convertor/fold{}/images/{}'.format(fold,path2save))
sh.copy("../input/car-object-detection/data/{}/{}.jpg".format(source,name),'/tmp/convertor/fold{}/images/{}/{}.jpg'.format(fold,path2save,name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment