Fix: Ensure Consistent MASK Output Dimensions from ReduxAdvanced Node#30
Open
sko00o wants to merge 1 commit intokaibioinfo:mainfrom
Open
Fix: Ensure Consistent MASK Output Dimensions from ReduxAdvanced Node#30sko00o wants to merge 1 commit intokaibioinfo:mainfrom
sko00o wants to merge 1 commit intokaibioinfo:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
This PR addresses an inconsistency in the dimensions of the MASK tensor returned by the
ReduxAdvancednode.Problem:
Previously, the shape of the returned
maskotensor depended on themodesetting, specifically on whether the internalprepareImageAndMaskfunction utilized thecroporletterboxhelper function:croppath (mode="center crop (square)"): This path (after recent user edits) produced a mask with shape(batch, height, width, 1).letterboxpath (mode="keep aspect ratio"or"autocrop with mask"): This path produced a mask with shape(batch, 1, height, width).The final
returnstatement inapply_stylemodelusedmasko.squeeze(-1). This correctly processed the(b, h, w, 1)output fromcropinto the standard(b, h, w)mask format. However, it did not correctly process the(b, 1, h, w)output fromletterbox, leaving it as a 4D tensor (unless width happened to be 1).This inconsistency meant that the MASK output type did not have a stable dimension format, potentially causing issues with downstream nodes that expect the standard ComfyUI 3D mask format
(batch, height, width), such asConditioning (Set Mask)orGrowMask. While theMaskToImagenode could handle both formats, this masked the underlying inconsistency in theReduxAdvancednode's output.Solution:
The core change is minimal and focuses on unifying the output format before the final
squeeze.letterboxfunction: The final step in handling the mask withinletterboxwas changed from.view(b, 1, desiredSize, desiredSize)(which was effectively a no-op) to.movedim(1, -1). This moves the channel dimension (dim 1) to the end, transforming the shape from(b, 1, h, w)to(b, h, w, 1).cropandletterboxnow return masks with the shape(b, h, w, 1)(when a mask is present).masko.squeeze(-1)in theapply_stylemodel's return statement now correctly handles the output from both paths, reliably producing the standard 3D mask format(batch, height, width).Benefit:
This change guarantees that the
ReduxAdvancednode's MASK output is always a standard 3D tensor(batch, height, width), improving compatibility and predictability when connecting to other ComfyUI nodes.