code: def calculate_losses(self, pred, label):
      heatmap = label["heatmap"]
      heatmap_weight = label["heatmap_weight"]
      radius = torch.log(label["radius"] + 1)
      radius_weight = label["radius_weight"]
  
      heatmap_pred = pred["heatmap"]
      radius_pred = pred["radius"]
  
      heatmap_loss = F.binary_cross_entropy_with_logits(
          heatmap_pred, heatmap, reduction="none"
      )
      heatmap_loss = (heatmap_loss * heatmap_weight).mean(dim=(1, 2, 3))
  
      radius_loss = F.smooth_l1_loss(
          radius_pred, radius, reduction="none"
      )
      radius_loss = (radius_loss * radius_weight).mean(
          dim=(1, 2, 3)
      ) * self.radius_ratio
  
      return {
          "heatmap_loss": heatmap_loss,
          "radius_loss": radius_loss,
      }
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from backbones.upsample_head import SimpleUpsampleHead
label_desc: Use image node_id 4 for calling the SimpleTextsnakeDecoder obj's underlying member method code with example usage: obj.calculate_losses(pred, label) and returns: dict