Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

keep the resize function the same in test time the same with training time #798

Merged
merged 1 commit into from
May 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions demo/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,38 @@
from maskrcnn_benchmark import layers as L
from maskrcnn_benchmark.utils import cv2_util

class Resize(object):
def __init__(self, min_size, max_size):
self.min_size = min_size
self.max_size = max_size

# modified from torchvision to add support for max size
def get_size(self, image_size):
w, h = image_size
size = self.min_size
max_size = self.max_size
if max_size is not None:
min_original_size = float(min((w, h)))
max_original_size = float(max((w, h)))
if max_original_size / min_original_size * size > max_size:
size = int(round(max_size * min_original_size / max_original_size))

if (w <= h and w == size) or (h <= w and h == size):
return (h, w)

if w < h:
ow = size
oh = int(size * h / w)
else:
oh = size
ow = int(size * w / h)

return (oh, ow)

def __call__(self, image):
size = self.get_size(image.size)
image = F.resize(image, size)
return image
class COCODemo(object):
# COCO categories for pretty print
CATEGORIES = [
Expand Down Expand Up @@ -147,11 +178,12 @@ def build_transform(self):
normalize_transform = T.Normalize(
mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD
)

min_size = cfg.INPUT.MIN_SIZE_TEST
max_size = cfg.INPUT.MAX_SIZE_TEST
transform = T.Compose(
[
T.ToPILImage(),
T.Resize(self.min_image_size),
Resize(min_size, max_size),
T.ToTensor(),
to_bgr_transform,
normalize_transform,
Expand Down