forked from FeiX-OvO/NPH_Segmentation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
82 lines (50 loc) · 2.04 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
import os
import argparse
import subprocess
from TestFunc import *
from CSFseg import *
def imageList(dataPath):
fileName=[]
fileList=[]
# if os.path.isfile(dataPath) and '.nii' in dataPath:
# fileList+=[dataPath]
# temp=dataPath
# if '/' in temp: temp=temp.split('/')[-1]
# fileName+=[temp.split('.nii')[0]]
# print(fileName)
if os.path.isdir(dataPath):
fileList+=[d for d in os.listdir(dataPath) if '.nii' in d]
for temp in fileList:
fileName+=[temp.split('.nii')[0]]
else:
raise ValueError('Invalid data path input')
return fileList, fileName
#skull strip
def skull_strip(inName, outName):
subprocess.call(['bash', 'skull_strip.sh', inName, outName])
print('done')
#run test
if __name__== "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--modelPath', default='model_backup/epoch49_ResNet2D3Class_2Layer2x2_mixed2_300.pt')
parser.add_argument('--outputPath', default='reconstructed')
parser.add_argument('--dataPath', default='data-split/Scans')
parser.add_argument('--betPath', default='data-split/skull-strip')
parser.add_argument('--device', default='cpu')
parser.add_argument('--batch_size', default=200)
args = parser.parse_args()
dataPath=args.dataPath
modelPath=args.modelPath
outputPath=args.outputPath
betPath=args.betPath
device=args.device
BS=args.batch_size
fileList, fileName=imageList(dataPath)
for i in range(1):
# skull_strip(os.path.join(dataPath, fileList[i]), os.path.join(betPath, fileName[i]))
resultName=runTest(fileName[i], modelPath,outputPath, dataPath, betPath, device, BS)
maxArea, maxPos=segVent(fileName[i], outputPath, resultName)
with open('CSFmax.txt',"a+") as file:
file.write('{},{},{}\n'.format(fileName[i], maxPos, maxArea))
# print(fileName)