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

How can I use retina_masks as an argument in model.predict? #1000

Open
1 task done
Josephts1 opened this issue Jan 28, 2025 · 2 comments
Open
1 task done

How can I use retina_masks as an argument in model.predict? #1000

Josephts1 opened this issue Jan 28, 2025 · 2 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@Josephts1
Copy link

Search before asking

Question

Hi, everyone.
I'm trying to use retina_masks in my YOLO model but I don't know how to use this argument. Should I expect a file with the mask of the objects?
I haven't found much documentation on this subject, I would appreciate it if someone could explain to me how the retina_mask=True argument is used in model.predict

results=model.predict('URL', save_crop=True, retina_masks=True, project='URL')

Additional

No response

@Josephts1 Josephts1 added the question Further information is requested label Jan 28, 2025
@UltralyticsAssistant UltralyticsAssistant added the documentation Improvements or additions to documentation label Jan 28, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @Josephts1, thank you for raising this question about the Ultralytics HUB 🚀! Please visit our HUB Docs to learn more about HUB usage and features:

  • Quickstart. Start training and deploying YOLO models with HUB in seconds.
  • Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
  • Projects: Creating and Managing. Group your models into projects for improved organization.
  • Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
  • Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
  • Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
    • iOS. Learn about YOLO CoreML models accelerated on Apple's Neural Engine on iPhones and iPads.
    • Android. Explore TFLite acceleration on mobile devices.
  • Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.

Regarding the retina_masks argument, could you please provide more details, such as:

  1. The complete code snippet you are using, including the full setup of your model.predict function.
  2. Any error logs, outputs, or unexpected behaviors you’ve encountered.
  3. The specific YOLO model version you are using (e.g., YOLOv5, YOLOv8).
  4. Details about your environment (e.g., operating system, Python version).

If this is a 🐛 Bug Report, it would also help if you could provide a Minimum Reproducible Example (MRE) so our team can investigate effectively.

This is an automated response to ensure you get assistance quickly 😊. An Ultralytics engineer will review your issue and provide a detailed response shortly.

Thank you for your patience and for contributing to Ultralytics! Your feedback helps make our tools better for everyone 🚀✨

@pderrenger
Copy link
Member

@Josephts1 hello! 👋

Great question about using the retina_masks argument in the model.predict function! Here's a detailed explanation:

The retina_masks=True argument is used to enable high-resolution segmentation masks in your results. When this is set to True, the predicted masks will match the resolution of the original input image. If it's set to False (default), the masks will match the image size used during inference, which may be resized (e.g., 640x640). This feature is particularly useful when you want precise masks for tasks like detailed object segmentation or post-processing.

How to Use retina_masks

Your code snippet looks good! Here's an example of how you can use it:

from ultralytics import YOLO

# Load the model
model = YOLO('yolov8-seg.pt')  # Ensure you're using a segmentation-capable YOLO model

# Perform inference with retina masks enabled
results = model.predict(
    source='your_image_or_video_path', 
    save_crop=True, 
    retina_masks=True, 
    project='your_project_name'
)

# Access and visualize masks
for mask in results[0].masks.data:
    print(mask.shape)  # Each mask will have the same resolution as the original image

Expected Output

  • When retina_masks=True, the masks will have high resolution and align with your original input image. These masks are accessible via results[0].masks.data.
  • If save_crop=True, the cropped regions will be saved to your specified project directory. Note that this doesn't save the masks directly as image files but focuses on cropped object bounding boxes. If you need to save masks, you may need to process results[0].masks.data and save them manually.

Additional Notes

  • Ensure you're using a segmentation YOLO model like yolov8-seg.pt for this feature to work. If you're using a detection model, retina_masks won't produce masks.
  • If you'd like to visualize or save the masks as image files, you can loop through results[0].masks.data and use a plotting library to overlay or save them.

For more information, you can reference the retina_masks argument documentation here.

Let me know if you have further questions! 🚀

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

No branches or pull requests

3 participants