(seg_dir, factor, scale_size=[480])
| 222 | |
| 223 | |
| 224 | def read_seg(seg_dir, factor, scale_size=[480]): |
| 225 | seg = Image.open(seg_dir) |
| 226 | _w, _h = seg.size # note PIL.Image.Image's size is (w, h) |
| 227 | if len(scale_size) == 1: |
| 228 | if(_w > _h): |
| 229 | _th = scale_size[0] |
| 230 | _tw = (_th * _w) / _h |
| 231 | _tw = int((_tw // 64) * 64) |
| 232 | else: |
| 233 | _tw = scale_size[0] |
| 234 | _th = (_tw * _h) / _w |
| 235 | _th = int((_th // 64) * 64) |
| 236 | else: |
| 237 | _th = scale_size[1] |
| 238 | _tw = scale_size[0] |
| 239 | small_seg = np.array(seg.resize((_tw // factor, _th // factor), 0)) |
| 240 | small_seg = torch.from_numpy(small_seg.copy()).contiguous().float().unsqueeze(0) |
| 241 | return to_one_hot(small_seg), np.asarray(seg) |
| 242 | |
| 243 | |
| 244 | def color_normalize(x, mean=[0.485, 0.456, 0.406], std=[0.228, 0.224, 0.225]): |
no test coverage detected