-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Handle empty change indices in SAM's mask to rle conversion #35665
Conversation
Hi @MSt-10! Thanks for the fix 🤗 Do you have a minimum reproducing example for the error? It would be also great to add a test |
Not really, it is highly dependent on the used image and the state of the fine-tuned model. I haven't observed the bug with the pre-trained model only after fine-tuning it. |
One could call the method directly with an empty mask. This should also produce the error I think. |
Such an example would be fine! |
Where should I add this test? In this file? |
Yes! |
Are my tests sufficient? @qubvel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests, its great to see you added for all 3 cases 👍 It can be merged in a single method IMO, smth like test_rle_encoding
input_mask = torch.tensor([[[0, 1], [1, 1]]], dtype=torch.long) | ||
rle = _mask_to_rle_tf(input_mask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably pass TF tensor instead of torch?
Hey @MSt-10, hope you are doing well! Let me know if any help is needed from our side to finish this PR 🤗 |
…into sam-rle-bug
…into sam-rle-bug
@qubvel Sorry for the delay but I don't use TF, hence I overlooked it. I hope it's correct now🤗 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for update, a nit comment
…or PyTorch and TensorFlow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
if input_mask[i, 0] == 0: | ||
out.append({"size": [height, width], "counts": [height * width]}) | ||
else: | ||
out.append({"size": [height, width], "counts": [0, height * width]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing that changes here is the counts, we could reduce code with just updating counts 😉 but it's a nit!
…ace#35665) * Handle empty change indices in RLE conversion for masks * [test] Add unit tests for RLE encoding of masks in SamProcessor * [test] Update RLE conversion tests to use TensorFlow implementation * [test] Fix formatting in SamProcessorTest according to check_code_quality action * [test] Fix formatting in SamProcessorTest according to check_code_quality * [test] Refactored rle test cases into one test and used tf tensors in tf test cases * [test] Fix: removed self parameter from refactored methods * [test] Removed nested methods in run-length encoding tests for PyTorch and TensorFlow * [test] Added description to individual to run-length encoding tests for PyTorch and TensorFlow.
…ace#35665) * Handle empty change indices in RLE conversion for masks * [test] Add unit tests for RLE encoding of masks in SamProcessor * [test] Update RLE conversion tests to use TensorFlow implementation * [test] Fix formatting in SamProcessorTest according to check_code_quality action * [test] Fix formatting in SamProcessorTest according to check_code_quality * [test] Refactored rle test cases into one test and used tf tensors in tf test cases * [test] Fix: removed self parameter from refactored methods * [test] Removed nested methods in run-length encoding tests for PyTorch and TensorFlow * [test] Added description to individual to run-length encoding tests for PyTorch and TensorFlow.
What does this PR do?
It handles empty change indices when the predicted mask is converted to rle.
Previously this caused an exception.
Fixes #35664
Who can review?
@ArthurZucker