modelscope / modelscope/DiffSynth-Studio

关于Flux2klein的图像预处理gap

Open
#1,398 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
13.1k
Forks
1.3k
Avg merge
13h 12m
Merged PRs (30d)
45

Description

你好,我在diffuser库中观察到,cond image只有在大于目标尺寸1024时才会进行防缩。

condition_images = []
for img in image:
    image_width, image_height = img.size
    if image_width * image_height > 1024 * 1024:
        img = self.image_processor._resize_to_target_area(img, 1024 * 1024)
        image_width, image_height = img.size

    multiple_of = self.vae_scale_factor * 2
    image_width = (image_width // multiple_of) * multiple_of
    image_height = (image_height // multiple_of) * multiple_of
    img = self.image_processor.preprocess(img, height=image_height, width=image_width, resize_mode="crop")
    condition_images.append(img)
    height = height or image_height
    width = width or image_width

但是我在本代码仓库观察到,似乎会强制将cond防缩到1024的size

def calculate_dimensions(self, target_area, ratio):
        import math
        width = math.sqrt(target_area * ratio)
        height = width / ratio
        width = round(width / 32) * 32
        height = round(height / 32) * 32
        return width, height
    
    def crop_and_resize(self, image, target_height, target_width):
        width, height = image.size
        scale = max(target_width / width, target_height / height)
        image = torchvision.transforms.functional.resize(
            image,
            (round(height*scale), round(width*scale)),
            interpolation=torchvision.transforms.InterpolationMode.BILINEAR
        )
        image = torchvision.transforms.functional.center_crop(image, (target_height, target_width))
        return image

    def edit_image_auto_resize(self, edit_image):
        calculated_width, calculated_height = self.calculate_dimensions(1024 * 1024, edit_image.size[0] / edit_image.size[1])
        return self.crop_and_resize(edit_image, calculated_height, calculated_width)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing edit_image_auto_resize and its calculate_dimensions and crop_and_resize helpers, then compare their behavior with the condition-image preprocessing shown in the issue. Confirm whether Flux2klein should resize every image to a 1024×1024 target area or only images exceeding it; done means the chosen behavior is implemented consistently and verified against representative image sizes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.