MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / _get_param_spatial_crop

Function _get_param_spatial_crop

slowfast/datasets/transform.py:535–574  ·  view source on GitHub ↗

Given scale, ratio, height and width, return sampled coordinates of the videos.

(
    scale, ratio, height, width, num_repeat=10, log_scale=True, switch_hw=False
)

Source from the content-addressed store, hash-verified

533
534
535def _get_param_spatial_crop(
536 scale, ratio, height, width, num_repeat=10, log_scale=True, switch_hw=False
537):
538 """
539 Given scale, ratio, height and width, return sampled coordinates of the videos.
540 """
541 for _ in range(num_repeat):
542 area = height * width
543 target_area = random.uniform(*scale) * area
544 if log_scale:
545 log_ratio = (math.log(ratio[0]), math.log(ratio[1]))
546 aspect_ratio = math.exp(random.uniform(*log_ratio))
547 else:
548 aspect_ratio = random.uniform(*ratio)
549
550 w = int(round(math.sqrt(target_area * aspect_ratio)))
551 h = int(round(math.sqrt(target_area / aspect_ratio)))
552
553 if np.random.uniform() < 0.5 and switch_hw:
554 w, h = h, w
555
556 if 0 < w <= width and 0 < h <= height:
557 i = random.randint(0, height - h)
558 j = random.randint(0, width - w)
559 return i, j, h, w
560
561 # Fallback to central crop
562 in_ratio = float(width) / float(height)
563 if in_ratio < min(ratio):
564 w = width
565 h = int(round(w / min(ratio)))
566 elif in_ratio > max(ratio):
567 h = height
568 w = int(round(h * max(ratio)))
569 else: # whole image
570 w = width
571 h = height
572 i = (height - h) // 2
573 j = (width - w) // 2
574 return i, j, h, w
575
576
577def random_resized_crop(

Callers 3

random_resized_cropFunction · 0.85
random_sized_crop_imgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected