(self, img)
| 324 | return self.pipeline |
| 325 | |
| 326 | def prepare_src_image(self, img): |
| 327 | h, w = img.shape[:2] |
| 328 | input_shape = [256,256] |
| 329 | if h != input_shape[0] or w != input_shape[1]: |
| 330 | if 256 < h: interpolation = cv2.INTER_AREA |
| 331 | else: interpolation = cv2.INTER_LINEAR |
| 332 | x = cv2.resize(img, (input_shape[0], input_shape[1]), interpolation = interpolation) |
| 333 | else: |
| 334 | x = img.copy() |
| 335 | |
| 336 | if x.ndim == 3: |
| 337 | x = x[np.newaxis].astype(np.float32) / 255. # HxWx3 -> 1xHxWx3, normalized to 0~1 |
| 338 | elif x.ndim == 4: |
| 339 | x = x.astype(np.float32) / 255. # BxHxWx3, normalized to 0~1 |
| 340 | else: |
| 341 | raise ValueError(f'img ndim should be 3 or 4: {x.ndim}') |
| 342 | x = np.clip(x, 0, 1) # clip to 0~1 |
| 343 | x = torch.from_numpy(x).permute(0, 3, 1, 2) # 1xHxWx3 -> 1x3xHxW |
| 344 | x = x.to(get_device()) |
| 345 | return x |
| 346 | |
| 347 | def GetMaskImg(self): |
| 348 | if self.mask_img is None: |
no test coverage detected