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

feat: Add combine parameter to Sam2Segmentation for flexible mask outputs #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

veighnsche
Copy link

This update introduces a new combine parameter to the Sam2Segmentation node, enhancing its flexibility for segmentation tasks. The combine parameter allows users to specify whether the segmentation masks should be combined into a single tensor or output as individual masks in a batch tensor format.

Key Changes:

  1. combine Parameter:

    • When set to True (default), all masks are combined into a single tensor, ensuring backward compatibility with workflows relying on combined masks.
    • When set to False, the node outputs a batch tensor containing individual masks, which can be processed independently.
  2. Improved Compatibility:

    • Ensures all outputs are tensors, avoiding issues with downstream nodes like MaskListToMaskBatch expecting objects with .shape attributes.
  3. Code Refactoring:

    • Enhanced segmentation logic to handle different output formats cleanly.
    • Improved handling of input masks, coordinates, and bounding boxes for consistency and clarity.

Testing and Validation:

  • Tested the node with both combine=True and combine=False scenarios.
  • Verified compatibility with downstream nodes to prevent errors such as AttributeError: 'list' object has no attribute 'shape'.
  • Ensured output consistency and alignment with expected tensor structures.

This change adds flexibility for segmentation workflows while maintaining backward compatibility, making the node more versatile for varied use cases.

… outputs

This update introduces a new `combine` parameter to the `Sam2Segmentation` node, enhancing its flexibility for segmentation tasks. The `combine` parameter allows users to specify whether the segmentation masks should be combined into a single tensor or output as individual masks in a batch tensor format.

#### Key Changes:
1. **`combine` Parameter**:
   - When set to `True` (default), all masks are combined into a single tensor, ensuring backward compatibility with workflows relying on combined masks.
   - When set to `False`, the node outputs a batch tensor containing individual masks, which can be processed independently.

2. **Improved Compatibility**:
   - Ensures all outputs are tensors, avoiding issues with downstream nodes like `MaskListToMaskBatch` expecting objects with `.shape` attributes.

3. **Code Refactoring**:
   - Enhanced segmentation logic to handle different output formats cleanly.
   - Improved handling of input masks, coordinates, and bounding boxes for consistency and clarity.

#### Testing and Validation:
- Tested the node with both `combine=True` and `combine=False` scenarios.
- Verified compatibility with downstream nodes to prevent errors such as `AttributeError: 'list' object has no attribute 'shape'`.
- Ensured output consistency and alignment with expected tensor structures.

This change adds flexibility for segmentation workflows while maintaining backward compatibility, making the node more versatile for varied use cases.
@Mithrillion
Copy link

This is actually extremely useful. With the individual masks, we will be able to automatically attach regional prompts to different areas of an image input, potentially greatly improve upscaling, style transferring etc. quality. I managed to piece together a very fragile automatic regional prompting workflow, but because extracting the text labels from the florence2 dense region caption output is still a pain, it is very convoluted. However I think if the florence2 node can also provide list-form regional caption directly, it can work wonderfully with the functionality added here.

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