|  | 
| 1 | 1 | # Copyright (c) OpenMMLab. All rights reserved. | 
| 2 | 2 | import warnings | 
|  | 3 | +from pathlib import Path | 
| 3 | 4 | from typing import Optional | 
| 4 | 5 | 
 | 
| 5 | 6 | import mmengine.fileio as fileio | 
| @@ -90,21 +91,28 @@ def transform(self, results: dict) -> Optional[dict]: | 
| 90 | 91 |         """ | 
| 91 | 92 | 
 | 
| 92 | 93 |         filename = results['img_path'] | 
|  | 94 | + | 
| 93 | 95 |         try: | 
| 94 |  | -            if self.file_client_args is not None: | 
| 95 |  | -                file_client = fileio.FileClient.infer_client( | 
| 96 |  | -                    self.file_client_args, filename) | 
| 97 |  | -                img_bytes = file_client.get(filename) | 
|  | 96 | +            if Path(filename).suffix in ['.npy', '.npz']: | 
|  | 97 | +                img = np.load(filename) | 
| 98 | 98 |             else: | 
| 99 |  | -                img_bytes = fileio.get( | 
| 100 |  | -                    filename, backend_args=self.backend_args) | 
| 101 |  | -            img = mmcv.imfrombytes( | 
| 102 |  | -                img_bytes, flag=self.color_type, backend=self.imdecode_backend) | 
|  | 99 | +                if self.file_client_args is not None: | 
|  | 100 | +                    file_client = fileio.FileClient.infer_client( | 
|  | 101 | +                        self.file_client_args, filename) | 
|  | 102 | +                    img_bytes = file_client.get(filename) | 
|  | 103 | +                else: | 
|  | 104 | +                    img_bytes = fileio.get( | 
|  | 105 | +                        filename, backend_args=self.backend_args) | 
|  | 106 | +                img = mmcv.imfrombytes( | 
|  | 107 | +                    img_bytes, | 
|  | 108 | +                    flag=self.color_type, | 
|  | 109 | +                    backend=self.imdecode_backend) | 
| 103 | 110 |         except Exception as e: | 
| 104 | 111 |             if self.ignore_empty: | 
| 105 | 112 |                 return None | 
| 106 | 113 |             else: | 
| 107 | 114 |                 raise e | 
|  | 115 | + | 
| 108 | 116 |         # in some cases, images are not read successfully, the img would be | 
| 109 | 117 |         # `None`, refer to https://github.com/open-mmlab/mmpretrain/issues/1427 | 
| 110 | 118 |         assert img is not None, f'failed to load image: {filename}' | 
|  | 
0 commit comments