Skip to content

Commit

Permalink
Introduce dim_min and dim_max to regulate input image dimensions (#…
Browse files Browse the repository at this point in the history
…15)

* Introduction of the parameters Dmin and Dmax, which regulate the input image dimensions into the model

* Rename Dmin to dim_min and Dmax to dim_max
  • Loading branch information
TheEverglow authored Oct 3, 2023
1 parent 5b43300 commit 036739a
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit 036739a

Please sign in to comment.