-
Notifications
You must be signed in to change notification settings - Fork 0
/
STEP2_Fit.py
72 lines (47 loc) · 1.36 KB
/
STEP2_Fit.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
# coding: utf-8
import sys
sys.path.insert(0, '/home/.conda/envs/tensorflow/lib/python3.6/site-packages')
import glob
import os
import keras
import matplotlib.pyplot
import numpy
import pandas
import pkg_resources
import tensorflow
import deepometry.model
import deepometry.utils
#--------#
drop = 6
model_directory = '/models/drop'+str(drop)
# build session running on GPU 1:
configuration = tensorflow.ConfigProto()
configuration.gpu_options.visible_device_list = "3"
#--------#
patients_to_test = ['157pres','157day8','157day15','171pres','171day11','172pres','172day29','175pres','175day8','177pres','177day8']
directories = ["/parsed_data/"]
xx, y, units = deepometry.utils.load(directories, patients_to_test, sample=True)
# Drop channels
x = xx[:,:,:,drop:]
del(xx)
print('Shape of x to be trained on: ', x.shape)
# apply session
configuration.gpu_options.allow_growth = True
session = tensorflow.Session(config = configuration)
keras.backend.set_session(session)
model = deepometry.model.Model(shape=x.shape[1:], units=units)
model.compile()
model.fit(
x,
y,
batch_size=32,
class_weight="auto",
epochs=512,
validation_split=0.3,
verbose=1
)
if not os.path.exists(model_directory):
os.makedirs(model_directory)
model.model.save( os.path.join(model_directory, 'resnet50_drop'+str(drop)+'.h5') )
del(x)
keras.backend.clear_session()