Incorrect buckets sizes are generated
In experimenting with adding native qwen resolutions to the bucket sizes I discovered that the function get_bucket_sizes is adding new and incorrect resolutions to the buckets list. I believe this is due to a unintended type promotion. Basically the mod operations that check for matching width and height will rarely equal 0 because it is resulting in a float value. So, the comparison should instead use a very small value close to zero or the int type should be explicit.
The result is that this function adds new resolution buckets with often wildly different aspect ratios than the input image. Images that should in fact match an existing resolution will end up in a bucket for the newly added resolution.
I am assuming this may have some affect on training quality.
https://github.com/ostris/ai-toolkit/blob/ee206cfa18b52f91b8b4cba9395c687f050d2c4e/toolkit/buckets.py#L59
Edit:
In other words, if I create a dataset where all the images conform to a standard SDXL width and height, they will still get put in random buckets and resized.
Any luck finding a fix? Let me know!
不知道是不是一个问题,我问了下AI解决了我的问题. 我的训练集是768*1024的图片,把bucket.py文件改成了,这样.
resolutions SDXL was trained on with a 1024x1024 base resolution
resolutions_1024: List[BucketResolution] = [ # SDXL Base resolution {"width": 1024, "height": 1024}, # SDXL Resolutions, widescreen
# SDXL Resolutions, portrait
{"width": 768, "height": 1024},
]
def get_bucket_sizes(resolution: int = 768, divisibility: int = 64) -> List[BucketResolution]: # determine scaler form 1024 to resolution scaler = resolution / 1024
bucket_size_list = []
for bucket in resolutions_1024:
# must be divisible by 8
width = int(bucket["width"] * scaler)
height = int(bucket["height"] * scaler)
if width % divisibility != 0:
width = width - (width % divisibility)
if height % divisibility != 0:
height = height - (height % divisibility)
bucket_size_list.append({"width": width, "height": height})
#return bucket_size_list
return [
{"width": 768, "height": 1024},
]
输出就符合我的要求了,
100%|##########| 165/165 [00:00<00:00, 32480.41it/s]
- Found 165 images
- adding x axis flips
- Found 330 images after adding flips Bucket sizes for /root/ai-toolkit/datasets/kkgrilplus: 768x1024: 330 files 1 buckets made
I used chatgpt to fix it. Please replace the contents of buckets.py with the code from this link.-- https://pastebin.com/Ni573Afd