JDAI-CV / FADA

(ECCV 2020) Classes Matter: A Fine-grained Adversarial Approach to Cross-domain Semantic Segmentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to implement the CCD in pytorch?

tinazoe1997 opened this issue · comments

Hi,
I'm recently trying to implement CCD in pytorch on source and target training data. However, the "sky" in "g2c_sd.pth" usually gets very large intra-class distance (resnet-101). The following pseudo code is how I calculate the intra-class distance between features belong to the class i and the feature of class center i :

  1. tensor = x - mu_i
  2. tensor = tensor[label == i]
  3. intra-distance = ((torch.norm(tensor, p=1, dim=1)) ** 2 / 2048).sum() / number of pixels belongs to class i

where the shape of each variable is:
x: [bs, 2048, num of pixels belongs to class i]
mu_i: [1, 2048]
tensor: [bs, 2048, num of pixels belongs to class i]

I calculate the inter-class distance in a similar way: replace 1) into tensor = mu_i - mu_j.
Am I correct?

Best regards,
Ut

I also have a question about the inconsistent results between Table 3. and the CCD referring to Figure 4.

In Table 3, the classes "TL" and "Bike" of FADA perform better than the CLAN. However, the CCD of these classes are performed poorly than CLAN as shown in Figure 4.

I'm wondering if this situation represents that the classifier provides powerful segmentation capabilities. Even the feature extractor performs poorly on these classes, but the classifier still performs well.

Hi, thanks for your interests!

The CCD reported in the paper is calculated by the model trained without self-distillation step. In my experimental records, I find that this model's performance on "TL" and "Bike" are slightly worse than CLAN.

For the implementation, if I remember it correctly, in my implementation the intra-distance is computed as the mean L2 norm between each feature x for class i and mu_i and the inter-class distance is computed similar. The inter-class distance is designed as a normalizer to prevent the case that features of different classes are clustered together.