Skip to content

Commit

Permalink
remove dependency on scipy.misc.imresize
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangwei221 committed Jul 20, 2021
1 parent 983013c commit 1c94ea8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
3 changes: 1 addition & 2 deletions COTR/cameras/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import numpy as np
import imageio
from PIL import Image
from scipy import misc


def crop_center_max(img):
Expand Down Expand Up @@ -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)
7 changes: 3 additions & 4 deletions COTR/inference/inference_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions COTR/inference/refinement_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
9 changes: 4 additions & 5 deletions COTR/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import torch
import cv2
import matplotlib.pyplot as plt
from scipy.misc import imresize


'''
Expand All @@ -32,15 +31,15 @@ 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
img = img[..., None]
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]
Expand Down Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c94ea8

Please sign in to comment.