MCPcopy Create free account
hub / github.com/NVlabs/SegFormer / LoadImageFromFile

Class LoadImageFromFile

mmseg/datasets/pipelines/loading.py:10–86  ·  view source on GitHub ↗

Load an image from file. Required keys are "img_prefix" and "img_info" (a dict that must contain the key "filename"). Added or updated keys are "filename", "img", "img_shape", "ori_shape" (same as `img_shape`), "pad_shape" (same as `img_shape`), "scale_factor" (1.0) and "img_norm_cf

Source from the content-addressed store, hash-verified

8
9@PIPELINES.register_module()
10class LoadImageFromFile(object):
11 """Load an image from file.
12
13 Required keys are "img_prefix" and "img_info" (a dict that must contain the
14 key "filename"). Added or updated keys are "filename", "img", "img_shape",
15 "ori_shape" (same as `img_shape`), "pad_shape" (same as `img_shape`),
16 "scale_factor" (1.0) and "img_norm_cfg" (means=0 and stds=1).
17
18 Args:
19 to_float32 (bool): Whether to convert the loaded image to a float32
20 numpy array. If set to False, the loaded image is an uint8 array.
21 Defaults to False.
22 color_type (str): The flag argument for :func:`mmcv.imfrombytes`.
23 Defaults to 'color'.
24 file_client_args (dict): Arguments to instantiate a FileClient.
25 See :class:`mmcv.fileio.FileClient` for details.
26 Defaults to ``dict(backend='disk')``.
27 imdecode_backend (str): Backend for :func:`mmcv.imdecode`. Default:
28 'cv2'
29 """
30
31 def __init__(self,
32 to_float32=False,
33 color_type='color',
34 file_client_args=dict(backend='disk'),
35 imdecode_backend='cv2'):
36 self.to_float32 = to_float32
37 self.color_type = color_type
38 self.file_client_args = file_client_args.copy()
39 self.file_client = None
40 self.imdecode_backend = imdecode_backend
41
42 def __call__(self, results):
43 """Call functions to load image and get image meta information.
44
45 Args:
46 results (dict): Result dict from :obj:`mmseg.CustomDataset`.
47
48 Returns:
49 dict: The dict contains loaded image and meta information.
50 """
51
52 if self.file_client is None:
53 self.file_client = mmcv.FileClient(**self.file_client_args)
54
55 if results.get('img_prefix') is not None:
56 filename = osp.join(results['img_prefix'],
57 results['img_info']['filename'])
58 else:
59 filename = results['img_info']['filename']
60 img_bytes = self.file_client.get(filename)
61 img = mmcv.imfrombytes(
62 img_bytes, flag=self.color_type, backend=self.imdecode_backend)
63 if self.to_float32:
64 img = img.astype(np.float32)
65
66 results['filename'] = filename
67 results['ori_filename'] = results['img_info']['filename']

Callers 2

test_load_imgMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_load_imgMethod · 0.72