-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_lung.py
53 lines (41 loc) · 1.41 KB
/
train_lung.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
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 8 18:15:43 2019
@author: Reza Azad
"""
from __future__ import division
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import models as M
import numpy as np
from keras.callbacks import ModelCheckpoint, TensorBoard,ReduceLROnPlateau
from keras import callbacks
import pickle
#################################### Load Data #####################################
folder = './processed_data/'
tr_data = np.load(folder+'data_train.npy')
tr_mask = np.load(folder+'Train_maska.npy')
tr_data = np.expand_dims(tr_data, axis=3)
tr_mask = np.expand_dims(tr_mask, axis=3)
print('Dataset loaded')
tr_data = tr_data /255.
print('dataset Normalized')
print(type(tr_data))
# Build model
model = M.BCDU_net_D1(input_size = (512,512,1))
print('here')
model.summary()
print('Training')
batch_size = 2
nb_epoch = 50
mcp_save = ModelCheckpoint('weight_lung', save_best_only=True, monitor='val_loss', mode='min')
reduce_lr_loss = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=7, verbose=1, epsilon=1e-4, mode='min')
history = model.fit(tr_data,tr_mask,
batch_size=batch_size,
epochs=nb_epoch,
shuffle=True,
verbose=1,
validation_split=0.2, callbacks=[mcp_save, reduce_lr_loss] )
print('Trained model saved')
with open('hist_lung', 'wb') as file_pi:
pickle.dump(history.history, file_pi)