forked from inayatkh/ucwinRoadCaffeMobileNet-SSDdetections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_createtrainvaldata.py
45 lines (30 loc) · 1.26 KB
/
02_createtrainvaldata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from PIL import Image
import os
import string
from os.path import basename
import configparser
def createTrainvalTxt(baseDirDataSet):
buffer = ''
baseDir = baseDirDataSet+'/images'
for filename in os.listdir(baseDir):
# print (file_extension)
filenameOnly = os.path.splitext(filename)[0]
s = 'images/'+filename+' '+'labels/'+filenameOnly+'.xml\n'
print (repr(s))
img_file, anno = s.strip("\n").split(" ")
#print(repr(img_file), repr(anno))
buffer+=s
with open(baseDirDataSet+'/structure/trainval.txt', 'w') as file:
file.write(buffer)
print("{} is created successfully".format(baseDirDataSet+'/structure/trainval.txt'))
with open(baseDirDataSet+'/structure/test.txt', 'w') as file:
file.write(buffer)
print("{} is created successfully".format(baseDirDataSet+'/structure/test.txt'))
if __name__ == '__main__':
# Load paths and dataset names from config.ini file
config = configparser.ConfigParser()
config.read('settings-config.ini')
dataset_name = config['DEFAULT']['dataset_name']
data_root_dir = config['DEFAULT']['data_root_dir']
dataset_root_dir = "{}/{}".format(data_root_dir, dataset_name)
createTrainvalTxt(dataset_root_dir)