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

Mask returned in serverless automatic annotation does not agree with external result #7943

Closed
2 tasks done
hermda02 opened this issue May 24, 2024 · 6 comments
Closed
2 tasks done
Labels
documentation Documentation should be updated

Comments

@hermda02
Copy link

hermda02 commented May 24, 2024

Actions before raising this issue

  • I searched the existing issues and did not find anything similar.
  • I read/searched the docs

Steps to Reproduce

  1. Create a simple serverless detector function which produces a binary mask.
  2. Return an inference result with the following format:
    results.append({ "type": "mask", "confidence": str(prob), "label": "Net", "mask": cvat_mask, })
    where cvat_mask = binary_mask + [bounding box corners]
  3. Select "Automatic annotation" on an image within a CVAT task.

Expected Behavior

Expect CVAT to return an annotated image with the input binary mask applied, like the attached image. (These are the same inference results that go into CVAT).
image_prediction

Possible Solution

Documentation concerning the format required by CVAT in order for the binary mask to be properly handled.

Context

I've created a serverless function with my own pre-trained UNet model which returns masks for a given image by using PyTorch. When running inference on both my own machine and using Nuclio I am able to retrieve the same results as far as model outputs and mask details go.

However, when sending the mask in to CVAT, it returns a messy image:
Screenshot from 2024-05-24 12-22-05

This appears to be an issue with going from a binary mask to the RLE solution (https://github.com/cvat-ai/cvat/blob/develop/cvat/apps/lambda_manager/views.py, lines 738-743).

Environment

Server version: 2.9.0
Core version: 12.0.0
Canvas version: 2.18.0
UI version: 1.58.0
@hermda02 hermda02 added the bug Something isn't working label May 24, 2024
@bsekachev
Copy link
Member

Hello,

If you can reproduce it on one of functions already located in our repository, we will consider it as a bug.

@bsekachev bsekachev added the need info Need more information to investigate the issue label May 24, 2024
@hermda02
Copy link
Author

Unfortunately I was not. If possible, I would like to change the label to a documentation issue.

@bsekachev bsekachev added documentation Documentation should be updated and removed bug Something isn't working need info Need more information to investigate the issue labels May 25, 2024
@hermda02
Copy link
Author

This seems to be related to #6332 . Any chance you know in which piece of code the mask is parsed and applied to the input image?

I'm finding that an input block mask (mask[:500,:500] = 1) returns a masked image that appears to suffer some type of anti-aliasing:
image

@bsekachev
Copy link
Member

Be sure you are sending correct borders.

[0, 0, 500, 500] - will be incorrect in this case
[0, 0, 499, 499] is correct

@hermda02
Copy link
Author

hermda02 commented May 28, 2024

The borders are correct and are determined by torchvision.ops.mask_to_boxes.

Docker log output shows:

Borders: [0, 0, 499, 499]
Mask: tensor([[1, 1, 1,  ..., 0, 0, 0],
        [1, 1, 1,  ..., 0, 0, 0],
        [1, 1, 1,  ..., 0, 0, 0],
        ...,
        [0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0]])
Sum(mask): tensor(250000)

Edit:
Corresponding code:

        mask_out[:] = 0
        mask_out[:500,:500] = 1

        boxes = masks_to_boxes(mask_out.unsqueeze(0)).tolist()
        box = [int(b) for b in boxes[0]]

        print(box)

        print(mask_out)
        print(torch.sum(mask_out))

        cvat_mask = mask_out.long().tolist() + box

        prob = torch.nn.functional.softmax(output, dim=1).cpu().numpy()
        results.append({
            "type": "mask",
            "confidence": str(prob),
            "label": "Net",
            "mask": cvat_mask,   
        })
        return results

@hermda02
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation should be updated
Projects
None yet
Development

No branches or pull requests

2 participants