Contrastive-Adaptation-Network-for-Unsupervised-Domain-Adaptation icon indicating copy to clipboard operation
Contrastive-Adaptation-Network-for-Unsupervised-Domain-Adaptation copied to clipboard

Features normalization computing centers

Open joppichristian opened this issue 4 years ago • 4 comments

Thank you for sharing code!

I have a question about the function get_centers that computes the centers of clusters. Did you forget to normalize features before multiply them per mask? Or simply the normalization is in the net forward?

https://github.com/kgl-prml/Contrastive-Adaptation-Network-for-Unsupervised-Domain-Adaptation/blob/bdea238ed343f8919d3ef74fc928ebdb81561008/solver/utils.py#L99

joppichristian avatar Mar 11 '20 18:03 joppichristian

I think that you can see the code normalizing features in clusteing.py :

def cos(self, pointA, pointB, cross):
    pointA = F.normalize(pointA, dim=1) #Cosine similarity only cares about direction
    pointB = F.normalize(pointB, dim=1)
    if not cross:
        return 0.5 * (1.0 - torch.sum(pointA * pointB, dim=1))
    else:
        NA = pointA.size(0)
        NB = pointB.size(0)
        assert(pointA.size(1) == pointB.size(1))
        return 0.5 * (1.0 - torch.matmul(pointA, pointB.transpose(0, 1)))

WDYIE avatar May 25 '20 03:05 WDYIE

Hi, I have the same question. It seems that the center is the sum of features instead of mean.

HHHedo avatar Jun 10 '20 03:06 HHHedo

Hi, There are normalize operation, Beacause Cosine similarity only cares about direction!

WDYIE avatar Jun 10 '20 14:06 WDYIE

Hi, There are normalize operation, Beacause Cosine similarity only cares about direction!

Thanks for your reply!

HHHedo avatar Jun 11 '20 03:06 HHHedo