forked from Nightmare4214/CTPelvic1K
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.py
57 lines (51 loc) · 1.83 KB
/
test3.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
51
52
53
54
55
56
57
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import os
import pickle
import shutil
def load_pickle(file: str, mode: str = 'rb'):
with open(file, mode) as f:
a = pickle.load(f)
return a
def check():
pre_data_path = '/data/datasets/CTPelvic1K/pre_data'
files = os.listdir(pre_data_path)
files.sort()
splits_final = load_pickle('splits_final.pkl')
for i in range(1, 7):
if 2 == i:
continue
for prefix in ['train', 'val', 'test']:
for path in splits_final[i][prefix]:
path = path.replace('train_', '', 1)
flag = False
for file in files:
if file.startswith(path):
flag = True
break
if not flag:
print(path)
if __name__ == '__main__':
fold_path = '/data/datasets/CTPelvic1K/folds'
splits_final = load_pickle('splits_final.pkl')
pre_data_path = '/data/datasets/CTPelvic1K/pre_data'
files = os.listdir(pre_data_path)
files.sort()
for i in range(1, 7):
if 2 == i:
continue
fold = os.path.join(fold_path, 'fold{}'.format(i))
os.makedirs(fold, exist_ok=True)
for prefix in ['train', 'val', 'test']:
cur_path = os.path.join(fold, prefix)
os.makedirs(cur_path, exist_ok=True)
for path in splits_final[i][prefix]:
path = path.replace('train_', '', 1)
targets = []
for file in files:
if file.startswith(path):
targets.append(file)
if len(targets) == 2:
break
for target in targets:
shutil.copyfile(os.path.join(pre_data_path, target), os.path.join(cur_path, target))