Skip to content

Commit

Permalink
Merge pull request #1008 from Cauldrath/zero_height_error
Browse files Browse the repository at this point in the history
Fix zero height buckets
  • Loading branch information
kohya-ss authored Dec 20, 2023
2 parents 35e5424 + f8360a4 commit 1519e30
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions library/model_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,19 +1307,19 @@ def load_vae(vae_id, dtype):

def make_bucket_resolutions(max_reso, min_size=256, max_size=1024, divisible=64):
max_width, max_height = max_reso
max_area = (max_width // divisible) * (max_height // divisible)
max_area = max_width * max_height

resos = set()

size = int(math.sqrt(max_area)) * divisible
resos.add((size, size))
width = int(math.sqrt(max_area) // divisible) * divisible
resos.add((width, width))

size = min_size
while size <= max_size:
width = size
height = min(max_size, (max_area // (width // divisible)) * divisible)
resos.add((width, height))
resos.add((height, width))
width = min_size
while width <= max_size:
height = min(max_size, int((max_area // width) // divisible) * divisible)
if height > 0:
resos.add((width, height))
resos.add((height, width))

# # make additional resos
# if width >= height and width - divisible >= min_size:
Expand All @@ -1329,7 +1329,7 @@ def make_bucket_resolutions(max_reso, min_size=256, max_size=1024, divisible=64)
# resos.add((width, height - divisible))
# resos.add((height - divisible, width))

size += divisible
width += divisible

resos = list(resos)
resos.sort()
Expand Down

0 comments on commit 1519e30

Please sign in to comment.