Optimization of function for converting mask images to uint8 type#426
Open
lcolok wants to merge 7 commits intoltdrdata:Mainfrom
Open
Optimization of function for converting mask images to uint8 type#426lcolok wants to merge 7 commits intoltdrdata:Mainfrom
lcolok wants to merge 7 commits intoltdrdata:Mainfrom
Conversation
…to handle input masks in the expected format
ltdrdata
requested changes
Apr 25, 2024
|
|
||
| # If mask is floating-point type, convert it to np.float32 to avoid overflow | ||
| if mask_clamped.dtype.kind == 'f': | ||
| mask_clamped = mask_clamped.astype(np.float32) |
Owner
There was a problem hiding this comment.
Since it has already been clamped between 0 and 1, is there a need to consider overflow?
| height, width, _ = image.shape | ||
| # Create an empty mask with the shape (N, H, W, 1), where N is the batch size, set to 1 | ||
| mask = torch.zeros( | ||
| (1, height, width, 1), dtype=torch.float32, device=mask_working_device |
Owner
There was a problem hiding this comment.
What is the reason for making the mask 4-dim here? The masks used in ComfyUI are 3-dim masks (b, h, w)
Owner
There was a problem hiding this comment.
The review was pending due to my mistake.
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.
Dear friend,
Thank you so much for your continuous contributions.
During recent usage, I found some potential improvements when converting mask images to uint8 type. I've adapted the original
(mask*255.0).astype(np.uint8)operation into a new function:optimized_mask_to_uint8(mask). This function has the following processing logic:This is my small improvement to the function. I hope we can discuss it together to see if it is suitable for adoption. I really appreciate your past efforts and look forward to further collaboration!
Best regards