Exemplo n.º 1
0
def sigmas_coef(ctx, log_var0, log_var1):
    v0 = F.exp(log_var0)
    v1 = F.exp(log_var1)
    v0_g = F.greater_scalar(v0, 1.)
    v0_l = F.logical_not(v0_g)
    v1_g = F.greater_scalar(v1, 1.)
    v1_l = F.logical_not(v1_g)
    v0_g_and_v1_g = F.logical_and(v0_g, v1_g)
    v0_g_and_v1_l = F.logical_and(v0_g, v1_l)
    v0_l_and_v1_g = F.logical_and(v0_l, v1_g)
    v0_l_and_v1_l = F.logical_and(v0_l, v1_l)
    c = v0_g_and_v1_g \
        + v0_g_and_v1_l * v1 \
        + v0_l_and_v1_g / v0 \
        + v0_l_and_v1_l * v1 / v0
    return c
Exemplo n.º 2
0
def sigmas_coef(ctx, log_var0, log_var1):
    v0 = F.exp(log_var0)
    v1 = F.exp(log_var1)
    v0_g = F.greater_scalar(v0, 1.)
    v0_l = F.logical_not(v0_g)
    v1_g = F.greater_scalar(v1, 1.)
    v1_l = F.logical_not(v1_g)
    v0_g_and_v1_g = F.logical_and(v0_g, v1_g)
    v0_g_and_v1_l = F.logical_and(v0_g, v1_l)
    v0_l_and_v1_g = F.logical_and(v0_l, v1_g)
    v0_l_and_v1_l = F.logical_and(v0_l, v1_l)
    c = v0_g_and_v1_g \
        + v0_g_and_v1_l * v1 \
        + v0_l_and_v1_g / v0 \
        + v0_l_and_v1_l * v1 / v0
    return c
Exemplo n.º 3
0
def lab2rgb(input):
    input_trans = F.split(input, axis=1)
    L, a, b = F.split(input, axis=1)
    y = (L + 16.0) / 116.0
    x = (a / 500.0) + y
    z = y - (b / 200.0)
    neg_mask = F.less_scalar(z, 0).apply(need_grad=False)
    z = z * F.logical_not(neg_mask)
    mask_Y = F.greater_scalar(y, 0.2068966).apply(need_grad=False)
    mask_X = F.greater_scalar(x, 0.2068966).apply(need_grad=False)
    mask_Z = F.greater_scalar(z, 0.2068966).apply(need_grad=False)
    Y_1 = (y ** 3) * mask_Y
    Y_2 = L / (116. * 7.787) * F.logical_not(mask_Y)
    var_Y = Y_1 + Y_2

    X_1 = (x ** 3) * mask_X
    X_2 = (x - 16. / 116.) / 7.787 * F.logical_not(mask_X)
    var_X = X_1 + X_2

    Z_1 = (z ** 3) * mask_Z
    Z_2 = (z - 16. / 116.) / 7.787 * F.logical_not(mask_Z)
    var_Z = Z_1 + Z_2

    X = 0.95047 * var_X
    Y = 1.00000 * var_Y
    Z = 1.08883 * var_Z

    var_R = X * 3.2406 + Y * -1.5372 + Z * -0.4986
    var_G = X * -0.9689 + Y * 1.8758 + Z * 0.0415
    var_B = X * 0.0557 + Y * -0.2040 + Z * 1.0570

    mask_R = F.greater_scalar(var_R, 0.0031308).apply(need_grad=False)
    n_mask_R = F.logical_not(mask_R)
    R_1 = (1.055 * (F.maximum2(var_R, n_mask_R) ** (1 / 2.4)) - 0.055) * mask_R
    R_2 = (12.92 * var_R) * n_mask_R
    var_R = R_1 + R_2

    mask_G = F.greater_scalar(var_G, 0.0031308).apply(need_grad=False)
    n_mask_G = F.logical_not(mask_G)
    G_1 = (1.055 * (F.maximum2(var_G, n_mask_G) ** (1 / 2.4)) - 0.055) * mask_G
    G_2 = (12.92 * var_G) * n_mask_G
    var_G = G_1 + G_2

    mask_B = F.greater_scalar(var_B, 0.0031308).apply(need_grad=False)
    n_mask_B = F.logical_not(mask_B)
    B_1 = (1.055 * (F.maximum2(var_B, n_mask_B) ** (1 / 2.4)) - 0.055) * mask_B
    B_2 = (12.92 * var_B) * n_mask_B
    var_B = B_1 + B_2
    return F.stack(var_R, var_G, var_B, axis=1)
Exemplo n.º 4
0
def srwu_coef(ctx, log_var):
    v = F.exp(log_var)
    v0_g = F.greater_scalar(v, 1.)
    v0_l = F.logical_not(v0_g)
    c = v0_g + v * v0_l
    return c
Exemplo n.º 5
0
def srwu_coef(ctx, log_var):
    v = F.exp(log_var)
    v0_g = F.greater_scalar(v, 1.)
    v0_l = F.logical_not(v0_g)
    c = v0_g + v * v0_l
    return c