Skip to content

Commit

Permalink
Remove pad_max_tiles in CLIP inference (pytorch#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucylq authored Oct 16, 2024
1 parent 6a8a027 commit 7d29c21
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions torchtune/models/clip/inference/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from torchtune.modules.transforms.vision_utils.get_inscribed_size import (
get_inscribed_size,
)
from torchtune.modules.transforms.vision_utils.pad_dim_to_size import pad_dim_to_size
from torchtune.modules.transforms.vision_utils.tile_crop import tile_crop

from torchvision.transforms.v2 import functional as F
Expand All @@ -35,15 +34,13 @@ def __init__(
tile_size: int,
max_num_tiles: int,
antialias: bool,
pad_max_tiles: bool = False,
):
super().__init__()
self.resample = resample
self.image_mean = image_mean
self.image_std = image_std
self.tile_size = tile_size
self.max_num_tiles = max_num_tiles
self.pad_tile_size = max_num_tiles if pad_max_tiles else None
self.antialias = antialias
self.tile_crop = tile_crop
self.pad = torch.nn.functional.pad
Expand Down Expand Up @@ -121,9 +118,6 @@ def forward(
# Reshape.
tiles = self.tile_crop(output, self.tile_size)

if self.pad_tile_size:
tiles = pad_dim_to_size(tiles, size=self.pad_tile_size, dim=0)

# Calculate aspect ratio.
aspect_ratio = canvas_size // self.tile_size

Expand Down Expand Up @@ -181,7 +175,6 @@ class CLIPImageTransform:
If False, it will pick the resolution that minimizes downscaling, including no downscaling at all.
In this case, the image will only be upscaled if it's size < tile_size. Default False.
antialias (bool): Whether to apply antialiasing when resizing the image. Default True.
pad_max_tiles (bool): If True, the image will be padded to have tiles == max_num_tiles.
Examples:
>>> image_transform = CLIPImageTransform(
... image_mean=None,
Expand Down Expand Up @@ -212,7 +205,6 @@ def __init__(
resample: str = "bilinear",
resize_to_max_canvas: bool = False,
antialias: bool = True,
pad_max_tiles: bool = False,
) -> None:

# get_canvas_best_fit
Expand Down Expand Up @@ -258,7 +250,6 @@ def __init__(
tile_size=self.tile_size,
max_num_tiles=self.max_num_tiles,
antialias=self.antialias,
pad_max_tiles=pad_max_tiles,
)

def __call__(self, *, image: Image.Image, **kwargs) -> Mapping[str, Any]:
Expand Down

0 comments on commit 7d29c21

Please sign in to comment.