Skip to content
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
10 changes: 5 additions & 5 deletions wpodnet/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def __init__(self, wpodnet: WPODNet):
self.wpodnet = wpodnet
self.wpodnet.eval()

def _resize_to_fixed_ratio(self, image: Image.Image) -> Image.Image:
def _resize_to_fixed_ratio(self, image: Image.Image, dim_min: int, dim_max: int) -> Image.Image:
h, w = image.height, image.width

wh_ratio = max(h, w) / min(h, w)
side = int(wh_ratio * 288)
bound_dim = min(side + side % self._stride, 608)
side = int(wh_ratio * dim_min)
bound_dim = min(side + side % self._stride, dim_max)

factor = bound_dim / min(h, w)
reg_w, reg_h = int(w * factor), int(h * factor)
Expand Down Expand Up @@ -103,12 +103,12 @@ def _get_bounds(self, affines: np.ndarray, anchor_y: int, anchor_x: int, scaling

return np.transpose(bounds)

def predict(self, image: Image.Image, scaling_ratio: float = 1.0) -> Prediction:
def predict(self, image: Image.Image, scaling_ratio: float = 1.0, dim_min: int = 288, dim_max: int = 608) -> Prediction:
orig_h, orig_w = image.height, image.width

# Resize the image to fixed ratio
# This operation is convienence for setup the anchors
resized = self._resize_to_fixed_ratio(image)
resized = self._resize_to_fixed_ratio(image, dim_min=dim_min, dim_max=dim_max)
resized = self._to_torch_image(resized)
resized = resized.to(self.wpodnet.device)

Expand Down