Example #1
0
def main():
    batch_size = int(sys.argv[2])
    epochs = int(sys.argv[3])

    x_train = np.load(getData.x_train_path).astype('float32')
    y_train = np.load(getData.y_train_path).astype('float32')

    # 0~1归一化
    x_train /= 255

    # -1~1归一化
    # x_train = x_train/127.5-1

    # rgb-mean归一化
    # r_mean_value = np.mean(x_train[:, :, :, 0])
    # g_mean_value = np.mean(x_train[:, :, :, 1])
    # b_mean_value = np.mean(x_train[:, :, :, 2])
    # x_train[:, :, :, 0] = x_train[:, :, :, 0] - r_mean_value
    # x_train[:, :, :, 1] = x_train[:, :, :, 1] - g_mean_value
    # x_train[:, :, :, 2] = x_train[:, :, :, 2] - b_mean_value

    nowTime = datetime.datetime.now().strftime('%m%d_%H_%M')

    if sys.argv[1] == "-unet":
        print("model_name : {}".format("unet"))
        model = Unet.getModel()
        model_temp_name = "unet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "unet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-fuzzyunet":
        print("model_name : {}".format("fuzzyunet"))
        model = FuzzyUnet.getModel()
        model_temp_name = "fuzzy_unet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "fuzzy_unet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-softmaxunet":
        print("model_name : {}".format("softmaxunet"))
        model = UnetSoftmax.getModel()
        model_temp_name = "softmax_unet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "softmax_unet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-resunet":
        print("model_name : {}".format("resunet"))
        model = ResUnet.getModel()
        model_temp_name = "res_unet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "res_unet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-attunet":
        print("model_name : {}".format("attunet"))
        model = AttUnet.AttU_Net(
            (getData.height, getData.width,
             getData.n_channel)).create(getData.n_class, 1e-4, 5e-4, 2)
        model_temp_name = "attunet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "attunet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-r2unet":
        print("model_name : {}".format("r2unet"))
        model = AttUnet.R2U_Net(
            (getData.height, getData.width,
             getData.n_channel)).create(getData.n_class, 1e-4, 5e-4, 2)
        model_temp_name = "r2unet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "r2unet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    elif sys.argv[1] == "-r2attunet":
        print("model_name : {}".format("r2attunet"))
        model = AttUnet.R2AttU_Net(
            (getData.height, getData.width,
             getData.n_channel)).create(getData.n_class, 1e-4, 5e-4, 2)
        model_temp_name = "r2attunet_temp_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        model_name = "r2attunet_batchsize_{}_epochs_{}_{}.h5".format(
            batch_size, epochs, nowTime)
        run(model, batch_size, epochs, model_temp_name, model_name, x_train,
            y_train)

    else:
        print("输入错误,重新输入")
Example #2
0
x_train = train_data.astype('float32') / 255.
y_train = train_label.astype('float32') / 255.
x_train = np.reshape(x_train, (len(x_train), 512, 512, 3))  # adapt this if using `channels_first` image data format
y_train = np.reshape(y_train, (len(y_train), 512, 512, 1))  # adapt this if using `channels_first` im

x_test = test_data.astype('float32') / 255.
y_test = test_label.astype('float32') / 255.
x_test = np.reshape(x_test, (len(x_test), 512, 512, 3))  # adapt this if using `channels_first` image data format
y_test = np.reshape(y_test, (len(y_test), 512, 512, 1))  # adapt this if using `channels_first` im

TensorBoard(log_dir='./autoencoder', histogram_freq=0,
            write_graph=True, write_images=True)

from  ResUnet import *
model=ResUnet(input_size=(512,512,3),start_neurons=16,keep_prob=0.9,block_size=7)
weight="Model/Luna/ResUnet.h5"
restore=False
if restore and os.path.isfile(weight):
    model.load_weights(weight)

model_checkpoint = ModelCheckpoint(weight, monitor='val_acc', verbose=1, save_best_only=True)

model.fit(x_train, y_train,
                epochs=300,
                batch_size=4,
                validation_split=0.12,
                # validation_data=(x_test, y_test),
                shuffle=True,
                callbacks= [TensorBoard(log_dir='./autoencoder'), model_checkpoint]
          )
Example #3
0
import os
import numpy as np
import cv2
from keras.callbacks import TensorBoard, ModelCheckpoint
from keras.utils.vis_utils import model_to_dot
from keras.utils import plot_model
np.random.seed(42)
import scipy.misc as mc
data_location = ''
training_images_loc = data_location + 'Chase/train/image/'
training_label_loc = data_location + 'Chase/train/label/'
testing_images_loc = data_location + 'Chase/test/image/'
testing_label_loc = data_location + 'Chase/test/label/'
train_files = os.listdir(training_images_loc)
train_data = []
train_label = []
desired_size = 1024
for i in train_files:
    im = mc.imread(training_images_loc + i)
    label = mc.imread(training_label_loc + "Image_" +
                      i.split('_')[1].split(".")[0] + "_1stHO.png")
    old_size = im.shape[:2]  # old_size is in (height, width) format
    delta_w = desired_size - old_size[1]
    delta_h = desired_size - old_size[0]
    top, bottom = delta_h // 2, delta_h - (delta_h // 2)
    left, right = delta_w // 2, delta_w - (delta_w // 2)
    color = [0, 0, 0]
    color2 = [0]
    new_im = cv2.copyMakeBorder(im,
                                top,
Example #4
0
test_data = np.array(test_data)
test_label = np.array(test_label)

x_test = test_data.astype('float32') / 255.

y_test = test_label.astype('float32') / 255.
x_test = np.reshape(
    x_test, (len(x_test), 512, 512,
             3))  # adapt this if using `channels_first` image data format
y_test = np.reshape(
    y_test,
    (len(y_test), 512, 512, 1))  # adapt this if using `channels_first` im

from ResUnet import *
model = ResUnet(input_size=(512, 512, 3),
                start_neurons=16,
                keep_prob=1,
                block_size=1)
weight = "Model/Luna/ResUnet.h5"

if os.path.isfile(weight): model.load_weights(weight)

model_checkpoint = ModelCheckpoint(weight,
                                   monitor='val_acc',
                                   verbose=1,
                                   save_best_only=True)

y_pred = model.predict(x_test)
y_pred_threshold = []
i = 0
for y in y_pred:
Example #5
0
import os
import cv2
import numpy as np
from sklearn.metrics import recall_score, roc_auc_score, accuracy_score, confusion_matrix
from keras.callbacks import ModelCheckpoint
from util import *
import scipy.misc as mc
import math
data_location = ''
testing_images_loc = data_location + 'Drive/test/images/'
testing_label_loc = data_location + 'Drive/test/label/'
test_files = os.listdir(testing_images_loc)
test_data = []
test_label = []
desired_size = 592
for i in test_files:
    im = mc.imread(testing_images_loc + i)
    label = mc.imread(testing_label_loc + i.split('_')[0] + '_manual1.png')
    old_size = im.shape[:2]  # old_size is in (height, width) format
    delta_w = desired_size - old_size[1]
    delta_h = desired_size - old_size[0]
    top, bottom = delta_h // 2, delta_h - (delta_h // 2)
    left, right = delta_w // 2, delta_w - (delta_w // 2)
    color = [0, 0, 0]
    color2 = [0]
    new_im = cv2.copyMakeBorder(im,
                                top,
                                bottom,
                                left,
                                right,