Skip to content

data_utils

Functions:

fastvideo.models.dits.hyworld.data_utils.get_closest_ratio

get_closest_ratio(height: float, width: float, ratios: list, buckets: list)

Get the closest ratio in the buckets.

Parameters:

Name Type Description Default
height float

video height

required
width float

video width

required
ratios list

video aspect ratio

required
buckets list

buckets generated by generate_crop_size_list

required

Returns:

Type Description

the closest size in the buckets and the corresponding ratio

Source code in fastvideo/models/dits/hyworld/data_utils.py
def get_closest_ratio(height: float, width: float, ratios: list, buckets: list):
    """
    Get the closest ratio in the buckets.

    Args:
        height (float): video height
        width (float): video width
        ratios (list): video aspect ratio
        buckets (list): buckets generated by `generate_crop_size_list`

    Returns:
        the closest size in the buckets and the corresponding ratio
    """
    aspect_ratio = float(height) / float(width)

    ratios_array = np.array(ratios)
    closest_ratio_id = np.abs(ratios_array - aspect_ratio).argmin()
    closest_size = buckets[closest_ratio_id]
    closest_ratio = ratios_array[closest_ratio_id]

    return closest_size, closest_ratio