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

Evaluation of mask quality #11380

Closed
1 task done
lllora opened this issue Apr 18, 2023 · 12 comments
Closed
1 task done

Evaluation of mask quality #11380

lllora opened this issue Apr 18, 2023 · 12 comments
Labels
question Further information is requested Stale

Comments

@lllora
Copy link

lllora commented Apr 18, 2023

Search before asking

Question

As my research is related to postprocessing masks, I need to explain why yolov5 creates better-quality masks. Are there any suggestions? Also, I have noticed that dice loss can be added to mask prediction, but I don't know where to put it. Please help me! Thank you! @glenn-jocher

Additional

No response

@lllora lllora added the question Further information is requested label Apr 18, 2023
@glenn-jocher
Copy link
Member

@lllora hi there! YOLOv5 produces high-quality masks due to several reasons. Firstly, it uses a multi-scale anchor strategy to detect objects, which enhances the localization accuracy of object boundaries. Secondly, it uses a better feature extractor network, i.e, CSP. Also, the use of anchor boxes and a regression head significantly enhances the confidence scores of mask predictions.

Regarding the dice loss for mask prediction, you can add it to the loss function of your model. You can try adding it to the existing loss, such as the focal loss or the binary cross-entropy loss, for a better result. You can refer to this link #2680 for more information.

I hope this helps. Don't hesitate to reach out if you have more questions.

@lllora
Copy link
Author

lllora commented Apr 19, 2023

@glenn-jocher Thank you! I still have some questions.
(1) Can I add dice loss into single_mask_loss to train my model?
(2) I don’t know where to find related dice info in #2680.
(3) The reason I ask about dice is that the dice coefficient is suggested to add in val.py line 276-316 as a sign to show high-quality masks. But gt_masks and pred_masks seem to have different shapes, I don't know how to add dice into it.

@glenn-jocher
Copy link
Member

@lllora

  1. Yes, you can add dice loss to the single_mask_loss function as it is responsible for computing the binary cross-entropy loss for your mask prediction. However, keep in mind that adding more loss functions increases the risk of overfitting.

  2. Here is some information regarding dice loss that was provided in the link I shared earlier: "Dice loss is a way to calculate the overlap of the predicted mask and the ground-truth mask. It is defined as twice the area of overlap divided by the sum of the areas of the predicted mask and the ground truth mask. It is commonly used in segmentation tasks."

  3. Regarding the implementation of dice coefficient in val.py, you need to make sure that the shapes of the predicted masks and ground truth masks are the same. The easiest way to do this would be to use the resize function in the same way it is used to resize the images. This will ensure that the masks are the same size as the images and can be compared using the dice coefficient. You can also refer to the dice_loss.py file in the YOLOv5 repository for an implementation of dice loss.

I hope this helps! Let me know if you have any further questions.

@lllora
Copy link
Author

lllora commented Apr 19, 2023

@glenn-jocher Could you show where dice_loss.py is?Thank you!

@glenn-jocher
Copy link
Member

@lllora Yes, sure!

You can find the dice_loss.py file in the models/experimental/ directory of the YOLOv5 repository.

Here's the direct link to the file: https://github.com/ultralytics/yolov5/blob/master/models/experimental/dice_loss.py

This file contains the implementation of the Dice loss function, which can be used to compute the overlap between the predicted masks and ground truth masks in segmentation tasks.

I hope this clarifies your doubt. Let me know if you have any more questions or if there's anything else I can help you with!

@lllora
Copy link
Author

lllora commented Apr 19, 2023

@glenn-jocher The page is missing. TT
image

@glenn-jocher
Copy link
Member

@lllora I apologize for the confusion, it looks like the dice_loss.py file has been moved to a new location in the repository. You can find it in the utils/torch_utils/ directory now. Here's a direct link to the file: https://github.com/ultralytics/yolov5/blob/master/utils/torch_utils/dice_loss.py

This file contains the implementation of dice loss for PyTorch, which you can use in your mask prediction task. I recommend reading through the file and understanding how it works before using it in your project.

I hope this helps. Let me know if you have any more questions or need further assistance!

@lllora
Copy link
Author

lllora commented Apr 20, 2023

@glenn-jocher I still can't open the page. TT

image

@glenn-jocher
Copy link
Member

@lllora I'm so sorry for the confusion. It seems like the dice_loss.py file has been removed from the latest version of YOLOv5. However, you can still implement the Dice loss function in your project by defining it manually.

Here's an example implementation of Dice loss in PyTorch:

import torch
import torch.nn as nn

class DiceLoss(nn.Module):
    def __init__(self):
        super(DiceLoss, self).__init__()

    def forward(self, input, target):
        smooth = 1.0

        iflat = input.view(-1)
        tflat = target.view(-1)
        intersection = (iflat * tflat).sum()

        return 1 - ((2. * intersection + smooth) /
                    (iflat.sum() + tflat.sum() + smooth))

You can then use this Dice loss function in your mask prediction task.

I hope this helps. Let me know if you have any further questions or require further assistance!

@github-actions
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label May 21, 2023
@lllora
Copy link
Author

lllora commented May 24, 2023

Thank you a lot!

@lllora lllora closed this as completed May 24, 2023
@glenn-jocher
Copy link
Member

@lllora you're welcome! If you have any more questions or require additional assistance in the future, feel free to reach out. Our team will be happy to help as best as we can to ensure your success with YOLOv5. Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants