forked from arishin/ChangeNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrainValTxtMaker.py
50 lines (40 loc) · 1.21 KB
/
TrainValTxtMaker.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
46
47
48
49
50
import os
from pathlib import Path
import random
import glob
train_file_list = './trainCD.txt'
val_file_list = './valCD.txt'
test_file_list = './testCD.txt'
"""
## Train Val txt
rootdir = Path('/home/lorant/Projects/data/Change3D/Change3D_dyn/')
with open(train_file_list, 'w') as tr, open(val_file_list, 'w') as vl:
#images = os.listdir(rootdir)
images = glob.glob(str(rootdir)+'/*.png')
images.sort()
print(len(images))
for gtimname in images:
if random.random()<0.8:
f=tr
else:
f=vl
savedirpath = Path(rootdir.parent.stem)/rootdir.stem
a=str(savedirpath/gtimname)
f.write(a+"\n")
print('Train Val done!')
"""
## Test txt
def createTxt(rootdir):
#images = os.listdir(rootdir)
images = glob.glob(str(rootdir)+'/*.png')
images.sort()
print(len(images))
with open(test_file_list, 'w') as tst:
for gtimname in images:
f=tst
savedirpath = Path(rootdir.parent.stem)/rootdir.stem
a=str(savedirpath/gtimname)
f.write(a+"\n")
print('Test done!')
#rootdir = Path('/home/lorant/Projects/data/Change3D/Change3D_stat_4class_cut_final/imgs_multi_dyn/')
#createTxt(rootdir)