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

Method test_load_seg_custom_classes

tests/test_data/test_loading.py:104–198  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

102 assert results['gt_semantic_seg'].dtype == np.uint8
103
104 def test_load_seg_custom_classes(self):
105
106 test_img = np.random.rand(10, 10)
107 test_gt = np.zeros_like(test_img)
108 test_gt[2:4, 2:4] = 1
109 test_gt[2:4, 6:8] = 2
110 test_gt[6:8, 2:4] = 3
111 test_gt[6:8, 6:8] = 4
112
113 tmp_dir = tempfile.TemporaryDirectory()
114 img_path = osp.join(tmp_dir.name, 'img.jpg')
115 gt_path = osp.join(tmp_dir.name, 'gt.png')
116
117 mmcv.imwrite(test_img, img_path)
118 mmcv.imwrite(test_gt, gt_path)
119
120 # test only train with label with id 3
121 results = dict(
122 img_info=dict(filename=img_path),
123 ann_info=dict(seg_map=gt_path),
124 label_map={
125 0: 0,
126 1: 0,
127 2: 0,
128 3: 1,
129 4: 0
130 },
131 seg_fields=[])
132
133 load_imgs = LoadImageFromFile()
134 results = load_imgs(copy.deepcopy(results))
135
136 load_anns = LoadAnnotations()
137 results = load_anns(copy.deepcopy(results))
138
139 gt_array = results['gt_semantic_seg']
140
141 true_mask = np.zeros_like(gt_array)
142 true_mask[6:8, 2:4] = 1
143
144 assert results['seg_fields'] == ['gt_semantic_seg']
145 assert gt_array.shape == (10, 10)
146 assert gt_array.dtype == np.uint8
147 np.testing.assert_array_equal(gt_array, true_mask)
148
149 # test only train with label with id 4 and 3
150 results = dict(
151 img_info=dict(filename=img_path),
152 ann_info=dict(seg_map=gt_path),
153 label_map={
154 0: 0,
155 1: 0,
156 2: 0,
157 3: 2,
158 4: 1
159 },
160 seg_fields=[])
161

Callers

nothing calls this directly

Calls 2

LoadImageFromFileClass · 0.90
LoadAnnotationsClass · 0.90

Tested by

no test coverage detected