Functions to load image. Args: results (dict): Result dict from :class:`mmengine.dataset.BaseDataset`. Returns: dict: The dict contains loaded image and meta information.
(self, results: dict)
| 100 | self.backend_args = backend_args.copy() |
| 101 | |
| 102 | def transform(self, results: dict) -> Optional[dict]: |
| 103 | """Functions to load image. |
| 104 | |
| 105 | Args: |
| 106 | results (dict): Result dict from |
| 107 | :class:`mmengine.dataset.BaseDataset`. |
| 108 | |
| 109 | Returns: |
| 110 | dict: The dict contains loaded image and meta information. |
| 111 | """ |
| 112 | |
| 113 | filename = results['img_path'] |
| 114 | try: |
| 115 | if self.file_client_args is not None: |
| 116 | file_client = fileio.FileClient.infer_client( |
| 117 | self.file_client_args, filename) |
| 118 | img_bytes = file_client.get(filename) |
| 119 | else: |
| 120 | img_bytes = fileio.get( |
| 121 | filename, backend_args=self.backend_args) |
| 122 | img = mmcv.imfrombytes( |
| 123 | img_bytes, flag=self.color_type, backend=self.imdecode_backend) |
| 124 | except Exception as e: |
| 125 | if self.ignore_empty: |
| 126 | return None |
| 127 | else: |
| 128 | raise e |
| 129 | if self.to_float32: |
| 130 | img = img.astype(np.float32) |
| 131 | |
| 132 | results['img'] = img |
| 133 | results['img_shape'] = img.shape[:2] |
| 134 | results['ori_shape'] = img.shape[:2] |
| 135 | return results |
| 136 | |
| 137 | def __repr__(self): |
| 138 | repr_str = (f'{self.__class__.__name__}(' |