text stringlengths 0 93.6k |
|---|
def inverse_transform(images): |
return ((images+1.) / 2) * 255.0 |
def imsave(images, size, path): |
images = merge(images, size) |
images = cv2.cvtColor(images.astype('uint8'), cv2.COLOR_RGB2BGR) |
return cv2.imwrite(path, images) |
def merge(images, size): |
h, w = images.shape[1], images.shape[2] |
img = np.zeros((h * size[0], w * size[1], 3)) |
for idx, image in enumerate(images): |
i = idx % size[1] |
j = idx // size[1] |
img[h*j:h*(j+1), w*i:w*(i+1), :] = image |
return img |
def orthogonal_regularizer(scale) : |
""" Defining the Orthogonal regularizer and return the function at last to be used in Conv layer as kernel regularizer""" |
def ortho_reg(w) : |
""" Reshaping the matrxi in to 2D tensor for enforcing orthogonality""" |
_, _, _, c = w.get_shape().as_list() |
w = tf.reshape(w, [-1, c]) |
""" Declaring a Identity Tensor of appropriate size""" |
identity = tf.eye(c) |
""" Regularizer Wt*W - I """ |
w_transpose = tf.transpose(w) |
w_mul = tf.matmul(w_transpose, w) |
reg = tf.subtract(w_mul, identity) |
"""Calculating the Loss Obtained""" |
ortho_loss = tf.nn.l2_loss(reg) |
return scale * ortho_loss |
return ortho_reg |
def orthogonal_regularizer_fully(scale) : |
""" Defining the Orthogonal regularizer and return the function at last to be used in Fully Connected Layer """ |
def ortho_reg_fully(w) : |
""" Reshaping the matrix in to 2D tensor for enforcing orthogonality""" |
_, c = w.get_shape().as_list() |
"""Declaring a Identity Tensor of appropriate size""" |
identity = tf.eye(c) |
w_transpose = tf.transpose(w) |
w_mul = tf.matmul(w_transpose, w) |
reg = tf.subtract(w_mul, identity) |
""" Calculating the Loss """ |
ortho_loss = tf.nn.l2_loss(reg) |
return scale * ortho_loss |
return ortho_reg_fully |
def tf_rgb_to_gray(x) : |
x = (x + 1.0) * 0.5 |
x = tf.image.rgb_to_grayscale(x) |
x = (x * 2) - 1.0 |
return x |
def RGB2LAB(srgb): |
srgb = inverse_transform(srgb) |
lab = rgb_to_lab(srgb) |
l, a, b = preprocess_lab(lab) |
l = tf.expand_dims(l, axis=-1) |
a = tf.expand_dims(a, axis=-1) |
b = tf.expand_dims(b, axis=-1) |
x = tf.concat([l, a, b], axis=-1) |
return x |
def LAB2RGB(lab) : |
lab = inverse_transform(lab) |
rgb = lab_to_rgb(lab) |
rgb = tf.clip_by_value(rgb, 0, 1) |
# r, g, b = tf.unstack(rgb, axis=-1) |
# rgb = tf.concat([r,g,b], axis=-1) |
x = (rgb * 2) - 1.0 |
return x |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.