def test_resize_transform(self): input_shapes = [(100, 100), (100, 100, 1), (100, 100, 3)] output_shapes = [(200, 200), (200, 200, 1), (200, 200, 3)] for in_shape, out_shape in zip(input_shapes, output_shapes): in_img = np.random.randint(0, 255, size=in_shape, dtype=np.uint8) tfm = T.ResizeTransform(in_shape[0], in_shape[1], out_shape[0], out_shape[1]) out_img = tfm.apply_image(in_img) self.assertEqual(out_img.shape, out_shape)
def run_img(img): logger.debug('img.shape: {}'.format(img.shape)) img = img[:, :, ::-1] if self.fix_ratio: transform = T.ResizeTransform(*img.shape[:2], *[self.cfg.INPUT.MIN_SIZE_TEST]*2, Image.BILINEAR) else: transform = self.transform_gen.get_transform(img) img = apply_image(transform, img) input_y, input_x = img.shape[:2] if _boxes is None: boxes = [[0, 0, input_x, input_y]] else: boxes = np.asarray(_boxes).reshape(-1, 2) boxes = transform.apply_coords(boxes) boxes = boxes.reshape(-1, 4) with torch.no_grad(): img = torch.as_tensor(img.astype('float32').transpose(2, 0, 1)) model = self.model images = model.preprocess_image([{'image': img}]) features = model.backbone(images.tensor) features = [features[f] for f in model.roi_heads.in_features] x = model.roi_heads.pooler(features, [Boxes(torch.tensor(boxes, dtype=torch.float32, device=model.device))]) x = model.roi_heads.res5[:res5_i](x) return x.cpu().numpy().transpose(0, 2, 3, 1)
def get_transform(self, image, sem_seg): return T.ResizeTransform(input_shape[0], input_shape[1], output_shape[0], output_shape[1])
def get_transform(self, image): old_h, old_w = image.shape[:2] new_h, new_w = int(old_h * np.random.rand()), int(old_w * 1.5) return T.ResizeTransform(old_h, old_w, new_h, new_w)