I am trying to normalize the weight that I get from embedding layer using F.normalize function but getting error as “IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)”.
Not sure why.
def forward(self, imgs):
### complete the forward path --------------------
cls_scores = []
## YOUR CODE HERE
for i in range(len(self.classes)):
v = self.backbone(imgs)
class_out = random.choice(self.classes)
class_out = self.classes.index(class_out)
class_out = torch.tensor(class_out)
wt = self.embeddings(class_out) # not sure what should be the input
wt_normalized = F.normalize(wt, p=2, dim=1)
self.dc.weight = nn.Parameter(wt_normalized)
v_out = self.dc(v)
out = nn.Upsample(size=(8, 8), mode='bilinear')(v_out)
out = nn.Upsample(size=(64, 64), mode='bilinear')(v_out)
score = self.mlp(out)
cls_scores.append(score)
### ----------------------------------------------
return cls_scores # Dim: [batch_size, 10]