Created
August 1, 2018 08:46
-
-
Save lharries/ba4b543dba30ae7bb7998e33ea58fd75 to your computer and use it in GitHub Desktop.
Divide folder of images into train and test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_train_test(categories, PATH, percent_test=0.2): | |
for category in categories: | |
print(len(os.listdir(PATH+category))) | |
files = os.listdir(PATH+category) | |
for file in files: | |
if np.random.rand(1) < percent_test: | |
shutil.copyfile(PATH + category +"/" + file, PATH + "test/" +category +"/" + file) | |
else: | |
shutil.copyfile(PATH + category +"/" + file, PATH + "train/"+ category +"/" + file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment