# Codeblock 5b target_bbox = target[..., 21:25] #(1) pred_bbox0 = prediction[..., 21:25] #(2) pred_bbox1 = prediction[..., 26:30] #(3) iou_pred_bbox0 = intersection_over_union(pred_bbox0, target_bbox) #(4) iou_pred_bbox1 = intersection_over_union(pred_bbox1, target_bbox) #(5) iou_pred_bboxes = torch.cat([iou_pred_bbox0.unsqueeze(0), iou_pred_bbox1.unsqueeze(0)], dim=0) best_iou, best_bbox_idx = torch.max(iou_pred_bboxes, dim=0) #(6) target_bbox = obj * target_bbox #(7) best_bbox = obj * (best_bbox_idx*pred_bbox1 #(8) + (1-best_bbox_idx)*pred_bbox0) target_bbox[..., 2:4] = torch.sqrt(target_bbox[..., 2:4]) #(9) best_bbox[..., 2:4] = torch.sign(best_bbox[..., 2:4]) * torch.sqrt(torch.abs(best_bbox[..., 2:4]) + 1e-6) #(10) bbox_loss = sse( #(11) torch.flatten(target_bbox, end_dim=-2), torch.flatten(best_bbox, end_dim=-2) )