Skip to content

Commit 6c7da47

Browse files
committed
Fix crop for small videos.
1 parent f45d714 commit 6c7da47

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

torchvision/transforms/_presets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ def forward(self, vid: Tensor) -> Tensor:
113113
if self.crop_size is not None:
114114
if self.crop_mode == "center_crop":
115115
vid = F.center_crop(vid, self.crop_size)
116-
else:
116+
elif vid.shape[-2] >= self.crop_size[-2] and vid.shape[-1] >= self.crop_size[-1]:
117117
crops = (
118118
list(F.five_crop(vid, self.crop_size))
119119
if self.crop_mode == "five_crop"
120120
else list(F.ten_crop(vid, self.crop_size))
121121
)
122122
vid = torch.cat(crops)
123+
else:
124+
vid = F.resize(vid, self.crop_size, interpolation=self.interpolation)
123125
vid = F.convert_image_dtype(vid, torch.float)
124126
vid = F.normalize(vid, mean=self.mean, std=self.std)
125127
H, W = vid.shape[-2:]

0 commit comments

Comments
 (0)