-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTrain_Skin_Lesion_Segmentation.py
67 lines (50 loc) · 1.91 KB
/
Train_Skin_Lesion_Segmentation.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
# -*- 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"] = "9"
import models as M
import numpy as np
from keras.callbacks import ModelCheckpoint, TensorBoard,ReduceLROnPlateau
from keras import callbacks
import pickle
# ===== normalize over the dataset
def dataset_normalized(imgs):
imgs_normalized = np.empty(imgs.shape)
imgs_std = np.std(imgs)
imgs_mean = np.mean(imgs)
imgs_normalized = (imgs-imgs_mean)/imgs_std
for i in range(imgs.shape[0]):
imgs_normalized[i] = ((imgs_normalized[i] - np.min(imgs_normalized[i])) / (np.max(imgs_normalized[i])-np.min(imgs_normalized[i])))*255
return imgs_normalized
#################################### Load Data #####################################
base_add = '../'
tr_data = np.load(base_add+'data_train.npy')
val_data = np.load(base_add+'data_val.npy')
tr_mask = np.load(base_add+'mask_train.npy')
val_mask = np.load(base_add+'mask_val.npy')
tr_mask = np.expand_dims(tr_mask, axis=3)
val_mask = np.expand_dims(val_mask, axis=3)
print('ISIC18 Dataset loaded')
tr_data = dataset_normalized(tr_data)
val_data = dataset_normalized(val_data)
tr_mask = tr_mask /255.
val_mask = val_mask /255.
print('dataset Normalized')
# Build model
model = M.Deeplabv3pa(input_shape = (256, 256, 3))
model.summary()
print('Training')
batch_size = 7
nb_epoch = 100
mcp_save = ModelCheckpoint('weight_isic18_deeplab_v3pa', 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_data=(val_data, val_mask), callbacks=[mcp_save, reduce_lr_loss] )