original_docstring: 
      This is for calculating the mean iou of the current iteration
      :param model: Model
      :param data_loader: Validation data loader
      :param device:
      :return: the mean iou
      
docstring: This is for calculating the mean iou of the current iteration
docstring_tokens: This is for calculating the mean iou of the current iteration
code: def val_metrics(model, data_loader, device):
      """
      This is for calculating the mean iou of the current iteration
      :param model: Model
      :param data_loader: Validation data loader
      :param device:
      :return: the mean iou
      """
      for images, targets, img_name in data_loader:
          images = list(image.to(device) for image in images)
          targets = [{k: v.to(device) for k, v in t.items()} for t in targets]
          model.eval()
  
          list_targets_boxes = []
          list_targets_labels = []
          # Loop to take the bounding boxes and labels only
          for x in targets:
              list_targets_boxes.append(x['boxes'])
              list_targets_labels.append(x['labels'])
              if len(list_targets_labels) == 0:
                  list_targets_labels.append(0)
  
          # Current model predictions
          pred_y = model(images)
          pred_y_boxes = []
          pred_y_labels = []
          for x in pred_y:
              pred_y_boxes.append(x['boxes'])
              pred_y_labels.append(x['labels'])
  
          loss_val = 0
          loss_val_total = 0
          count = 0
          # Calculate the iou for each prediction compared to each iou, then averages them
          for x in list_targets_boxes:
              for y in pred_y_boxes:
                  loss_val += torch.sum(jaccard(x, y))
                  if y.size(dim=0) > 0:
                      loss_val_total += loss_val.item() / y.size(dim=0)
          model.train()
      return loss_val_total
code_tokens: def val_metrics ( model , data_loader , device ) : for images , targets , img_name in data_loader : images = list ( image . to ( device ) for image in images ) targets = [ { k : v . to ( device ) for k , v in t . items ( ) } for t in targets ] model . eval ( ) list_targets_boxes = [ ] list_targets_labels = [ ] for x in targets : list_targets_boxes . append ( x [ 'boxes' ] ) list_targets_labels . append ( x [ 'labels' ] ) if len ( list_targets_labels ) == 0 : list_targets_labels . append ( 0 ) pred_y = model ( images ) pred_y_boxes = [ ] pred_y_labels = [ ] for x in pred_y : pred_y_boxes . append ( x [ 'boxes' ] ) pred_y_labels . append ( x [ 'labels' ] ) loss_val = 0 loss_val_total = 0 count = 0 for x in list_targets_boxes : for y in pred_y_boxes : loss_val += torch . sum ( jaccard ( x , y ) ) if y . size ( dim = 0 ) > 0 : loss_val_total += loss_val . item ( ) / y . size ( dim = 0 ) model . train ( ) return loss_val_total
short_docstring: This is for calculating the mean iou of the current iteration
short_docstring_tokens: This is for calculating the mean iou of the current iteration
comment: """
      This is for calculating the mean iou of the current iteration
      :param model: Model
      :param data_loader: Validation data loader
      :param device:
      :return: the mean iou
      """$SEP$# Loop to take the bounding boxes and labels only$SEP$# Current model predictions$SEP$# Calculate the iou for each prediction compared to each iou, then averages them