prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Write image name to pickle file
  Hi MMOCR team,
  Thank you for this awesome framework. I have a task to get coordinate of bounding box from Textsnake model, so I use --out argument in test.py to export to a pickle file. But when I load this pickle, I just got ‘boundary_result’ and don't know this ‘boundary_result’ belongs to which image. How can I get the image to write to the pickle file? Thank you.
  
  </issue>
  <code>
  [start of mmocr/models/textdet/dense_heads/head_mixin.py]
  1 # Copyright (c) OpenMMLab. All rights reserved.
  2 import numpy as np
  3 
  4 from mmocr.models.builder import HEADS
  5 from mmocr.models.textdet.postprocess import decode
  6 from mmocr.utils import check_argument
  7 
  8 
  9 @HEADS.register_module()
  10 class HeadMixin:
  11     """The head minxin for dbnet and pannet heads."""
  12 
  13     def resize_boundary(self, boundaries, scale_factor):
  14         """Rescale boundaries via scale_factor.
  15 
  16         Args:
  17             boundaries (list[list[float]]): The boundary list. Each boundary
  18             with size 2k+1 with k>=4.
  19             scale_factor(ndarray): The scale factor of size (4,).
  20 
  21         Returns:
  22             boundaries (list[list[float]]): The scaled boundaries.
  23         """
  24         assert check_argument.is_2dlist(boundaries)
  25         assert isinstance(scale_factor, np.ndarray)
  26         assert scale_factor.shape[0] == 4
  27 
  28         for b in boundaries:
  29             sz = len(b)
  30             check_argument.valid_boundary(b, True)
  31             b[:sz -
  32               1] = (np.array(b[:sz - 1]) *
  33                     (np.tile(scale_factor[:2], int(
  34                         (sz - 1) / 2)).reshape(1, sz - 1))).flatten().tolist()
  35         return boundaries
  36 
  37     def get_boundary(self, score_maps, img_metas, rescale):
  38         """Compute text boundaries via post processing.
  39 
  40         Args:
  41             score_maps (Tensor): The text score map.
  42             img_metas (dict): The image meta info.
  43             rescale (bool): Rescale boundaries to the original image resolution
  44                 if true, and keep the score_maps resolution if false.
  45 
  46         Returns:
  47             results (dict): The result dict.
  48         """
  49 
  50         assert check_argument.is_type_list(img_metas, dict)
  51         assert isinstance(rescale, bool)
  52 
  53         score_maps = score_maps.squeeze()
  54         boundaries = decode(
  55             decoding_type=self.decoding_type,
  56             preds=score_maps,
  57             text_repr_type=self.text_repr_type)
  58         if rescale:
  59             boundaries = self.resize_boundary(
  60                 boundaries,
  61                 1.0 / self.downsample_ratio / img_metas[0]['scale_factor'])
  62         results = dict(boundary_result=boundaries)
  63         return results
  64 
  65     def loss(self, pred_maps, **kwargs):
  66         """Compute the loss for text detection.
  67 
  68         Args:
  69             pred_maps (tensor): The input score maps of NxCxHxW.
  70 
  71         Returns:
  72             losses (dict): The dict for losses.
  73         """
  74         losses = self.loss_module(pred_maps, self.downsample_ratio, **kwargs)
  75         return losses
  76
  [end of mmocr/models/textdet/dense_heads/head_mixin.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/mmocr/models/textdet/dense_heads/head_mixin.py b/mmocr/models/textdet/dense_heads/head_mixin.py
  --- a/mmocr/models/textdet/dense_heads/head_mixin.py
  +++ b/mmocr/models/textdet/dense_heads/head_mixin.py
  @@ -59,7 +59,9 @@
               boundaries = self.resize_boundary(
                   boundaries,
                   1.0 / self.downsample_ratio / img_metas[0]['scale_factor'])
  -        results = dict(boundary_result=boundaries)
  +        results = dict(
  +            boundary_result=boundaries, filename=img_metas[0]['filename'])
  +
           return results
   
       def loss(self, pred_maps, **kwargs):
  
verification_info: {"golden_diff": "diff --git a/mmocr/models/textdet/dense_heads/head_mixin.py b/mmocr/models/textdet/dense_heads/head_mixin.py\n--- a/mmocr/models/textdet/dense_heads/head_mixin.py\n+++ b/mmocr/models/textdet/dense_heads/head_mixin.py\n@@ -59,7 +59,9 @@\n             boundaries = self.resize_boundary(\n                 boundaries,\n                 1.0 / self.downsample_ratio / img_metas[0]['scale_factor'])\n-        results = dict(boundary_result=boundaries)\n+        results = dict(\n+            boundary_result=boundaries, filename=img_metas[0]['filename'])\n+\n         return results\n \n     def loss(self, pred_maps, **kwargs):\n", "issue": "Write image name to pickle file\nHi MMOCR team,\nThank you for this awesome framework. I have a task to get coordinate of bounding box from Textsnake model, so I use --out argument in test.py to export to a pickle file. But when I load this pickle, I just got \u2018boundary_result\u2019 and don't know this \u2018boundary_result\u2019 belongs to which image. How can I get the image to write to the pickle file? Thank you.\n", "before_files": [{"content": "# Copyright (c) OpenMMLab. All rights reserved.\nimport numpy as np\n\nfrom mmocr.models.builder import HEADS\nfrom mmocr.models.textdet.postprocess import decode\nfrom mmocr.utils import check_argument\n\n\n@HEADS.register_module()\nclass HeadMixin:\n    \"\"\"The head minxin for dbnet and pannet heads.\"\"\"\n\n    def resize_boundary(self, boundaries, scale_factor):\n        \"\"\"Rescale boundaries via scale_factor.\n\n        Args:\n            boundaries (list[list[float]]): The boundary list. Each boundary\n            with size 2k+1 with k>=4.\n            scale_factor(ndarray): The scale factor of size (4,).\n\n        Returns:\n            boundaries (list[list[float]]): The scaled boundaries.\n        \"\"\"\n        assert check_argument.is_2dlist(boundaries)\n        assert isinstance(scale_factor, np.ndarray)\n        assert scale_factor.shape[0] == 4\n\n        for b in boundaries:\n            sz = len(b)\n            check_argument.valid_boundary(b, True)\n            b[:sz -\n              1] = (np.array(b[:sz - 1]) *\n                    (np.tile(scale_factor[:2], int(\n                        (sz - 1) / 2)).reshape(1, sz - 1))).flatten().tolist()\n        return boundaries\n\n    def get_boundary(self, score_maps, img_metas, rescale):\n        \"\"\"Compute text boundaries via post processing.\n\n        Args:\n            score_maps (Tensor): The text score map.\n            img_metas (dict): The image meta info.\n            rescale (bool): Rescale boundaries to the original image resolution\n                if true, and keep the score_maps resolution if false.\n\n        Returns:\n            results (dict): The result dict.\n        \"\"\"\n\n        assert check_argument.is_type_list(img_metas, dict)\n        assert isinstance(rescale, bool)\n\n        score_maps = score_maps.squeeze()\n        boundaries = decode(\n            decoding_type=self.decoding_type,\n            preds=score_maps,\n            text_repr_type=self.text_repr_type)\n        if rescale:\n            boundaries = self.resize_boundary(\n                boundaries,\n                1.0 / self.downsample_ratio / img_metas[0]['scale_factor'])\n        results = dict(boundary_result=boundaries)\n        return results\n\n    def loss(self, pred_maps, **kwargs):\n        \"\"\"Compute the loss for text detection.\n\n        Args:\n            pred_maps (tensor): The input score maps of NxCxHxW.\n\n        Returns:\n            losses (dict): The dict for losses.\n        \"\"\"\n        losses = self.loss_module(pred_maps, self.downsample_ratio, **kwargs)\n        return losses\n", "path": "mmocr/models/textdet/dense_heads/head_mixin.py"}]}