def get_scale_factor(scale, max_size, img_h, img_w):
    """
    :param scale: min size during test
    :param max_size: max size during test
    :param img_h: orig height of img
    :param img_w: orig width
    :return: scale factor for resizing
    """
    short = min(img_w, img_h)
    large = max(img_w, img_h)
    if short <= 0:
        scale_factor = 1.0
        return scale_factor
    if scale <= 0:
        scale_factor = 1.0
    else:
        scale_factor = min(scale / short, max_size / large)
    return scale_factor