Last active
May 23, 2020 04:40
-
-
Save SrikarNamburu/8fa6768d9cce5a04e0237e3ca66e8904 to your computer and use it in GitHub Desktop.
Creates train.txt and test.txt files
This file contains 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
import os | |
import random | |
imgspath = 'images' #path to images | |
path = '/content/gdrive/My Drive/darknet/build/darknet/x64/data/obj/' | |
images = [] | |
for i in os.listdir(imgspath): | |
temp = path+i | |
images.append(temp) | |
# train and test split... adjust it if necessary | |
trainlen = round(len(images)*.80) | |
testlen = round(len(images)*.20) | |
#print('total, train, test dataset size -',trainlen+testlen,trainlen,testlen) | |
random.shuffle(images) | |
test = images[:testlen] | |
train = images[testlen:] | |
with open('train.txt', 'w') as f: | |
for item in train: | |
f.write("%s\n" % item) | |
with open('test.txt', 'w') as f: | |
for item in test: | |
f.write("%s\n" % item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment