def get_enhanced_images(test_config, shadow_paths):
    # Default parameters for images
    img_rows = 256
    img_cols = 256
    img_channels = 3

    # Build Model
    model = test.build_test_model(test_config['model'],
                                  test_config['model_weight_path'])
    data_loader = Dataloader(dataset_name='shadow',
                             crop_shape=(img_rows, img_cols))

    save_folder = os.path.dirname(
        test_config['model_weight_path']) + "/enhanced_imgs"
    if not os.path.exists(save_folder):
        os.makedirs(save_folder)

    for i in range(len(shadow_paths)):
        img_path = shadow_paths[i]
        img = cv2.imread(img_path)
        if img is None:
            continue

        img = data_loader.transform_img(img, img_rows,
                                        img_cols)  # Convert to (0,1)
        img = img[np.newaxis, :]
        out_pred = model.predict(img, batch_size=1)
        output = out_pred[0].reshape(img_rows, img_cols, img_channels)
        result_img = post_process.rescale_to_image(output)

        spl = img_path.split("/")
        save_path = save_folder + "/" + spl[-5] + "_" + spl[-4] + "_" + spl[
            -3] + "_enhanced_" + spl[-1].split(".")[0].split("_")[1] + ".jpg"
        cv2.imwrite(save_path, result_img)
示例#2
0
def get_data_loader():
    #  Dataloader
    img_rows = 256
    img_cols = 256
    img_channels = 3
    image_path_name = 'segmentation'
    data_loader = Dataloader(dataset_name=image_path_name,
                             crop_shape=(img_rows, img_cols))
    return data_loader
示例#3
0
def f1(x):
    return x[:, :, :, :3]

def f2(x):
    return x[:, :, :, 3:]

def f3(x):
    return tf.reshape(x,[-1, 256, 256, 16])

img_rows = 256
img_cols = 256
img_channels = 3
crop_shape = (img_rows, img_cols, img_channels)
input_shape = (img_rows, img_cols, img_channels*2)
dataset_name = 'dark'
data_loader = Dataloader(dataset_name=dataset_name, crop_shape=(img_rows, img_cols))

# Build the network
mbllen = Network.build_mbllen(crop_shape)
# mbllen.load_weights('./1_dark2_color_identity_param.h5')

Input_MBLLEN = Input(shape=input_shape)
img_A = Lambda(f1)(Input_MBLLEN)
img_B = Lambda(f2)(Input_MBLLEN)

# VGG19 feature, content loss
vgg = Network.build_vgg()
vgg.trainable = False

fake_B = mbllen(img_A)
vgg_fake = Lambda(utls.range_scale)(fake_B)
示例#4
0
import os
import random
import Network
import utls
import cv2
import sys, os
sys.path.append(os.path.abspath(os.path.join('../', 'models/')))
import natsort
K.clear_session()

img_rows = 256
img_cols = 256
img_channels = 3
crop_shape = (img_rows, img_cols, img_channels)
input_shape = (img_rows, img_cols, img_channels)
data_loader = Dataloader(dataset_name=image_path,
                         crop_shape=(img_rows, img_cols))
resnet50 = Network.build_resnet50(crop_shape)
resnet50.trainable = False


def my_loss(y_true, y_pred):
    MSE_loss = K.mean(K.abs(y_pred[:, :, :, :3] - y_true))
    SSIM_loss = utls.tf_ssim(
        tf.expand_dims(y_pred[:, :, :, 0], -1),
        tf.expand_dims(y_true[:, :, :, 0], -1)) + utls.tf_ssim(
            tf.expand_dims(y_pred[:, :, :, 1], -1),
            tf.expand_dims(y_true[:, :, :, 1], -1)) + utls.tf_ssim(
                tf.expand_dims(y_pred[:, :, :, 2], -1),
                tf.expand_dims(y_true[:, :, :, 2], -1))
    #psnr=tf.clip_by_norm(tf.image.psnr(y_pred[:,:,:,:3], y_true,max_val=1.0),1)
    return 3 - SSIM_loss + 3 * MSE_loss