-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
Issue
In the segmentation map, we have much less levee pixels, causing imbalanced learning. We may address this issue by class weight, but we are more interested in the geometrical similarity between predicted images and ground truth, which should create a clearer gradient.
Solution
Use distance between two matrices. Each matrix has shape (N, 2), where N is number of samples and 2-dimension contains the coordinates of pixels labelled as 1 (Useful reference). Actual implementation in tensorflow would be like this.
def pairwise_dist (A, B):
"""
Computes pairwise distances between each element of A and B.
Args:
A, [m,d] matrix
B, [n,d] matrix
Returns:
D, [m,n] matrix of pairwise distances
"""
with tf.variable_scope('pairwise_dist'):
# squared norms of each row in A and B
na = tf.reduce_sum(tf.square(A), 1)
nb = tf.reduce_sum(tf.square(B), 1)
# na as a row and nb as a co"lumn vectors
na = tf.reshape(na, [-1, 1])
nb = tf.reshape(nb, [1, -1])
# return pairwise euclidead difference matrix
D = tf.sqrt(tf.maximum(na - 2*tf.matmul(A, B, False, True) + nb, 0.0))
return DYou could use tf.where to extract the indices (=coordinates) of images.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request