Skip to content

Conversation

@Justin900429
Copy link
Contributor

Summary

Fixes an AttributeError in VisualClozePipeline where the code attempted to access a non-existent height function on VisualClozeProcessor. The pipeline now calls the correct resizing utility (_resize_and_crop) during preprocessing.

if len(target_position) > 1 and sum(target_position) > 1:
new_w = resize_size[n_samples - 1][0] or 384
for i in range(len(processed_images)):
for j in range(len(processed_images[i])):
if processed_images[i][j] is not None:
new_h = int(processed_images[i][j].height * (new_w / processed_images[i][j].width))
new_w = int(new_w / 16) * 16
new_h = int(new_h / 16) * 16
processed_images[i][j] = self.height(processed_images[i][j], new_h, new_w)

This error occurs only when generating more than one image.

Reproduction

from diffusers import VisualClozePipeline
from PIL import Image
import torch

image_paths = [
    [
        Image.new("RGB", (384, 384), (0, 0, 0)),
        Image.new("RGB", (384, 384), (0, 0, 0)),
        Image.new("RGB", (384, 384), (0, 0, 0)),
    ],
    [
        Image.new("RGB", (384, 384), (0, 0, 0)),
        None,
        None,
    ],
]

task_prompt = "test"
content_prompt = None

pipe = VisualClozePipeline.from_pretrained(
    "VisualCloze/VisualClozePipeline-384", resolution=384, torch_dtype=torch.bfloat16
).to("cuda")

image_result = pipe(
    task_prompt=task_prompt,
    content_prompt=content_prompt,
    image=image_paths,
    upsampling_width=512,
    upsampling_height=512,
    upsampling_strength=0.0,
    guidance_scale=30,
    num_inference_steps=30,
    max_sequence_length=512,
    generator=torch.Generator("cuda").manual_seed(0),
).images[0]
  • Error:
AttributeError: 'VisualClozeProcessor' object has no attribute 'height'

@yiyixuxu @asomoza

Copy link
Contributor

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me! Just curious, why calling self._resize_and_crop and not self.resize?

@Justin900429
Copy link
Contributor Author

Justin900429 commented Aug 18, 2025

Thanks for the reply!

Not sure which one is the author’s intended approach, but since they use _resize_and_crop above for the same function, I just followed their implementation.

Reference:

target = self._resize_and_crop(input_images[i][j], resize_size[i][0], resize_size[i][1])

Edit:

In the authors’ original repo, they apply resize first and then perform a center crop. Therefore, using _resize_and_crop better aligns with their original implementation. (Check here)

@Justin900429
Copy link
Contributor Author

Gentle ping — would love some feedback on this when time permits.
Totally understand maintainers are busy, happy to adjust things if needed.
@a-r-r-o-w

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@a-r-r-o-w
Copy link
Contributor

@Justin900429 sorry about the delay, i forgot to merge

@a-r-r-o-w a-r-r-o-w merged commit 55f0b3d into huggingface:main Sep 10, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants