forked from UCRajkumar/ecSeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecSeg.py
47 lines (42 loc) · 1.29 KB
/
ecSeg.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
#!/usr/bin/env python3
#Author: Utkrisht Rajkumar
#Email: [email protected]
#Loads in trained model and produces segmentation maps of images in folder
import os
from predict import predict
from keras.models import Model, load_model
import sys, getopt
from keras import backend as K
if sys.version_info[0] < 3:
raise Exception("Must run with Python version 3 or higher")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def main(argv):
inputfile = './'
try:
opts, args = getopt.getopt(argv,"i:")
except getopt.GetoptError:
print('ecSeg.py -i <input path>')
sys.exit(2)
for opt, arg in opts:
if opt in ("-i"):
inputfile = arg
#create folders
if(os.path.exists((inputfile+'/coordinates'))):
pass
else:
os.mkdir((inputfile+'/coordinates'))
if(os.path.exists((inputfile+'/labels'))):
pass
else:
os.mkdir((inputfile+'/labels'))
print("Loading in trained model...")
model = load_model('ecDNA_model.h5') #load model
for f in os.listdir(inputfile): #get all images in path
ext = os.path.splitext(f)[1]
if ext.lower() == '.tif':
print('Segmenting',f)
predict(model, inputfile, (f))
print("Successfully exited...")
K.clear_session()
if __name__ == "__main__":
main(sys.argv[1:])