prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  bug report
  The attribute **meta_keys** is lost in Collect.
  ```python
  @PIPELINES.register_module()
  class Collect(object):
      """
      Collect data from the loader relevant to the specific task.
      This is usually the last stage of the data loader pipeline. Typically keys
      is set to some subset of "img" and "gt_label".
      """
  
      def __init__(self, keys):
          self.keys = keys
  
      def __call__(self, results):
          data = {}
          for key in self.keys:
              data[key] = results[key]
          return data
  
      def __repr__(self):
          return self.__class__.__name__ + \
              f'(keys={self.keys}, meta_keys={self.meta_keys})'
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mmcls/datasets/pipelines/formating.py`
  Content:
  ```
  1 from collections.abc import Sequence
  2 
  3 import mmcv
  4 import numpy as np
  5 import torch
  6 from PIL import Image
  7 
  8 from ..builder import PIPELINES
  9 
  10 
  11 def to_tensor(data):
  12     """Convert objects of various python types to :obj:`torch.Tensor`.
  13 
  14     Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,
  15     :class:`Sequence`, :class:`int` and :class:`float`.
  16     """
  17     if isinstance(data, torch.Tensor):
  18         return data
  19     elif isinstance(data, np.ndarray):
  20         return torch.from_numpy(data)
  21     elif isinstance(data, Sequence) and not mmcv.is_str(data):
  22         return torch.tensor(data)
  23     elif isinstance(data, int):
  24         return torch.LongTensor([data])
  25     elif isinstance(data, float):
  26         return torch.FloatTensor([data])
  27     else:
  28         raise TypeError(
  29             f'Type {type(data)} cannot be converted to tensor.'
  30             'Supported types are: `numpy.ndarray`, `torch.Tensor`, '
  31             '`Sequence`, `int` and `float`')
  32 
  33 
  34 @PIPELINES.register_module()
  35 class ToTensor(object):
  36 
  37     def __init__(self, keys):
  38         self.keys = keys
  39 
  40     def __call__(self, results):
  41         for key in self.keys:
  42             results[key] = to_tensor(results[key])
  43         return results
  44 
  45     def __repr__(self):
  46         return self.__class__.__name__ + f'(keys={self.keys})'
  47 
  48 
  49 @PIPELINES.register_module()
  50 class ImageToTensor(object):
  51 
  52     def __init__(self, keys):
  53         self.keys = keys
  54 
  55     def __call__(self, results):
  56         for key in self.keys:
  57             img = results[key]
  58             if len(img.shape) < 3:
  59                 img = np.expand_dims(img, -1)
  60             results[key] = to_tensor(img.transpose(2, 0, 1))
  61         return results
  62 
  63     def __repr__(self):
  64         return self.__class__.__name__ + f'(keys={self.keys})'
  65 
  66 
  67 @PIPELINES.register_module()
  68 class Transpose(object):
  69 
  70     def __init__(self, keys, order):
  71         self.keys = keys
  72         self.order = order
  73 
  74     def __call__(self, results):
  75         for key in self.keys:
  76             results[key] = results[key].transpose(self.order)
  77         return results
  78 
  79     def __repr__(self):
  80         return self.__class__.__name__ + \
  81             f'(keys={self.keys}, order={self.order})'
  82 
  83 
  84 @PIPELINES.register_module()
  85 class ToPIL(object):
  86 
  87     def __init__(self):
  88         pass
  89 
  90     def __call__(self, results):
  91         results['img'] = Image.fromarray(results['img'])
  92         return results
  93 
  94 
  95 @PIPELINES.register_module()
  96 class ToNumpy(object):
  97 
  98     def __init__(self):
  99         pass
  100 
  101     def __call__(self, results):
  102         results['img'] = np.array(results['img'], dtype=np.float32)
  103         return results
  104 
  105 
  106 @PIPELINES.register_module()
  107 class Collect(object):
  108     """
  109     Collect data from the loader relevant to the specific task.
  110 
  111     This is usually the last stage of the data loader pipeline. Typically keys
  112     is set to some subset of "img" and "gt_label".
  113     """
  114 
  115     def __init__(self, keys):
  116         self.keys = keys
  117 
  118     def __call__(self, results):
  119         data = {}
  120         for key in self.keys:
  121             data[key] = results[key]
  122         return data
  123 
  124     def __repr__(self):
  125         return self.__class__.__name__ + \
  126             f'(keys={self.keys}, meta_keys={self.meta_keys})'
  127 
  128 
  129 @PIPELINES.register_module()
  130 class WrapFieldsToLists(object):
  131     """Wrap fields of the data dictionary into lists for evaluation.
  132 
  133     This class can be used as a last step of a test or validation
  134     pipeline for single image evaluation or inference.
  135 
  136     Example:
  137         >>> test_pipeline = [
  138         >>>    dict(type='LoadImageFromFile'),
  139         >>>    dict(type='Normalize',
  140                     mean=[123.675, 116.28, 103.53],
  141                     std=[58.395, 57.12, 57.375],
  142                     to_rgb=True),
  143         >>>    dict(type='ImageToTensor', keys=['img']),
  144         >>>    dict(type='Collect', keys=['img']),
  145         >>>    dict(type='WrapIntoLists')
  146         >>> ]
  147     """
  148 
  149     def __call__(self, results):
  150         # Wrap dict fields into lists
  151         for key, val in results.items():
  152             results[key] = [val]
  153         return results
  154 
  155     def __repr__(self):
  156         return f'{self.__class__.__name__}()'
  157
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mmcls/datasets/pipelines/formating.py b/mmcls/datasets/pipelines/formating.py
  --- a/mmcls/datasets/pipelines/formating.py
  +++ b/mmcls/datasets/pipelines/formating.py
  @@ -3,6 +3,7 @@
   import mmcv
   import numpy as np
   import torch
  +from mmcv.parallel import DataContainer as DC
   from PIL import Image
   
   from ..builder import PIPELINES
  @@ -110,13 +111,34 @@
   
       This is usually the last stage of the data loader pipeline. Typically keys
       is set to some subset of "img" and "gt_label".
  +
  +    Args:
  +        keys (Sequence[str]): Keys of results to be collected in ``data``.
  +        meta_keys (Sequence[str], optional): Meta keys to be converted to
  +            ``mmcv.DataContainer`` and collected in ``data[img_metas]``.
  +            Default: ``('filename', 'ori_shape', 'img_shape', 'flip',
  +            'flip_direction', 'img_norm_cfg')``
  +
  +    Returns:
  +        dict: The result dict contains the following keys
  +                - keys in``self.keys``
  +                - ``img_metas`` if avaliable
       """
   
  -    def __init__(self, keys):
  +    def __init__(self,
  +                 keys,
  +                 meta_keys=('filename', 'ori_shape', 'img_shape', 'flip',
  +                            'flip_direction', 'img_norm_cfg')):
           self.keys = keys
  +        self.meta_keys = meta_keys
   
       def __call__(self, results):
           data = {}
  +        img_meta = {}
  +        for key in self.meta_keys:
  +            if key in results:
  +                img_meta[key] = results[key]
  +        data['img_metas'] = DC(img_meta, cpu_only=True)
           for key in self.keys:
               data[key] = results[key]
           return data
  
verification_info: {"golden_diff": "diff --git a/mmcls/datasets/pipelines/formating.py b/mmcls/datasets/pipelines/formating.py\n--- a/mmcls/datasets/pipelines/formating.py\n+++ b/mmcls/datasets/pipelines/formating.py\n@@ -3,6 +3,7 @@\n import mmcv\n import numpy as np\n import torch\n+from mmcv.parallel import DataContainer as DC\n from PIL import Image\n \n from ..builder import PIPELINES\n@@ -110,13 +111,34 @@\n \n     This is usually the last stage of the data loader pipeline. Typically keys\n     is set to some subset of \"img\" and \"gt_label\".\n+\n+    Args:\n+        keys (Sequence[str]): Keys of results to be collected in ``data``.\n+        meta_keys (Sequence[str], optional): Meta keys to be converted to\n+            ``mmcv.DataContainer`` and collected in ``data[img_metas]``.\n+            Default: ``('filename', 'ori_shape', 'img_shape', 'flip',\n+            'flip_direction', 'img_norm_cfg')``\n+\n+    Returns:\n+        dict: The result dict contains the following keys\n+                - keys in``self.keys``\n+                - ``img_metas`` if avaliable\n     \"\"\"\n \n-    def __init__(self, keys):\n+    def __init__(self,\n+                 keys,\n+                 meta_keys=('filename', 'ori_shape', 'img_shape', 'flip',\n+                            'flip_direction', 'img_norm_cfg')):\n         self.keys = keys\n+        self.meta_keys = meta_keys\n \n     def __call__(self, results):\n         data = {}\n+        img_meta = {}\n+        for key in self.meta_keys:\n+            if key in results:\n+                img_meta[key] = results[key]\n+        data['img_metas'] = DC(img_meta, cpu_only=True)\n         for key in self.keys:\n             data[key] = results[key]\n         return data\n", "issue": "bug report\nThe attribute **meta_keys** is lost in Collect.\r\n```python\r\n@PIPELINES.register_module()\r\nclass Collect(object):\r\n    \"\"\"\r\n    Collect data from the loader relevant to the specific task.\r\n    This is usually the last stage of the data loader pipeline. Typically keys\r\n    is set to some subset of \"img\" and \"gt_label\".\r\n    \"\"\"\r\n\r\n    def __init__(self, keys):\r\n        self.keys = keys\r\n\r\n    def __call__(self, results):\r\n        data = {}\r\n        for key in self.keys:\r\n            data[key] = results[key]\r\n        return data\r\n\r\n    def __repr__(self):\r\n        return self.__class__.__name__ + \\\r\n            f'(keys={self.keys}, meta_keys={self.meta_keys})'\r\n```\n", "before_files": [{"content": "from collections.abc import Sequence\n\nimport mmcv\nimport numpy as np\nimport torch\nfrom PIL import Image\n\nfrom ..builder import PIPELINES\n\n\ndef to_tensor(data):\n    \"\"\"Convert objects of various python types to :obj:`torch.Tensor`.\n\n    Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,\n    :class:`Sequence`, :class:`int` and :class:`float`.\n    \"\"\"\n    if isinstance(data, torch.Tensor):\n        return data\n    elif isinstance(data, np.ndarray):\n        return torch.from_numpy(data)\n    elif isinstance(data, Sequence) and not mmcv.is_str(data):\n        return torch.tensor(data)\n    elif isinstance(data, int):\n        return torch.LongTensor([data])\n    elif isinstance(data, float):\n        return torch.FloatTensor([data])\n    else:\n        raise TypeError(\n            f'Type {type(data)} cannot be converted to tensor.'\n            'Supported types are: `numpy.ndarray`, `torch.Tensor`, '\n            '`Sequence`, `int` and `float`')\n\n\n@PIPELINES.register_module()\nclass ToTensor(object):\n\n    def __init__(self, keys):\n        self.keys = keys\n\n    def __call__(self, results):\n        for key in self.keys:\n            results[key] = to_tensor(results[key])\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + f'(keys={self.keys})'\n\n\n@PIPELINES.register_module()\nclass ImageToTensor(object):\n\n    def __init__(self, keys):\n        self.keys = keys\n\n    def __call__(self, results):\n        for key in self.keys:\n            img = results[key]\n            if len(img.shape) < 3:\n                img = np.expand_dims(img, -1)\n            results[key] = to_tensor(img.transpose(2, 0, 1))\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + f'(keys={self.keys})'\n\n\n@PIPELINES.register_module()\nclass Transpose(object):\n\n    def __init__(self, keys, order):\n        self.keys = keys\n        self.order = order\n\n    def __call__(self, results):\n        for key in self.keys:\n            results[key] = results[key].transpose(self.order)\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + \\\n            f'(keys={self.keys}, order={self.order})'\n\n\n@PIPELINES.register_module()\nclass ToPIL(object):\n\n    def __init__(self):\n        pass\n\n    def __call__(self, results):\n        results['img'] = Image.fromarray(results['img'])\n        return results\n\n\n@PIPELINES.register_module()\nclass ToNumpy(object):\n\n    def __init__(self):\n        pass\n\n    def __call__(self, results):\n        results['img'] = np.array(results['img'], dtype=np.float32)\n        return results\n\n\n@PIPELINES.register_module()\nclass Collect(object):\n    \"\"\"\n    Collect data from the loader relevant to the specific task.\n\n    This is usually the last stage of the data loader pipeline. Typically keys\n    is set to some subset of \"img\" and \"gt_label\".\n    \"\"\"\n\n    def __init__(self, keys):\n        self.keys = keys\n\n    def __call__(self, results):\n        data = {}\n        for key in self.keys:\n            data[key] = results[key]\n        return data\n\n    def __repr__(self):\n        return self.__class__.__name__ + \\\n            f'(keys={self.keys}, meta_keys={self.meta_keys})'\n\n\n@PIPELINES.register_module()\nclass WrapFieldsToLists(object):\n    \"\"\"Wrap fields of the data dictionary into lists for evaluation.\n\n    This class can be used as a last step of a test or validation\n    pipeline for single image evaluation or inference.\n\n    Example:\n        >>> test_pipeline = [\n        >>>    dict(type='LoadImageFromFile'),\n        >>>    dict(type='Normalize',\n                    mean=[123.675, 116.28, 103.53],\n                    std=[58.395, 57.12, 57.375],\n                    to_rgb=True),\n        >>>    dict(type='ImageToTensor', keys=['img']),\n        >>>    dict(type='Collect', keys=['img']),\n        >>>    dict(type='WrapIntoLists')\n        >>> ]\n    \"\"\"\n\n    def __call__(self, results):\n        # Wrap dict fields into lists\n        for key, val in results.items():\n            results[key] = [val]\n        return results\n\n    def __repr__(self):\n        return f'{self.__class__.__name__}()'\n", "path": "mmcls/datasets/pipelines/formating.py"}], "after_files": [{"content": "from collections.abc import Sequence\n\nimport mmcv\nimport numpy as np\nimport torch\nfrom mmcv.parallel import DataContainer as DC\nfrom PIL import Image\n\nfrom ..builder import PIPELINES\n\n\ndef to_tensor(data):\n    \"\"\"Convert objects of various python types to :obj:`torch.Tensor`.\n\n    Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,\n    :class:`Sequence`, :class:`int` and :class:`float`.\n    \"\"\"\n    if isinstance(data, torch.Tensor):\n        return data\n    elif isinstance(data, np.ndarray):\n        return torch.from_numpy(data)\n    elif isinstance(data, Sequence) and not mmcv.is_str(data):\n        return torch.tensor(data)\n    elif isinstance(data, int):\n        return torch.LongTensor([data])\n    elif isinstance(data, float):\n        return torch.FloatTensor([data])\n    else:\n        raise TypeError(\n            f'Type {type(data)} cannot be converted to tensor.'\n            'Supported types are: `numpy.ndarray`, `torch.Tensor`, '\n            '`Sequence`, `int` and `float`')\n\n\n@PIPELINES.register_module()\nclass ToTensor(object):\n\n    def __init__(self, keys):\n        self.keys = keys\n\n    def __call__(self, results):\n        for key in self.keys:\n            results[key] = to_tensor(results[key])\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + f'(keys={self.keys})'\n\n\n@PIPELINES.register_module()\nclass ImageToTensor(object):\n\n    def __init__(self, keys):\n        self.keys = keys\n\n    def __call__(self, results):\n        for key in self.keys:\n            img = results[key]\n            if len(img.shape) < 3:\n                img = np.expand_dims(img, -1)\n            results[key] = to_tensor(img.transpose(2, 0, 1))\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + f'(keys={self.keys})'\n\n\n@PIPELINES.register_module()\nclass Transpose(object):\n\n    def __init__(self, keys, order):\n        self.keys = keys\n        self.order = order\n\n    def __call__(self, results):\n        for key in self.keys:\n            results[key] = results[key].transpose(self.order)\n        return results\n\n    def __repr__(self):\n        return self.__class__.__name__ + \\\n            f'(keys={self.keys}, order={self.order})'\n\n\n@PIPELINES.register_module()\nclass ToPIL(object):\n\n    def __init__(self):\n        pass\n\n    def __call__(self, results):\n        results['img'] = Image.fromarray(results['img'])\n        return results\n\n\n@PIPELINES.register_module()\nclass ToNumpy(object):\n\n    def __init__(self):\n        pass\n\n    def __call__(self, results):\n        results['img'] = np.array(results['img'], dtype=np.float32)\n        return results\n\n\n@PIPELINES.register_module()\nclass Collect(object):\n    \"\"\"\n    Collect data from the loader relevant to the specific task.\n\n    This is usually the last stage of the data loader pipeline. Typically keys\n    is set to some subset of \"img\" and \"gt_label\".\n\n    Args:\n        keys (Sequence[str]): Keys of results to be collected in ``data``.\n        meta_keys (Sequence[str], optional): Meta keys to be converted to\n            ``mmcv.DataContainer`` and collected in ``data[img_metas]``.\n            Default: ``('filename', 'ori_shape', 'img_shape', 'flip',\n            'flip_direction', 'img_norm_cfg')``\n\n    Returns:\n        dict: The result dict contains the following keys\n                - keys in``self.keys``\n                - ``img_metas`` if avaliable\n    \"\"\"\n\n    def __init__(self,\n                 keys,\n                 meta_keys=('filename', 'ori_shape', 'img_shape', 'flip',\n                            'flip_direction', 'img_norm_cfg')):\n        self.keys = keys\n        self.meta_keys = meta_keys\n\n    def __call__(self, results):\n        data = {}\n        img_meta = {}\n        for key in self.meta_keys:\n            if key in results:\n                img_meta[key] = results[key]\n        data['img_metas'] = DC(img_meta, cpu_only=True)\n        for key in self.keys:\n            data[key] = results[key]\n        return data\n\n    def __repr__(self):\n        return self.__class__.__name__ + \\\n            f'(keys={self.keys}, meta_keys={self.meta_keys})'\n\n\n@PIPELINES.register_module()\nclass WrapFieldsToLists(object):\n    \"\"\"Wrap fields of the data dictionary into lists for evaluation.\n\n    This class can be used as a last step of a test or validation\n    pipeline for single image evaluation or inference.\n\n    Example:\n        >>> test_pipeline = [\n        >>>    dict(type='LoadImageFromFile'),\n        >>>    dict(type='Normalize',\n                    mean=[123.675, 116.28, 103.53],\n                    std=[58.395, 57.12, 57.375],\n                    to_rgb=True),\n        >>>    dict(type='ImageToTensor', keys=['img']),\n        >>>    dict(type='Collect', keys=['img']),\n        >>>    dict(type='WrapIntoLists')\n        >>> ]\n    \"\"\"\n\n    def __call__(self, results):\n        # Wrap dict fields into lists\n        for key, val in results.items():\n            results[key] = [val]\n        return results\n\n    def __repr__(self):\n        return f'{self.__class__.__name__}()'\n", "path": "mmcls/datasets/pipelines/formating.py"}]}