Skip to content

Instantly share code, notes, and snippets.

@devarshi16
Created November 26, 2019 08:28
Show Gist options
  • Save devarshi16/37a8283646b5aff1a6ec7a30730cd36d to your computer and use it in GitHub Desktop.
Save devarshi16/37a8283646b5aff1a6ec7a30730cd36d to your computer and use it in GitHub Desktop.
import os
import random as rand
import shutil
if not os.path.exists('val'):
os.makedirs('val')
if not os.path.exists('test'):
os.makedirs('test')
if not os.path.exists('true_test'):
os.makedirs('true_test')
# Name of folders in which files are present
folder_names =[
'cropped_cheque_reduced',
'cropped_created_reduced',
'cropped_nach_reduced',
'cropped_pan_and_aadhaar_reduced'
]
# Name of folders in which files are to be stored after split
split_names = ['val','test','true_test']
for folder in folder_names:
images = os.listdir(folder)
number_of_images = len(images)
for split in split_names:
for i in range(number_of_images/len(split_names)):
img = rand.choice(images)
images.remove(img)
source = folder+'/'+img
dest = split+'/'+img
print('copying from:'+source+'to'+dest)
shutil.copy(source,dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment