Mô hình Segment Anything nhanh (FastSAM)
Mô hình Fast Segment Anything (FastSAM) là giải pháp dựa trên CNN, hoạt động theo thời gian thực cho tác vụ Segment Anything. Tác vụ này được thiết kế để phân đoạn mọi đối tượng trong ảnh dựa trên nhiều loại prompt tương tác do người dùng cung cấp. FastSAM giảm đáng kể nhu cầu tính toán mà vẫn duy trì hiệu năng cạnh tranh, trở thành lựa chọn thiết thực cho nhiều tác vụ thị giác.
Xem: Theo dõi đối tượng bằng FastSAM với Ultralytics
Kiến trúc model#

Tổng quan#
FastSAM được thiết kế để khắc phục những hạn chế của Mô hình Segment Anything (SAM), một model Transformer cồng kềnh đòi hỏi nhiều tài nguyên tính toán. FastSAM tách tác vụ Segment Anything thành hai giai đoạn tuần tự: phân đoạn mọi instance và chọn đối tượng theo prompt. Giai đoạn đầu sử dụng YOLOv8-seg để tạo mask phân đoạn cho mọi instance trong ảnh. Ở giai đoạn thứ hai, model xuất vùng quan tâm tương ứng với prompt.
Tính năng chính#
-
Giải pháp thời gian thực: Tận dụng hiệu quả tính toán của CNN, FastSAM cung cấp giải pháp thời gian thực cho tác vụ Segment Anything, hữu ích cho các ứng dụng công nghiệp cần kết quả nhanh.
-
Hiệu quả và hiệu năng: FastSAM giảm đáng kể nhu cầu tính toán và tài nguyên trong khi đạt hiệu năng tương đương SAM, cho phép triển khai ứng dụng thời gian thực.
-
Phân đoạn theo prompt: FastSAM có thể phân đoạn mọi đối tượng trong ảnh theo các prompt tương tác khác nhau do người dùng cung cấp, mang lại tính linh hoạt và khả năng thích ứng trong nhiều tình huống.
-
Dựa trên YOLOv8-seg: FastSAM được xây dựng trên YOLOv8-seg, một model phát hiện đối tượng có nhánh phân đoạn instance. Nhờ đó, model có thể tạo hiệu quả mask phân đoạn cho mọi instance trong ảnh.
-
Kết quả cạnh tranh trên benchmark: Trong tác vụ đề xuất đối tượng trên MS COCO, FastSAM đạt điểm số cao với tốc độ nhanh hơn đáng kể so với SAM trên một GPU NVIDIA RTX 3090, thể hiện hiệu quả và năng lực của model.
-
Ứng dụng thực tiễn: Phương pháp này cung cấp giải pháp thiết thực cho nhiều tác vụ thị giác, với tốc độ nhanh hơn hàng chục đến hàng trăm lần so với các phương pháp Segment Anything trước đây.
-
Tính khả thi của nén model: FastSAM cho thấy tính khả thi của một hướng tiếp cận có thể giảm đáng kể khối lượng tính toán bằng cách đưa prior nhân tạo vào cấu trúc, từ đó mở ra những khả năng mới cho kiến trúc model lớn trong các tác vụ thị giác tổng quát.
Các model hiện có, tác vụ được hỗ trợ và chế độ hoạt động#
Bảng này trình bày các model hiện có cùng trọng số pretrained cụ thể, các tác vụ được hỗ trợ và khả năng tương thích với các chế độ hoạt động khác nhau như Huấn luyện, Đánh giá, Suy luận và Xuất. Các chế độ được hỗ trợ được đánh dấu ✅, còn chế độ không được hỗ trợ được đánh dấu ❌.
| Loại model | Weights pretrained | Các tác vụ được hỗ trợ | Huấn luyện | Validation | Suy luận | Export |
|---|---|---|---|---|---|---|
| FastSAM-s | FastSAM-s.pt | Phân đoạn đối tượng | ❌ | ✅ | ✅ | ✅ |
| FastSAM-x | FastSAM-x.pt | Phân đoạn đối tượng | ❌ | ✅ | ✅ | ✅ |
So sánh FastSAM với YOLO#
Ở đây, chúng tôi so sánh FastSAM-s với các biến thể SAM của Meta và các model phân đoạn của Ultralytics, bao gồm YOLO26:
| Model | Kích thước (MB) | Tham số (M) | Tốc độ (CPU) (ms/ảnh) |
|---|---|---|---|
| Meta SAM-b | 375 | 93.7 | 41703 |
| Meta SAM2-b | 162 | 80.8 | 28867 |
| Meta SAM2-t | 78.1 | 38.9 | 23430 |
| MobileSAM | 40.7 | 10.1 | 23802 |
| FastSAM-s với backbone YOLOv8 | 23.9 | 11.8 | 58.0 |
| Ultralytics YOLOv8n-seg | 7.1 (nhỏ hơn 11.0 lần) | 3.4 (ít hơn 11.4 lần) | 24.8 (nhanh hơn 945 lần) |
| Ultralytics YOLO11n-seg | 6.2 (nhỏ hơn 12.6 lần) | 2.9 (ít hơn 13.4 lần) | 24.3 (nhanh hơn 964 lần) |
| Ultralytics YOLO26n-seg | 6.7 (nhỏ hơn 11.7 lần) | 2.7 (ít hơn 14.4 lần) | 25.2 (nhanh hơn 930 lần) |
So sánh này cho thấy sự khác biệt đáng kể về kích thước và tốc độ giữa các biến thể SAM và model phân đoạn YOLO. SAM có khả năng phân đoạn tự động độc đáo, nhưng các model YOLO, đặc biệt là YOLOv8n-seg, YOLO11n-seg và YOLO26n-seg, nhỏ hơn, nhanh hơn và hiệu quả tính toán hơn đáng kể.
Tốc độ SAM được đo bằng PyTorch, tốc độ YOLO được đo bằng ONNX Runtime. Các thử nghiệm được chạy trên Apple M4 Air 2025 với RAM 16GB, sử dụng torch==2.10.0, ultralytics==8.4.31 và onnxruntime==1.24.4. Để tái tạo thử nghiệm này:
from ultralytics import ASSETS, SAM, YOLO, FastSAM
# Đo hiệu năng SAM2-t, SAM2-b, SAM-b, MobileSAM
for file in ["sam_b.pt", "sam2_b.pt", "sam2_t.pt", "mobile_sam.pt"]:
model = SAM(file)
model.info()
model(ASSETS)
# Lập hồ sơ FastSAM-s
model = FastSAM("FastSAM-s.pt")
model.info()
model(ASSETS)
# Đo hiệu năng các model YOLO (ONNX)
for file_name in ["yolov8n-seg.pt", "yolo11n-seg.pt", "yolo26n-seg.pt"]:
model = YOLO(file_name)
model.info()
onnx_path = model.export(format="onnx", dynamic=True, nms=False) # Đầu NMS-free của YOLO26; không có tác dụng với YOLOv8/YOLO11
model = YOLO(onnx_path)
model(ASSETS)Ví dụ sử dụng#
Các model FastSAM dễ dàng tích hợp vào ứng dụng Python của bạn. Ultralytics cung cấp cả Python API và các lệnh CLI.
Cách sử dụng Predict#
Để phân đoạn ảnh, hãy dùng phương thức predict như minh họa bên dưới:
from ultralytics import FastSAM
# Xác định nguồn inference
source = "path/to/bus.jpg"
# Tạo model FastSAM
model = FastSAM("FastSAM-s.pt") # hoặc FastSAM-x.pt
# Chạy suy luận trên một ảnh
everything_results = model(source, device="cpu", retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)
# Chạy suy luận với prompt bboxes
results = model(source, bboxes=[439, 437, 524, 709])
# Chạy inference với prompt điểm
results = model(source, points=[[200, 200]], labels=[1])
# Chạy inference với prompt văn bản
results = model(source, texts="a photo of a dog")
# Chạy inference đồng thời với prompt bbox, điểm và văn bản
results = model(source, bboxes=[439, 437, 524, 709], points=[[200, 200]], labels=[1], texts="a photo of a dog")Đoạn mã này minh họa cách tải pretrained model và chạy dự đoán trên ảnh một cách đơn giản.
Chạy suy luận trên ảnh một lần để nhận toàn bộ results phân đoạn, sau đó áp dụng prompt nhiều lần lên các kết quả đó mà không cần chạy lại suy luận.
from ultralytics.models.fastsam import FastSAMPredictor
# Tạo FastSAMPredictor
overrides = {"conf": 0.25, "task": "segment", "mode": "predict", "model": "FastSAM-s.pt", "save": False, "imgsz": 1024}
predictor = FastSAMPredictor(overrides=overrides)
# Phân đoạn tất cả
everything_results = predictor("ultralytics/assets/bus.jpg")
# Inference với prompt
bbox_results = predictor.prompt(everything_results, bboxes=[[200, 200, 300, 300]])
point_results = predictor.prompt(everything_results, points=[200, 200])
text_results = predictor.prompt(everything_results, texts="a photo of a dog")Tất cả results được trả về trong các ví dụ trên đều là đối tượng Results, cho phép truy cập các mask được dự đoán và ảnh nguồn.
Cách sử dụng Val#
FastSAM chỉ hỗ trợ phát hiện và phân đoạn một lớp đối tượng, nên model nhận diện và phân đoạn mọi đối tượng thành cùng một lớp. Khi chuẩn bị dataset, hãy chuyển tất cả ID danh mục đối tượng thành 0.
Có thể xác thực model trên một dataset như sau:
from ultralytics import FastSAM
# Tạo model FastSAM
model = FastSAM("FastSAM-s.pt") # hoặc FastSAM-x.pt
# Xác thực model
results = model.val(data="coco8-seg.yaml")Theo dõi sử dụng#
Để thực hiện theo dõi đối tượng trên một hình ảnh, hãy sử dụng phương thức track như bên dưới:
from ultralytics import FastSAM
# Tạo model FastSAM
model = FastSAM("FastSAM-s.pt") # hoặc FastSAM-x.pt
# # Theo dõi bằng model FastSAM trên video
results = model.track(source="path/to/video.mp4", imgsz=640)Cách sử dụng chính thức FastSAM#
FastSAM cũng có sẵn trực tiếp trong repository CASIA-LMC-Lab/FastSAM. Dưới đây là tổng quan ngắn về các bước thường thực hiện để sử dụng FastSAM:
Cài đặt#
-
Clone repository FastSAM:
git clone https://github.com/CASIA-LMC-Lab/FastSAM.git -
Tạo và kích hoạt môi trường Conda với Python 3.9:
conda create -n FastSAM python=3.9 conda activate FastSAM -
Điều hướng đến repository đã clone và cài đặt các package cần thiết:
cd FastSAM pip install -r requirements.txt -
Cài đặt model CLIP:
pip install git+https://github.com/ultralytics/CLIP.git
Ví dụ sử dụng#
-
Tải xuống checkpoint của model.
-
Sử dụng FastSAM để suy luận. Ví dụ lệnh:
-
Phân đoạn tất cả đối tượng trong một hình ảnh:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg -
Phân đoạn các đối tượng cụ thể bằng prompt văn bản:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --text_prompt "the yellow dog" -
Phân đoạn các đối tượng bên trong bounding box (cung cấp tọa độ box theo định dạng xywh):
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --box_prompt "[570,200,230,400]" -
Phân đoạn các đối tượng gần những điểm cụ thể:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --point_prompt "[[520,360],[620,300]]" --point_label "[1,0]"
-
Ngoài ra, bạn có thể thử FastSAM thông qua bản demo Colab của CASIA-LMC-Lab.
Trích dẫn và lời cảm ơn#
Chúng tôi xin ghi nhận những đóng góp đáng kể của các tác giả FastSAM trong lĩnh vực phân đoạn instance theo thời gian thực:
@misc{zhao2023fast,
title={Fast Segment Anything},
author={Xu Zhao and Wenchao Ding and Yongqi An and Yinglong Du and Tao Yu and Min Li and Ming Tang and Jinqiao Wang},
year={2023},
eprint={2306.12156},
archivePrefix={arXiv},
primaryClass={cs.CV}
}Bài báo FastSAM gốc có thể được tìm thấy trên arXiv. Các tác giả đã công khai công trình của mình và mã nguồn có thể truy cập trên GitHub. Chúng tôi trân trọng nỗ lực của họ trong việc thúc đẩy lĩnh vực này và giúp cộng đồng rộng lớn hơn tiếp cận công trình.
Câu hỏi thường gặp#
FastSAM, viết tắt của Fast Segment Anything Model, là giải pháp dựa trên mạng nơ-ron tích chập (CNN) thời gian thực, được thiết kế để giảm nhu cầu tính toán mà vẫn duy trì hiệu năng cao trong các tác vụ phân đoạn đối tượng. Khác với Mô hình Segment Anything (SAM), sử dụng kiến trúc dựa trên Transformer nặng hơn, FastSAM sử dụng Ultralytics YOLOv8-seg để phân đoạn instance hiệu quả qua hai giai đoạn: phân đoạn mọi instance, sau đó chọn đối tượng theo prompt.
FastSAM thực hiện phân đoạn thời gian thực bằng cách tách tác vụ phân đoạn thành hai giai đoạn: phân đoạn mọi instance với YOLOv8-seg và chọn đối tượng theo prompt. Nhờ tận dụng hiệu quả tính toán của CNN, FastSAM giảm đáng kể nhu cầu tính toán và tài nguyên mà vẫn duy trì hiệu năng cạnh tranh. Cách tiếp cận hai giai đoạn này giúp FastSAM cung cấp khả năng phân đoạn nhanh và hiệu quả, phù hợp với các ứng dụng cần kết quả nhanh.
FastSAM phù hợp với nhiều tác vụ thị giác máy tính cần hiệu suất phân đoạn theo thời gian thực. Các ứng dụng bao gồm:
- Tự động hóa công nghiệp để kiểm soát và đảm bảo chất lượng
- Phân tích video theo thời gian thực phục vụ an ninh và giám sát
- Phương tiện tự hành để phát hiện và phân đoạn đối tượng
- Chẩn đoán hình ảnh y tế cho các tác vụ phân đoạn chính xác và nhanh chóng
Khả năng xử lý nhiều loại prompt tương tác của người dùng giúp FastSAM thích ứng linh hoạt với các tình huống đa dạng.
Để sử dụng FastSAM suy luận bằng Python, bạn có thể làm theo ví dụ bên dưới:
from ultralytics import FastSAM # Xác định nguồn inference source = "path/to/bus.jpg" # Tạo model FastSAM model = FastSAM("FastSAM-s.pt") # hoặc FastSAM-x.pt # Chạy suy luận trên một ảnh everything_results = model(source, device="cpu", retina_masks=True, imgsz=1024, conf=0.4, iou=0.9) # Chạy suy luận với prompt bboxes results = model(source, bboxes=[439, 437, 524, 709]) # Chạy inference với prompt điểm results = model(source, points=[[200, 200]], labels=[1]) # Chạy inference với prompt văn bản results = model(source, texts="a photo of a dog") # Chạy inference đồng thời với prompt bbox, điểm và văn bản results = model(source, bboxes=[439, 437, 524, 709], points=[[200, 200]], labels=[1], texts="a photo of a dog")Để biết thêm chi tiết về các phương thức suy luận, hãy xem mục Cách sử dụng Predict trong tài liệu.
FastSAM hỗ trợ nhiều loại prompt để định hướng các tác vụ phân đoạn:
- Prompt Everything: Tạo kết quả phân đoạn cho tất cả đối tượng nhìn thấy được.
- Gợi ý hộp giới hạn (BBox): Phân đoạn các đối tượng nằm trong hộp giới hạn được chỉ định. Hộp không chồng lấp với bất kỳ mask nào được phát hiện sẽ không chọn gì cả.
- Prompt văn bản: Sử dụng văn bản mô tả để phân đoạn các đối tượng khớp với nội dung mô tả.
- Prompt điểm: Phân đoạn các đối tượng gần những điểm do người dùng xác định.
Tính linh hoạt này giúp FastSAM thích ứng với nhiều tình huống tương tác của người dùng, tăng khả năng ứng dụng trong các lĩnh vực khác nhau. Để biết thêm thông tin về cách sử dụng các prompt này, hãy tham khảo mục Tính năng chính.
Bình luận26
Đặt câu hỏi, chia sẻ kết quả hoặc giúp đỡ người khác.
qinfendekaizhou
why is the postprocess times is so long
PrashantDixit0(đã chỉnh sửa)
@qinfendekaizhou, can you share the reproducible code for it? Or the reference from where u noticed this.
In general, post-process time gets increased because of the post-processes involved to show the results, like
- NMS
- filtering by confidence score/ labels
- Scaling results to the original given inputs
- Number of objects to be annotated,
- Type of annotation, like BB or Segmentation
juliopchile
Will someone try to do a FastSAM for SAM2?
shahedmomenzadeh
Hi, I have a question Can I use the generated bbox cordinates by a yolo detection model like yolov11 as bboxes prompt for FastSAM ?
Glenn JocherUltralytics@shahedmomenzadeh yes, you can use YOLO detection model-generated bbox coordinates as prompts for FastSAM. The FastSAM documentation shows examples of passing bbox coordinates directly to the model using either the Python API or CLI. Just ensure your coordinates are in XYXY format as shown in the examples.
ismailwale
How can I make an inference of a video using frame by frame in loop using FastSam ?because I tried multiple times making inference directly with video predictor I constantly running out of memory despite setting stream =True since SAM is trying to keep the memory of 2000 frames of the video at ones . I will appreciate any ideal on how to predict and segment the video as a single frame image at every instance and put everything in a loop.
Similar question win MobileSam
Glenn JocherUltralytics@ismailwale to process a video frame by frame and avoid memory overload with FastSAM or MobileSAM, load the video as a frame sequence using a tool like OpenCV. Loop through each frame, run inference on it individually, and clear any cached results to free up memory between frames. For reference on frame-wise usage, consult OpenCV and FastSAM integration. Let me know if you need further clarifications!
ismailwale
Thanks so much for your guide .I appreciate it sir.
llu025
Thank you all for your great work! I am having troubles with prompting with a bounding box, it seems the FastSAM model ignores it and detects objects all over the video frames. This is how I obtain the results:
results = model( input_filename, device=device, imgsz=(736, 1280), verbose=False, stream=True, bboxes=[0, 0, 360, 640], retina_masks=True, conf=0.4, iou=0.9, )I also tried with
bboxes=[[0, 0, 360, 640]],without success. The model should detect objects in the top left quadrant of the video, instead it detects everywhere. Also, it oddly does not raise any error or warnings, both withbboxesas list of integers orbboxesas list of lists of integers.
Glenn JocherUltralyticsIt seems the bounding box prompts aren't being applied as expected. Ensure the
bboxesformat is correct (e.g.,[[x1, y1, x2, y2]]as a list of lists). Additionally, try using theFastSAMPredictorapproach for more controlled prompt application, as shown in this example. Let me know if the issue persists!llu025
Thank you @glenn-jocher for the "prompt" response ;-)
I need to use
stream=Truesince I am working with large videos. I cannot use it coupled withFastSAMPredictor, because it does not support it. My only alternative is to grab frames on my own with OpenCV, is that correct?By the way, in your examples in here
bboxesis passed as a list of integers, I followed those in the beginning. I see in the examples withFastSAMPredictorthat a list of lists is used instead. In any case, I ensured that I was using a list of lists, and it did not work anyway.Here's a minimal example of what I am trying to do, i.e., detecting objects in the top left part of the video:
from ultralytics import FastSAM import os import ffmpeg input_filename = "test_video.mp4" base_name = os.path.splitext(os.path.basename(input_filename))[0] output_filename = os.path.join("output", f"{base_name}.avi") model = FastSAM("models/FastSAM-x.pt") process2 = ( ffmpeg.input( "pipe:", format="rawvideo", pix_fmt="rgb24", s="1280x720", loglevel="-8", ) .output( output_filename, pix_fmt="yuv420p", vcodec="libx264", loglevel="-8", crf=17, ) .overwrite_output() .run_async(pipe_stdin=True) ) results = model( input_filename, device="cuda", imgsz=(736, 1280), verbose=False, stream=True, bboxes=[[0, 0, 360, 640]], retina_masks=True, conf=0.4, iou=0.9, ) for result in results: frame = result.plot() # Save on disk with process2 process2.stdin.write(frame.tobytes()) process2.stdin.close() process2.wait()
Glenn JocherUltralyticsThank you for the detailed explanation and example. Yes, you're correct—using OpenCV to manually grab frames is a valid and efficient approach, especially when working with
stream=Truefor large videos, as it avoids memory issues. Regardingbboxes, FastSAM expects a list of lists in the format[[x1, y1, x2, y2]]. If this still doesn't work as intended, please ensure your bounding box coordinates are correct and within the frame dimensions. Let us know if you encounter any further issues!llu025
I still encounter the same issue. I used
bboxes=[[20, 20, 500, 500]]just to be 100% sure the coordinates are within the the frame dimensions (1280x720), nothing changed. Since I have to grab frames with OpenCV anyway, I will just crop them myself, but I am quite sure this option is not working as intended.
Glenn JocherUltralytics@llu025 thank you for the update. If you’re certain the
bboxesparameter is properly configured and still not working as intended, cropping frames manually with OpenCV before passing them to the model is indeed a reliable workaround. It may also be worth checking the latest FastSAM updates or reporting this as a potential issue to ensure the bounding box prompt functionality is reviewed. Let us know if you need further assistance!
chongkuiqi
Thanks for your great work! I'm using FastSAM-x with bboxes prompt, the original image shape is [720, 1280], and I set 'imgsz' 1024. However, the results mask shape is [576, 1024], but I remembered in ultralytics-8.2.10, I can get masks with the same shape as the original image. May I ask why this change happened ?
chongkuiqi
Sorry, I forgot to set 'Retina_masks', problem solved, thanks again.
feiwenxiong
how many boxes are supported in thsi api, it cound only segment 2 boxes at most.
Glenn JocherUltralytics@feiwenxiong fastSAM should support multiple boxes. If you're experiencing limitations, please ensure your input format is correct. For further assistance, you might want to check the latest updates or documentation.
YuechengLiu
Thanks the authors for the great work!
I'm using FastSAM-x for instance segmentation (bboxes as the prompt), but I find that the shape of the predicted masks mismatch with the bounding box number. (e.g. the model takes 18 bboxes as input, but the shape of the predicted mask is (17, H, W)) . I tried to set
conf=0.01andiou=0.999, but it doesn't work. How can I solve that? Thanks!
Glenn JocherUltralytics@YuechengLiu thank you for your kind words! The issue you're experiencing might be due to a mismatch in the bounding box prompts and the segmentation results. Please ensure you're using the latest version of the FastSAM model. If the problem persists, consider checking the input format and the bounding box coordinates. For further assistance, you can refer to the FastSAM documentation: https://docs.ultralytics.com/models/fast-sam/.
YuechengLiu
Thanks for your kind reply! The bounding boxes I'm using are predicted by yolov10x (result.boxes.xyxy), so I think the input format might be right. I also tried the same bounding boxes for
mobile_sam, and the output dimension is as expected (same as the input dimension). The problem does not always occur. Do you have any idea about that? Thanks!YuechengLiu
And I'm using the latest version of ultralytics
Glenn JocherUltralyticsThanks for confirming you're using the latest version. Given that the issue is intermittent, it might be related to the specific bounding boxes or the image content. Please try running the model with a different set of bounding boxes or images to see if the issue persists. If it does, consider opening an issue on the GitHub repository with detailed information for further investigation.
nguyenvandang1998
Hi! I am using the FastSAM model and trying to obtain information about the bounding box and mask image of the object, but I don't know how to do it. I hope you can help me. Thank you very much!!
nguyenvandang1998
Currently, I can obtain information about the bounding box, but I still don't know how to get the mask image!!
Glenn JocherUltralytics(đã chỉnh sửa)Hi there! 🙌 To extract both bounding boxes and mask images using the FastSAM model, you would typically work with the
resultsobject returned by the model's prediction method. For the bounding boxes, you can access them directly as shown in the documentation or examples provided. For the mask images, since FastSAM is designed for real-time segmentation, the results should also include segmentation masks corresponding to detected objects.Here's a simplified way to access both:
from ultralytics import FastSAM # Define your image source source = 'path/to/your/image.jpg' # Load the FastSAM model (ensure you've chosen the correct model path) model = FastSAM('FastSAM-s.pt') # or another appropriate model # Perform inference results = model(source) # Accessing bounding boxes (assuming XYXY format) boxes = results[0].boxes.xyxy # Accessing segmentation masks # The masks are directly associated with detected objects in the results masks = results[0].masks # To visualize or further process masks and boxes, you would iterate through these objectsTo visualize or save the masks, you'd typically iterate over the
masksobject, and each mask can be processed according to your requirements (e.g., overlaying on the original image or saving as separate mask images).Remember, the exact attribute names (
boxes,masks) and methods might vary based on the model output specification, so it's always good to refer to the specific documentation or example codes for guidance.Hope this helps! Let us know if you have more questions. 😊
2