Ejemplo n.º 1
0
def my_loss3(y_true, y_pred):
    MSE_loss = K.mean(K.square(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))
    #distortion loss calculated using iou
    #resnet_loss = K.mean(K.abs(y_pred[:, :, :, 3:19] - y_pred[:, :, :, 19:35]))
    edge_map1 = tf.image.sobel_edges(y_pred[:, :, :, :3])
    edge_map2 = tf.image.sobel_edges(y_true)
    ssim1 = K.mean(
        tf.image.ssim(edge_map1,
                      edge_map2,
                      max_val=255,
                      filter_size=3,
                      filter_sigma=1.5,
                      k1=0.01,
                      k2=0.03))
    dist_loss = 1 - ssim1 + K.mean(
        K.square(edge_map1 - edge_map2)) + 1 - tf.clip_by_norm(
            tf.image.psnr(y_pred[:, :, :, :3], y_true, max_val=1.0), 1)

    loss = 3 - SSIM_loss + MSE_loss + dist_loss
    return loss
Ejemplo n.º 2
0
def my_loss(y_true, y_pred):
    MAE_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))
    VGG_loss = K.mean(K.abs(y_pred[:, :, :, 3:19] - y_pred[:, :, :, 19:35]))

    percent = 0.4
    index = int(256 * 256 * percent - 1)
    gray1 = 0.39 * y_pred[:, :, :,
                          0] + 0.5 * y_pred[:, :, :,
                                            1] + 0.11 * y_pred[:, :, :, 2]
    gray = tf.reshape(gray1, [-1, 256 * 256])
    gray_sort = tf.nn.top_k(-gray, 256 * 256)[0]
    yu = gray_sort[:, index]
    yu = tf.expand_dims(tf.expand_dims(yu, -1), -1)
    mask = tf.to_float(gray1 <= yu)
    mask1 = tf.expand_dims(mask, -1)
    mask = tf.concat([mask1, mask1, mask1], -1)

    low_fake_clean = tf.multiply(mask, y_pred[:, :, :, :3])
    high_fake_clean = tf.multiply(1 - mask, y_pred[:, :, :, :3])
    low_clean = tf.multiply(mask, y_true[:, :, :, :])
    high_clean = tf.multiply(1 - mask, y_true[:, :, :, :])
    Region_loss = K.mean(
        K.abs(low_fake_clean - low_clean) * 4 +
        K.abs(high_fake_clean - high_clean))

    loss = MAE_loss + VGG_loss / 3. + 3 - SSIM_loss + Region_loss
    return loss
Ejemplo n.º 3
0
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