Skip to content

Instantly share code, notes, and snippets.

@Sachin-crypto
Created December 16, 2022 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sachin-crypto/14ff4f35172f98fedc8e0b7455c57fb1 to your computer and use it in GitHub Desktop.
Save Sachin-crypto/14ff4f35172f98fedc8e0b7455c57fb1 to your computer and use it in GitHub Desktop.
# Creating dirs train, valid and test and organize data into them
os.chdir('D:\SACHIN\Jupyter\Hand Sign Language\Hand_Sign_Language_DL_Project\American-Sign-Language-Digits-Dataset')
# If dir doesn't exist then make specified dirs
if os.path.isdir('train/0/') is False:
os.mkdir('train')
os.mkdir('valid')
os.mkdir('test')
for i in range(0, 10):
# Moving 0-9 dirs into train dir
shutil.move(f'{i}', 'train')
os.mkdir(f'valid/{i}')
os.mkdir(f'test/{i}')
# Take 90 sample imgs for valid dir
valid_samples = random.sample(os.listdir(f'train/{i}'), 90)
for j in valid_samples:
# Moving the sample imgs from train dir to valid sub-dirs
shutil.move(f'train/{i}/{j}', f'valid/{i}')
# Take 10 sample imgs for test dir
test_samples = random.sample(os.listdir(f'train/{i}'), 10)
for k in test_samples:
# Moving the sample imgs from train dir to test sub-dirs
shutil.move(f'train/{i}/{k}', f'test/{i}')
os.chdir('../..')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment