YiYiXu commited on
Commit
348ced6
·
verified ·
1 Parent(s): d08c29f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md CHANGED
@@ -8,4 +8,60 @@ image_processor = ModularPipeline.from_pretrained("YiYiXu/WanImageProcessor", tr
8
  image = image_processor(
9
  image="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/wan_i2v_input.JPG",
10
  max_area=1280*704, output="processed_image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ```
 
8
  image = image_processor(
9
  image="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/wan_i2v_input.JPG",
10
  max_area=1280*704, output="processed_image")
11
+ ```
12
+
13
+
14
+ this is the function
15
+
16
+ ```py
17
+ # copied from https://github.com/Wan-Video/Wan2.2/blob/388807310646ed5f318a99f8e8d9ad28c5b65373/wan/utils/utils.py#L136
18
+ def best_output_size(w, h, dw, dh, expected_area):
19
+ # float output size
20
+ ratio = w / h
21
+ ow = (expected_area * ratio)**0.5
22
+ oh = expected_area / ow
23
+
24
+ # process width first
25
+ ow1 = int(ow // dw * dw)
26
+ oh1 = int(expected_area / ow1 // dh * dh)
27
+ assert ow1 % dw == 0 and oh1 % dh == 0 and ow1 * oh1 <= expected_area
28
+ ratio1 = ow1 / oh1
29
+
30
+ # process height first
31
+ oh2 = int(oh // dh * dh)
32
+ ow2 = int(expected_area / oh2 // dw * dw)
33
+ assert oh2 % dh == 0 and ow2 % dw == 0 and ow2 * oh2 <= expected_area
34
+ ratio2 = ow2 / oh2
35
+
36
+ # compare ratios
37
+ if max(ratio / ratio1, ratio1 / ratio) < max(ratio / ratio2,
38
+ ratio2 / ratio):
39
+ return ow1, oh1
40
+ else:
41
+ return ow2, oh2
42
+
43
+
44
+
45
+ @property
46
+ def expected_configs(self):
47
+ return [
48
+ ConfigSpec(name="patch_size", default=(1, 2, 2)),
49
+ ConfigSpec(name="vae_stride", default=(4, 16, 16)),
50
+ ]
51
+
52
+ image = load_image(block_state.image).convert("RGB")
53
+ max_area = 1280*704
54
+
55
+ ih, iw = image.height, image.width
56
+ dh, dw = pipe.transformer.config.patch_size[1] * pipe.vae_scale_factor_spatial, pipe.transformer.config.patch_size[2] * pipe.vae_scale_factor_spatial
57
+ ow, oh = best_output_size(iw, ih, dw, dh, max_area)
58
+
59
+ scale = max(ow / iw, oh / ih)
60
+ resized_image = image.resize((round(iw * scale), round(ih * scale)), Image.LANCZOS)
61
+
62
+ # center-crop
63
+ x1 = (resized_image.width - ow) // 2
64
+ y1 = (resized_image.height - oh) // 2
65
+ image = resized_image.crop((x1, y1, x1 + ow, y1 + oh))
66
+
67
  ```