By ratio
Browse files123456789101112131415161718192021222324252627282930bucket_options = {640: [(416, 960),(448, 864),(480, 832),(512, 768),(544, 704),(576, 672),(608, 640),(640, 608),(672, 576),(704, 544),(768, 512),(832, 480),(864, 448),(960, 416),],}def find_nearest_bucket(h, w, resolution=640):min_metric = float('inf')best_bucket = Nonefor (bucket_h, bucket_w) in bucket_options[resolution]:metric = abs(h * bucket_w - w * bucket_h)if metric <= min_metric:min_metric = metricbest_bucket = (bucket_h, bucket_w)return best_bucket1234def find_nearest_bucket(h, w, resolution=640):rate = ((resolution**2) / (h * w))**(1/2)return (int(h * rate), int(w * rate))
diffusers_helper/bucket_tools.py+4-30