default=None, help="Pretrained vgg16 weight path.") args = parser.parse_args() model_name = args.model TRAIN_BATCH = args.train_batch VAL_BATCH = args.val_batch lr_init = args.lr_init lr_decay = args.lr_decay vgg_path = args.vgg config = Config() 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)
# testing image's path img_path = './BUS/data2/wavelet/Case81.png' # label path label_path = './BUS/data2/GT/Case81.png' # input size img_width = 128 img_height = 128 nb_class = 2 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.")
argmax_idx = np.argmax(res_map, axis=2) # For np.where calculation. lake = (argmax_idx == 1) img[:, :, 0] = np.where(lake, 255, 0) return img model_name = 'fcn' img_path = './img/test-512.tif' # Use only 2 classes. labels = ['lake','_background_'] # Choose model to train if model_name == "fcn": model = fcn_8s(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4) elif model_name == "unet": model = unet(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4) elif model_name == "unet_fpa": model = unet_fpa(input_shape=(512, 512, 3), num_classes=len(labels), lr_init=1e-3, lr_decay=5e-4) 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":
import cv2 import numpy as np from keras import backend as K from model.unet import unet from model.fcn import fcn_8s # Use only 3 classes. labels = ['background', 'person', 'car', 'road'] model = fcn_8s(input_shape=(256, 512, 3), num_classes=len(labels), init_lr=5e-3) model.load_weights('./model_weight.h5') def result_map_to_img(res_map): img = np.zeros((256, 512, 3), dtype=np.uint8) res_map = np.squeeze(res_map) argmax_idx = np.argmax(res_map, axis=2) # For np.where calculation. person = (argmax_idx == 1) car = (argmax_idx == 2) road = (argmax_idx == 3) img[:, :, 0] = np.where(person, 255, 0) img[:, :, 1] = np.where(car, 255, 0) img[:, :, 2] = np.where(road, 255, 0)
args = parser.parse_args() model_name = args.model TRAIN_BATCH = args.train_batch VAL_BATCH = args.val_batch lr_init = args.lr_init lr_decay = args.lr_decay vgg_path = args.vgg # Use only 3 classes. labels = ['background', 'person', 'car', 'road'] # 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
'segnet' ], help="Model to test. 'fcn', 'unet', 'pspnet' is available.") parser.add_argument("-P", "--img_path", required=True, help="The image path you want to test") args = parser.parse_args() model_name = args.model 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)