Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 📦 changed way of creating bbox from mask #124

Merged
merged 3 commits into from
Nov 14, 2023

Conversation

Yurchikian
Copy link
Contributor

Had some issues while trying to create bbox from mask.

Changed code according to
This stackoverflow answer

Also fixed processing of mask input

@melMass
Copy link
Owner

melMass commented Nov 14, 2023

Thanks! I will test it now

nodes/crop.py Outdated Show resolved Hide resolved
nodes/crop.py Outdated Show resolved Hide resolved
@melMass
Copy link
Owner

melMass commented Nov 14, 2023

Thanks a lot for the contribution but I will use a different approach, what happens is I think Comfy changed the way mask are generated (I could be wrong).
Simply exposing an "invert" input on it seems to fix the issue you were trying to solve.

In case I misdiagnosed your issue can you explain what was not working as expected?

I just pushed the fix I'm mentioning in:
53cb503

melMass added a commit that referenced this pull request Nov 14, 2023
changes the default to false
related to #124
@melMass
Copy link
Owner

melMass commented Nov 14, 2023

So there is now a new input "invert" set to false by default (internally it was always "true" before):

image

@Yurchikian
Copy link
Contributor Author

I had several issues, that I've tried to fix. One of them is this error:

File "Q:\AI\ComfyUI\ComfyUI\custom_nodes\comfy_mtb\nodes\crop.py", line 144, in do_crop
    if mask:
RuntimeError: Boolean value of Tensor with more than one value is ambiguous

I believe that you can't just put ndarray into condition. So when the mask is present in Crop node, this error occurs, that's why I've changed it. And it works for both cases when mask is present and when mask is absent.

What about other issue - I had problems with wrong bbox generation, inverting mask beforehand did not help.
Just checked with updated version - works as expected (except the mentioned problem with mask cropping)

So all changes from my pull request are

- if mask:
+ if mask != None:

Copy link
Owner

@melMass melMass left a comment

Choose a reason for hiding this comment

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

You are right! I removed the other edits that I think are now covered by the invert input, thanks for spotting those issues!

@melMass melMass merged commit 14ee9e2 into melMass:main Nov 14, 2023
@melMass
Copy link
Owner

melMass commented Nov 14, 2023

I see what you meant for the mask my bad🤦
I'll push some fix and a test workflow now

melMass added a commit that referenced this pull request Nov 14, 2023
@melMass
Copy link
Owner

melMass commented Nov 14, 2023

I think it cover all cases, don't hesitate otherwise:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants