Support ControlNet models with different number of channels in control images #3815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
I'd like to be able to load TemporalNet2 into a ControlNetModel.
This ControlNet concatenates the previous image in a video and the optical flow together to form a 6-channel tensor as the control image.
At the moment the
convert_original_controlnet_to_diffusers.py
script does not support converting the checkpoint, raising the following error due to the control image having more channels than expected:Traceback
Adding the --num_in_channels argument doesn't help as this changes the in channels for the whole UNet (?).
Diving into the ControlNetModel code, I found that the model parameter giving the above error is controlled by the
conditioning_channels
variable which wasn't exposed in the UNet config. I've added it into the UNet config creation function inconvert_from_ckpt.py
based on thehint_channels
specified in the ControlNet .yaml/.json file.I'm not 100% that
hint_channels
is the right config value to read from (not too familiar with ControlNet), but with this change I'm able to convert the TemporalNet2 checkpoint as expected and able to load it into a ControlNetModel. The results seem to work fine based on some test videos.Are there any tests I can add to verify that the change works?
@patrickvonplaten @sayakpaul
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.