haofanwang / ControlNet-for-Diffusers

Transfer the ControlNet with any basemodel in diffusers🔥
MIT License
813 stars 48 forks source link

Support multiple-image inference #26

Closed zihaog0724 closed 1 year ago

zihaog0724 commented 1 year ago

Hi,

it seems like only single-image inference is supported in StableDiffusionControlNetPipeline.

For multi-image inference, one could go to the location of the diffusers package and modify the "# 2. pre-process" code block (around line 600).

original:

# 2. pre-process
sample = self.conv_in(sample)
if controlnet_hint is not None:
    sample += self.controlnet_input_hint_block(controlnet_hint)

modified:

# 2. pre-process
sample = self.conv_in(sample)
if controlnet_hint is not None:
    hint = self.controlnet_input_hint_block(controlnet_hint)
    if hint.shape[0] > 1:
        hint = hint.repeat(2, 1, 1, 1)
    sample += hint

Hope it helps.

haofanwang commented 1 year ago

Thanks for pointing out, but StableDiffusionControlNetPipeline has been officially supported in diffusers now, I will update this tutorial soon to keep pace with it.

zihaog0724 commented 1 year ago

@haofanwang Thanks. I'll close the issue.