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

Avoid Re-running Segmentation if Mask is Already Available #49

Open
dnl13 opened this issue Nov 23, 2024 · 7 comments
Open

Avoid Re-running Segmentation if Mask is Already Available #49

dnl13 opened this issue Nov 23, 2024 · 7 comments

Comments

@dnl13
Copy link

dnl13 commented Nov 23, 2024

Hi @kijai,

First of all, thank you so much for your tireless effort in bringing such amazing models to ComfyUI.
It's always a delight to see the incredible things you’ve been working on.

The workflow works really well for me, but I’ve noticed one thing:

For example, when using Sam2VideoSegmentation to generate a good mask, the segmentation process is re-executed for every queue run, even if a mask already exists and the coordinates as well as the input image haven’t changed.

Is there a way to skip the segmentation process if a mask is already present at the output?
The mask I generated is already good, so the node wouldn’t need to run again each time—or am I missing something here?

I hope my explanation makes sense.

Thank you again for your amazing work!

Edited:

A sorry, I forgot to mention:
I have three segmentations running for different parts of the video.

got prompt
WARNING: Sam2VideoSegmentationAddPoints.IS_CHANGED() got an unexpected keyword argument 'coordinates_positive'
WARNING: Sam2VideoSegmentationAddPoints.IS_CHANGED() got an unexpected keyword argument 'coordinates_positive'
WARNING: Sam2VideoSegmentationAddPoints.IS_CHANGED() got an unexpected keyword argument 'coordinates_positive'

but my workflow looks like this (example node setup):
Screenshot 2024-11-23 155110

@kijai
Copy link
Owner

kijai commented Nov 23, 2024

I don't really understand sorry... you are saying it runs segmentation again when you are trying to use the resulting masks with something else? I can't replicate that behavior, for me it works like everything else in Comfy: it runs it again only if the inputs change.

@dnl13
Copy link
Author

dnl13 commented Nov 23, 2024

I don't know, maybe it interferes with some other custom nodes.
This video shows what it is doing:

2024-11-23.17-50-24_small.mp4

RemoveBackground and the ImagePreview of the 16 frames are read from the cache, but Sam2VideoSegmentation keeps running the segmentation over and over again. I have just updated ComfyUI and all nodes, so everything should be up to date.

@kijai
Copy link
Owner

kijai commented Nov 23, 2024

I have no idea... definitely not how it works for me... pretty much with same nodes too, using the example video workflow.

@dnl13
Copy link
Author

dnl13 commented Nov 23, 2024

Alright, that's strange. I'll try to investigate this further—thank you so much for your response!

I’ll disable some custom nodes to check if they might be causing the issue. If I figure out what’s going on, I’ll get back to you.

Thanks again for your help!

@dnl13
Copy link
Author

dnl13 commented Nov 23, 2024

Ah, okay, that makes the difference: Sam2Segmentation caches!

Sam2VideoSegmentation, on the other hand, runs every time.

I didn’t realize that I could also use Sam2Segmentation for the workflow. Thanks for clarifying!

Should I leave the issue open? For me, it’s resolved. I don’t fully understand it, but I think I can continue working this way. ;)

Screenshot 2024-11-23 181748

@kijai
Copy link
Owner

kijai commented Nov 23, 2024

Ahhh sorry didn't notice and completely forgot about that node, I never finished it so it probably has such quirks... the idea was to allow multiple points within different frames on the video, just never finished it.

@dnl13
Copy link
Author

dnl13 commented Nov 23, 2024

Ok, since my workflow processes videos, Sam2Video... well, it was the obvious choice. 😄
But in my specific use case, Sam2Segmentation works as well.
Thanks again for the amazing nodes you bring to ComfyUI!

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

No branches or pull requests

2 participants