diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

AttributeError: type object 'Flux2ImageProcessor' has no attribute 'image_processor'

Open hannalaguilar opened this issue 4 weeks ago • 1 comments

Describe the bug

I'm trying to run train_dreambooth_flux2_img2img.py from the DreamBooth examples, but I encountered this error. I inspected the Flux2ImageProcessor code in diffusers.pipelines.flux2.image_processor, and it turns out that Flux2ImageProcessor does not have an image_processor attribute. The same is true for the VaeImageProcessor class.

from diffusers.pipelines.flux2.image_processor import Flux2ImageProcessor


File "/home/datascience/flux2_img2img/train_lora.py", line 358, in __init__
[rank1]:     dest_image = Flux2ImageProcessor.image_processor._resize_to_target_area(dest_image, 1024 * 1024)
[rank1]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]: AttributeError: type object 'Flux2ImageProcessor' has no attribute 'image_processor'

Reproduction

accelerate launch train_dreambooth_lora_flux2_img2img.py \
  --pretrained_model_name_or_path=black-forest-labs/FLUX.2-dev  \
  --output_dir="flux2-i2i" \
  --dataset_name="kontext-community/relighting" \
  --image_column="output" --cond_image_column="file_name" --caption_column="instruction" \
  --do_fp8_training \
  --gradient_checkpointing \
  --remote_text_encoder \
  --cache_latents \
  --resolution=1024 \
  --train_batch_size=1 \
  --guidance_scale=1 \
  --gradient_accumulation_steps=4 \
  --gradient_checkpointing \
  --optimizer="adamw" \
  --use_8bit_adam \
  --cache_latents \
  --learning_rate=1e-4 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=200 \
  --max_train_steps=1000 \
  --rank=16\
  --seed="0" 

### Logs

```shell

System Info

diffusers 0.36.0.dev0

Who can help?

No response

hannalaguilar avatar Dec 03 '25 00:12 hannalaguilar

What I did to solve it was to update these lines of code:

if image_width * image_height > 1024 * 1024:
    dest_image = Flux2ImageProcessor._resize_to_target_area(dest_image, 1024 * 1024)  # MODIFY
    image_width, image_height = dest_image.size

multiple_of = 2 ** (4 - 1)  # 2 ** (len(vae.config.block_out_channels) - 1), temp!
image_width = (image_width // multiple_of) * multiple_of
image_height = (image_height // multiple_of) * multiple_of

# MODIFY
img_processor_flux2 = Flux2ImageProcessor()
dest_image = img_processor_flux2.preprocess(
    image=dest_image,
    height=image_height,
    width=image_width,
    resize_mode="crop"
)
dest_image = img_processor_flux2.postprocess(dest_image)[0]

hannalaguilar avatar Dec 03 '25 11:12 hannalaguilar