Slide along the long edge, with the short edge as crop size
(clip)
| 126 | |
| 127 | |
| 128 | def random_shift_crop(clip): |
| 129 | """ |
| 130 | Slide along the long edge, with the short edge as crop size |
| 131 | """ |
| 132 | if not _is_tensor_video_clip(clip): |
| 133 | raise ValueError("clip should be a 4D torch.tensor") |
| 134 | h, w = clip.size(-2), clip.size(-1) |
| 135 | |
| 136 | if h <= w: |
| 137 | short_edge = h |
| 138 | else: |
| 139 | short_edge = w |
| 140 | |
| 141 | th, tw = short_edge, short_edge |
| 142 | |
| 143 | i = torch.randint(0, h - th + 1, size=(1,)).item() |
| 144 | j = torch.randint(0, w - tw + 1, size=(1,)).item() |
| 145 | return crop(clip, i, j, th, tw) |
| 146 | |
| 147 | |
| 148 | def to_tensor(clip): |
no test coverage detected