Hello, everyone. I am new to pytorch, so sorry if something sounds stupid.
My model consists of a vgg16 that outputs a 64x64 grid of boolean predictions.
I have built my own custom loss functions, but I think that I am doing something really wrong.
In two epochs the loss is dropping to zero, but when I try to test the model, with the exact same imagens used on training, I got results really weird.
For all images the result was a bunch of zeros and a one in the first position:
[1, 0, 0, 0, …0]
[0, 0, 0, 0, …0]
…
…
…
[0, 0, 0, 0, …0]
I will post here the loss function that I built. If someone could give me a hint on what I am doing wrong, I would be really grateful. If my question/explanation was confused/incomplete, please tell me, so I can try to explain better.
true_scores = torch.zeros((batch_size, 1, self.grid_size, self.grid_size)).to(device) # (N, 1, 64, 64)
# For each image
for i in range(batch_size):
for row in targets[i]:
cells = torch.floor(row/self.cell_size).type(torch.long) # (n_points, 2)
cells = cells[:, 1]*self.grid_size + cells[:, 0] # (n_points)
true_scores[i][0].view(self.grid_size**2)[cells] = 1.0
score_loss = self.logist_bce(pred, true_scores)
return score_loss