Add Anima regional control support#2524
Conversation
|
I don't think this is a good way to add it - Regions are already the mechanism to define regional prompts, adding another way that is somehow related but needs to be setup manually on top is not intuitive (and also a hassle). I will look at the attention couple PR in tooling nodes and hopefully get around to testing it soon. Don't have access to my GPU at home atm so might take a bit. Definitely want to try and get that in and see how it performs. If the control lllite is needed on top, it should be implemented as part of using regions, without any further setup or knowledge required on user side. But it will increase code complexity quite a bit, and without being able to actually assign prompts to colors in the control image it seems a bit random. I'm not really sure what the control model actually learned here...? Would be interested what your validation looked like. |
|
The controlnet model originally started as an experiment for training a regional control model, thinking that the prompts would associate with their respective colored region in the control image, but that didnt happen, so it ended up with just characters which follow those colored region without adhering to specific character prompts. That was the regional controlnet. |
|
Attention masking is always somewhat "weak" when it conflicts with what the model thinks it needs to do to keep the image consistent. But IMO it's better than to force regions too hard and sacrifice composition. Slight prompt drift is much easier to fix in follow-up steps (eg. "Refine Region") than bad overall composition. I'm not entirely convinced on the controlnet - for relatively simple setups that are already decent without it, it improves adherence, but also seems to fit content to the mask shape on a structural level somewhat (not necessarily desired). And it changes the image style completely. Apart from complexity I'm concerned that the small scale of the CN made it learn to fit the dataset and not just the general task. I'm not even entirely sure what the task was supposed to be, since the CN doesn't interact with prompts - it seems to go in the direction of segmentation CN. |
|
Those are fair concerns. The regional controlnet model's original goal is to learn true prompt to region assignment, but it didnt end up behaving that way. From my testing, it behaved closer to a spatial/layout conditioning model that encourages subjects to occupy the specified regions. Thats why i found it worked best when paired with attention masking (which i tested in comfyui). The control model influences where the content appears and attention masking influences which prompt affected the region. Both approaches have limitation, but together they produced better adherence in my testing. Here are some example and tests from other users: As for integration, i understand your concern about adding it as separate regional workflows. But from my testing, and you know too, that attention masking by itself doesn't perform well at all, and it literally doesnt work with complex regions. For that reason, i view this controlnet model as a complementary requirement for regions to properly work in krita. Implementation-wise i will leave it to your discretion. |
|
Defining shape isn't something the region feature ever did or is supposed to do though. Usually it's combined with a sketch or depth image for structural guidance. It sounds like the region CN fills a similar purpose, and is quite close the "Segmentation" control net. I would suggest to just expose it as Anima's segmentation control layer for now, since it doesn't have one currently. If you want to generate a segmentation guidance image from the defined regions, this could be added as a button next to the "Generate control image" button. If I got it correctly, the CN expect regions as plain color blobs in the image. Current |
|
That does sound better. I'll take up your suggestions. Edit: I think all the changes can be kept, and 'regional' just need to be changed to 'segmentation' |
…ol mode support for Anima
|
My idea was to add a new button next to the existing generate/pre-processor button, which generates a segmentation image from current regions. It should work the same as the pre-processors, ie. create an explicit new layer with the colored regions that becomes the source for the control layer. Also should be available to all models, not a special Anima thing. The behavior as it is in this PR isn't intuitive at all, Anima has special behavior that just ignores any configured layer and generates something else behind the scenes which users never see and somehow depends on regions when there is no obvious connection. Also the function that generations the segmentation image needs to draw plain colors, NOT the region layer content. |
totally forgot about that. Made the changes, please check |
Acly
left a comment
There was a problem hiding this comment.
Looks good, just some small stuff and the linting error
| return image | ||
|
|
||
| def generate(self): | ||
| if not self.can_generate: |
There was a problem hiding this comment.
any particular reason this was added?
There was a problem hiding this comment.
safeguard for unintended calls
There was a problem hiding this comment.
what unintended calls? if there is no way to hit this code please remove it.
There was a problem hiding this comment.
yea sorry about that, i didnt check there were only two calls for this, and they would be hidden. Removed it.
| and layer.compute_bounds().area > 0 | ||
| and Bounds.intersection(bounds, layer.bounds).area > 0 |
There was a problem hiding this comment.
| and layer.compute_bounds().area > 0 | |
| and Bounds.intersection(bounds, layer.bounds).area > 0 | |
| and Bounds.intersection(bounds, layer.compute_bounds()).area > 0 |
| if self.mode is not ControlMode.segmentation: | ||
| return | ||
|
|
There was a problem hiding this comment.
| if self.mode is not ControlMode.segmentation: | |
| return | |
| assert self.mode is ControlMode.segmentation |
There was a problem hiding this comment.
changed this, but assertion can be disabled right?
There was a problem hiding this comment.
technically yes, but they are not disabled in Krita (and I'm not sure what your point is?)
Acly
left a comment
There was a problem hiding this comment.
LGTM, Lint check still needs to be fixed, but I probably won't be able to merge until weekend anyway
Added Anima regional control support. Regional control requires an optional (https://huggingface.co/Sen-sou/Anima-LLLite-Regional-Controlnet) model to work best. Since Anima-LLLite models are already supported in krita, therefore added a new controlnet type 'regional'. It doesnt require explicit control image, it automatically combines the current regions to form a control image. Regions can still work without the control model but the region effect is relatively weaker.
Edit: Both 'regional' control net and region attention should be able to work independently. But currently region attention works independently but 'regional' controlnet needs regions to work.