princeton-vl / CornerNet-Lite

BSD 3-Clause "New" or "Revised" License
1.78k stars 431 forks source link

Questions about the mask in _ae_loss #126

Closed i-yliu closed 4 years ago

i-yliu commented 4 years ago

Hello,

I have a question regards to _ae_loss().

I am very confused what the shape is this mask? is it multiple channels, each instance per channel? I tried to find out where are the targets generate, but i can't find it. Could you please help me this questions? Thank you so much for your patience.

def _ae_loss(tag0, tag1, mask):
 num  = mask.sum(dim=1, keepdim=True).float()
tag0 = tag0.squeeze()
tag1 = tag1.squeeze()

tag_mean = (tag0 + tag1) / 2

tag0 = torch.pow(tag0 - tag_mean, 2) / (num + 1e-4)
tag0 = tag0[mask].sum()
tag1 = torch.pow(tag1 - tag_mean, 2) / (num + 1e-4)
tag1 = tag1[mask].sum()
pull = tag0 + tag1

mask = mask.unsqueeze(1) + mask.unsqueeze(2)
mask = mask.eq(2)
num  = num.unsqueeze(2)
num2 = (num - 1) * num
dist = tag_mean.unsqueeze(1) - tag_mean.unsqueeze(2)
dist = 1 - torch.abs(dist)
dist = nn.functional.relu(dist, inplace=True)
dist = dist - 1 / (num + 1e-4)
dist = dist / (num2 + 1e-4)
dist = dist[mask]
push = dist.sum()
return pull, push