|
22 | 22 | torch_device_module = getattr(torch, AI_DEVICE) |
23 | 23 |
|
24 | 24 |
|
25 | | -def resize_image(img, resolution): |
| 25 | +def resize_image(img, resolution, bucket_shape=None): |
26 | 26 | assert resolution in ["480p", "540p", "720p"] |
27 | | - bucket_config = { |
28 | | - 0.667: np.array([[480, 832], [544, 960], [720, 1280]], dtype=np.int64), |
29 | | - 1.500: np.array([[832, 480], [960, 544], [1280, 720]], dtype=np.int64), |
30 | | - 1.000: np.array([[480, 480], [576, 576], [720, 720]], dtype=np.int64), |
31 | | - } |
| 27 | + if bucket_shape is None: |
| 28 | + bucket_config = { |
| 29 | + 0.667: np.array([[480, 832], [544, 960], [720, 1280]], dtype=np.int64), |
| 30 | + 1.500: np.array([[832, 480], [960, 544], [1280, 720]], dtype=np.int64), |
| 31 | + 1.000: np.array([[480, 480], [576, 576], [960, 960]], dtype=np.int64), |
| 32 | + } |
| 33 | + else: |
| 34 | + bucket_config = {} |
| 35 | + for ratio, resolutions in bucket_shape.items(): |
| 36 | + bucket_config[float(ratio)] = np.array(resolutions, dtype=np.int64) |
32 | 37 | ori_height = img.shape[-2] |
33 | 38 | ori_weight = img.shape[-1] |
34 | 39 | ori_ratio = ori_height / ori_weight |
@@ -246,7 +251,7 @@ def read_image_input(self, img_path): |
246 | 251 | self.input_info.original_size = img_ori.size |
247 | 252 |
|
248 | 253 | if self.config.get("resize_mode", None) == "adaptive": |
249 | | - img, h, w = resize_image(img, self.config.get("resolution", "480p")) |
| 254 | + img, h, w = resize_image(img, self.config.get("resolution", "480p"), self.config.get("bucket_shape", None)) |
250 | 255 | logger.info(f"resize_image target_h: {h}, target_w: {w}") |
251 | 256 | patched_h = h // self.config["vae_stride"][1] // self.config["patch_size"][1] |
252 | 257 | patched_w = w // self.config["vae_stride"][2] // self.config["patch_size"][2] |
|
0 commit comments