Beispiel #1
0
 def loss_fn(self, out, annot):
     tar_vector = Losses.get_tar_vector(annot)
     loss_loc = Losses.get_loc_error(out, tar_vector)
     loss_wh = Losses.get_w_h_error(out, tar_vector)
     loss_conf = Losses.get_confidence_error(out, tar_vector)
     loss_cls = Losses.get_class_error(out, tar_vector)
     return loss_loc, loss_wh, loss_conf, loss_cls
Beispiel #2
0
some_target_for_loc_error = {
    (3, 3):
    [[0, [1, 1], [torch.Tensor([0.1]).cuda(),
                  torch.Tensor([0.1]).cuda()]]]
}
some_predictions_for_loc_error = torch.zeros((1, cell_num, cell_num, 30))
for y in range(cell_num):
    for x in range(cell_num):
        some_predictions_for_loc_error[0, y, x, :] = torch.Tensor([
            0.2, 0.2, 0, 0, 0, 0.2, 0.2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1
        ])
unittest.TestCase().assertAlmostEqual(
    0.01,
    Losses.get_loc_error(some_predictions_for_loc_error,
                         some_target_for_loc_error).cpu().detach().numpy()[0],
    2)

some_targets_class_prob_exist = {
    (3, 3): [[1, [0, 0], [torch.Tensor([0]).cuda(),
                          torch.Tensor([0]).cuda()]]]
}
some_predictions_class_prob_exist = torch.zeros((1, cell_num, cell_num, 30))
for y in range(cell_num):
    for x in range(cell_num):
        if y == 3 and x == 3:
            some_predictions_class_prob_exist[0, y, x, :] = torch.Tensor([
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            ])
        else: