From 1c94ea8c8ecdc2f67208ac598801dc40aac77c53 Mon Sep 17 00:00:00 2001 From: jiangwei Date: Tue, 20 Jul 2021 10:39:01 -0700 Subject: [PATCH] remove dependency on scipy.misc.imresize --- COTR/cameras/capture.py | 3 +-- COTR/inference/inference_helper.py | 7 +++---- COTR/inference/refinement_task.py | 7 +++---- COTR/utils/utils.py | 9 ++++----- readme.md | 1 - 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/COTR/cameras/capture.py b/COTR/cameras/capture.py index 802ae0b..1938524 100644 --- a/COTR/cameras/capture.py +++ b/COTR/cameras/capture.py @@ -13,7 +13,6 @@ import numpy as np import imageio from PIL import Image -from scipy import misc def crop_center_max(img): @@ -101,4 +100,4 @@ def pad_to_square_np(img, till_divisible_by=1, return_starts=False): def stretch_to_square_np(img): size = max(*img.shape[:2]) - return misc.imresize(img, (size, size), interp='bilinear') + return cv2.resize(img, (size, size), interpolation=cv2.INTER_LINEAR) diff --git a/COTR/inference/inference_helper.py b/COTR/inference/inference_helper.py index c49aa11..8163763 100644 --- a/COTR/inference/inference_helper.py +++ b/COTR/inference/inference_helper.py @@ -5,7 +5,6 @@ import torch from torchvision.transforms import functional as tvtf from tqdm import tqdm -from scipy import misc from COTR.utils import utils, debug_utils from COTR.utils.constants import MAX_SIZE @@ -16,6 +15,7 @@ THRESHOLD_PIXELS_RELATIVE = 0.02 BASE_ZOOM = 1.0 THRESHOLD_AREA = 0.02 +LARGE_GPU = True def find_prediction_loop(arr): @@ -103,12 +103,11 @@ def get_patch_centered_at(img, pos, scale=1.0, return_content=True, img_shape=No def cotr_patch_flow_exhaustive(model, patches_a, patches_b): def one_pass(model, img_a, img_b): - LARGE_GPU = True device = next(model.parameters()).device img_a = crop_center_max_np(img_a) img_b = crop_center_max_np(img_b) - img_a = misc.imresize(img_a, (MAX_SIZE, MAX_SIZE), interp='bilinear') - img_b = misc.imresize(img_b, (MAX_SIZE, MAX_SIZE), interp='bilinear') + img_a = cv2.resize(img_a, (MAX_SIZE, MAX_SIZE), interpolation=cv2.INTER_LINEAR) + img_b = cv2.resize(img_b, (MAX_SIZE, MAX_SIZE), interpolation=cv2.INTER_LINEAR) img = two_images_side_by_side(img_a, img_b) img = tvtf.normalize(tvtf.to_tensor(img), (0.485, 0.456, 0.406), (0.229, 0.224, 0.225)).float()[None] img = img.to(device) diff --git a/COTR/inference/refinement_task.py b/COTR/inference/refinement_task.py index fa76303..c3bb682 100644 --- a/COTR/inference/refinement_task.py +++ b/COTR/inference/refinement_task.py @@ -3,9 +3,8 @@ import numpy as np import torch from torchvision.transforms import functional as tvtf -import scipy -from scipy import misc import imageio +import cv2 from COTR.inference.inference_helper import BASE_ZOOM, THRESHOLD_PIXELS_RELATIVE, get_patch_centered_at, two_images_side_by_side, find_prediction_loop from COTR.utils import debug_utils, utils @@ -115,8 +114,8 @@ def get_task(self): assert img_from.shape[0] == img_from.shape[1] assert img_to.shape[0] == img_to.shape[1] - img_from = misc.imresize(img_from, (MAX_SIZE, MAX_SIZE), interp='bilinear') - img_to = misc.imresize(img_to, (MAX_SIZE, MAX_SIZE), interp='bilinear') + img_from = cv2.resize(img_from, (MAX_SIZE, MAX_SIZE), interpolation=cv2.INTER_LINEAR) + img_to = cv2.resize(img_to, (MAX_SIZE, MAX_SIZE), interpolation=cv2.INTER_LINEAR) img = two_images_side_by_side(img_from, img_to) img = tvtf.normalize(tvtf.to_tensor(img), (0.485, 0.456, 0.406), (0.229, 0.224, 0.225)).float() diff --git a/COTR/utils/utils.py b/COTR/utils/utils.py index 671fcb1..b000189 100644 --- a/COTR/utils/utils.py +++ b/COTR/utils/utils.py @@ -9,7 +9,6 @@ import torch import cv2 import matplotlib.pyplot as plt -from scipy.misc import imresize ''' @@ -32,7 +31,7 @@ def fix_randomness(seed=42): np.random.seed(seed) -def float_image_resize(img, shape, interp='bilinear'): +def float_image_resize(img, shape, interp=cv2.INTER_LINEAR): missing_channel = False if len(img.shape) == 2: missing_channel = True @@ -40,7 +39,7 @@ def float_image_resize(img, shape, interp='bilinear'): layers = [] img = img.transpose(2, 0, 1) for l in img: - l = imresize(l, shape, interp=interp, mode='F') + l = cv2.resize(l, shape, interpolation=interp) layers.append(l) if missing_channel: return np.stack(layers, axis=-1)[..., 0] @@ -175,8 +174,8 @@ def visualize_corrs(img1, img2, corrs, mask=None): if w > max_w: scale1 *= max_w / w scale2 *= max_w / w - img1 = imresize(img1, scale1) - img2 = imresize(img2, scale2) + img1 = cv2.resize(img1, (0,0), fx=scale1, fy=scale1) + img2 = cv2.resize(img2, (0,0), fx=scale2, fy=scale2) x1, x2 = corrs[:, :2], corrs[:, 2:] h1, w1 = img1.shape[:2] diff --git a/readme.md b/readme.md index 46bbcb9..6a9f05d 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,6 @@ Our implementation is based on PyTorch. Install the conda environment by: `conda Activate the environment by: `conda activate cotr_env`. -Notice that we use `scipy=1.2.1` . ### 2. Download the pretrained weights