labels = 2
if model_name == "fcn":
    model = fcn_8s(input_shape=(256, 256, 7),
                   num_classes=labels,
                   lr_init=lr_init,
                   lr_decay=lr_decay,
                   vgg_weight_path=vgg_path)
elif model_name == "unet":
    model = unet(input_shape=(256, 256, 7),
                 num_classes=labels,
                 lr_init=lr_init,
                 lr_decay=lr_decay,
                 vgg_weight_path=vgg_path)
elif model_name == "pspnet":
    model = pspnet50(input_shape=(256, 256, 7),
                     num_classes=labels,
                     lr_init=lr_init,
                     lr_decay=lr_decay)
elif model_name == "deeplabv3p":
    model = Deeplabv3(input_shape=(256, 256, 3), classes=labels)
elif model_name == "deeplabv3":
    model = deeplabv3_plus(input_shape=(256, 256, 7), num_classes=labels)
elif model_name == "maskrcnn":
    modelt = modellib.MaskRCNN(mode='training',
                               config=config,
                               model_dir=MODEL_DIR)
elif model_name == 'refinenet':
    model = refinenet(input_shape=(256, 256, 5), num_classes=lebels)
    #model =build_network_resnet101(inputHeight=256,inputWidth=256,n_classes=len(labels))
    #model = build_network_resnet101_stack(inputHeight=256,inputWidth=256,n_classes=len(labels),nStack=2)
elif model_name == "segnet":
    model = SegNet(input_shape=(256, 256, 5), classes=labels)
Ejemplo n.º 2
0
channels = 3


# Create model
print('Creating network...\n')
if model_name == "fcn":
    model = fcn_8s(input_shape=(img_height, img_width, channels), num_classes=nb_class,
                   lr_init=1e-3, lr_decay=5e-4, vgg_weight_path=vgg_path)
elif model_name == "unet":
    model = unet(input_shape=(img_height, img_width, channels), num_classes=nb_class,
                 lr_init=1e-3, lr_decay=5e-4, vgg_weight_path=vgg_path)
elif model_name == "fuzzyunet":
    model = fuzzy_unet(input_shape=(img_height, img_width, channels), num_classes=nb_class,
                 lr_init=1e-3, lr_decay=5e-4, vgg_weight_path=vgg_path)
elif model_name == "pspnet":
    model = pspnet50(input_shape=(img_height, img_width, channels), num_classes=nb_class, lr_init=1e-3, lr_decay=5e-4)

# load weights
try:
    model.load_weights(model_name + '_model_weight.h5')
except:
    print("You must train model and get weight before test.")

# Palette, used to show the result
palette = VOCPalette(nb_class=nb_class)
# print the testing image's name
print(img_path)
# read testing image
imgorg = Image.open(img_path)
# read label
imglab = Image.open(label_path)
Ejemplo n.º 3
0
# Choose model to train
if model_name == "fcn":
    model = fcn_8s(input_shape=(256, 512, 3),
                   num_classes=len(labels),
                   lr_init=lr_init,
                   lr_decay=lr_decay,
                   vgg_weight_path=vgg_path)
elif model_name == "unet":
    model = unet(input_shape=(256, 512, 3),
                 num_classes=len(labels),
                 lr_init=lr_init,
                 lr_decay=lr_decay,
                 vgg_weight_path=vgg_path)
elif model_name == "pspnet":
    model = pspnet50(input_shape=(256, 512, 3),
                     num_classes=len(labels),
                     lr_init=lr_init,
                     lr_decay=lr_decay)

# Define callbacks
checkpoint = ModelCheckpoint(filepath=model_name + '_model_weight.h5',
                             monitor='val_dice_coef',
                             save_best_only=True,
                             save_weights_only=True)
train_check = TrainCheck(output_path='./img', model_name=model_name)
#early_stopping = EarlyStopping(monitor='val_dice_coef', patience=10)

# training
history = model.fit_generator(data_generator('dataset_parser/data.h5',
                                             TRAIN_BATCH, 'train'),
                              steps_per_epoch=3475 // TRAIN_BATCH,
                              validation_data=data_generator(
Ejemplo n.º 4
0
elif model_name == "unet_gau":
    model = unet_gau(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_fpagau":
    model = unet_fpagau(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_att":
    model = unet_att(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_se":
    model = unet_se(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_se_gau":
    model = unet_se_gau(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_se_gau_fpa":
    model = unet_se_gau_fpa(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "unet_atts":
    model = unet_atts(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
elif model_name == "pspnet":
    model = pspnet50(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4)
try:
    model.load_weights('/media/ding/Study/First_next_term/lake segmentation project/Fifth/img/experiments/11/0.0001/unet_fpagau_model_weight.h5')
except:
    print("You must train model and get weight before test.")

x_img = cv2.imread(img_path)
cv2.imshow('x_img', x_img)
x_img = cv2.cvtColor(x_img, cv2.COLOR_BGR2RGB)
x_img = x_img / 127.5 - 1
x_img = np.expand_dims(x_img, 0)

pred = model.predict(x_img)
res = result_map_to_img(pred[0])
cv2.imwrite('./img/test.png',res)
# cv2.imshow('res', res)
Ejemplo n.º 5
0
img_path = args.img_path

labels = 2
if model_name == "fcn":
    model = fcn_8s(input_shape=(256, 256, 5),
                   num_classes=labels,
                   lr_init=1e-3,
                   lr_decay=5e-4)
elif model_name == "unet":
    model = unet(input_shape=(256, 256, 7),
                 num_classes=labels,
                 lr_init=1e-3,
                 lr_decay=5e-4)
elif model_name == "pspnet":
    model = pspnet50(input_shape=(256, 256, 5),
                     num_classes=labels,
                     lr_init=1e-3,
                     lr_decay=5e-4)
elif model_name == 'deeplabv3p':
    model = Deeplabv3(input_shape=(256, 256, 5), classes=labels)
elif model_name == "deeplabv3":
    model = deeplabv3_plus(input_shape=(256, 256, 5), num_classes=labels)
elif model_name == "segnet":
    model = SegNet(input_shape=(256, 256, 5), classes=labels)
elif model_name == "refinenet":
    model = refinenet(input_shape=(256, 256, 5), num_classes=labels)
model.load_weights("h5File/unet_model_weight.h5")

#model.load_weights("h5File/"+model_name+'_model_weight.h5')
print("load model successfully")

x_img = tifffile.imread("/data/test_h/15out.tif") / 255