replicate / cog-flux

Cog inference for flux models
https://replicate.com/black-forest-labs/flux-dev
Apache License 2.0
272 stars 28 forks source link

fix: aspect ratios #39

Open lucataco opened 1 week ago

lucataco commented 1 week ago

Fix for the following aspect ratios: 3:2, 5:4, and 16:9

Addresses Issue#38

zeke commented 1 week ago

Thanks for jumping on this @lucataco!

But it looks like these are still not correct?

Let's calculate the decimal value for each aspect ratio and compare it to the decimal value derived from the corresponding number pairs. We'll divide the first number by the second number in each case.

"1:1": (1024, 1024)
Aspect ratio: 1 / 1 = 1
Number pair: 1024 / 1024 = 1
Match: Yes

"16:9": (1360, 768)
Aspect ratio: 16 / 9 ≈ 1.7778
Number pair: 1360 / 768 ≈ 1.7708
Match: Close, but not exact (0.39% difference)

"21:9": (1536, 640)
Aspect ratio: 21 / 9 ≈ 2.3333
Number pair: 1536 / 640 = 2.4
Match: Close, but not exact (2.86% difference)

"3:2": (1152, 768)
Aspect ratio: 3 / 2 = 1.5
Number pair: 1152 / 768 = 1.5
Match: Yes

"2:3": (768, 1152)
Aspect ratio: 2 / 3 ≈ 0.6667
Number pair: 768 / 1152 ≈ 0.6667
Match: Yes

"4:5": (896, 1120)
Aspect ratio: 4 / 5 = 0.8
Number pair: 896 / 1120 = 0.8
Match: Yes

"5:4": (1120, 896)
Aspect ratio: 5 / 4 = 1.25
Number pair: 1120 / 896 = 1.25
Match: Yes

"3:4": (896, 1152)
Aspect ratio: 3 / 4 = 0.75
Number pair: 896 / 1152 ≈ 0.7778
Match: Close, but not exact (3.7% difference)

"4:3": (1152, 896)
Aspect ratio: 4 / 3 ≈ 1.3333
Number pair: 1152 / 896 ≈ 1.2857
Match: Close, but not exact (3.57% difference)

"9:16": (768, 1360)
Aspect ratio: 9 / 16 = 0.5625
Number pair: 768 / 1360 ≈ 0.5647
Match: Close, but not exact (0.39% difference)

"9:21": (640, 1536)
Aspect ratio: 9 / 21 ≈ 0.4286
Number pair: 640 / 1536 ≈ 0.4167
Match: Close, but not exact (2.78% difference)

In conclusion, 6 out of 11 aspect ratios match exactly with their corresponding number pairs. The other 5 are close but have small differences, ranging from 0.39% to 3.7%. These small differences are likely due to rounding to fit common screen resolutions while maintaining an approximate aspect ratio.