MCPcopy Create free account
hub / github.com/CompVis/zigma / random_shift_crop

Function random_shift_crop

datasets/video_utils.py:128–145  ·  view source on GitHub ↗

Slide along the long edge, with the short edge as crop size

(clip)

Source from the content-addressed store, hash-verified

126
127
128def 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
148def to_tensor(clip):

Callers 1

__call__Method · 0.85

Calls 2

_is_tensor_video_clipFunction · 0.85
cropFunction · 0.85

Tested by

no test coverage detected