Auto annotation new parameters for SAM models (#17288)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
c943a3b747
commit
e8743f2ac9
3 changed files with 15 additions and 4 deletions
|
|
@ -5,7 +5,9 @@ from pathlib import Path
|
|||
from ultralytics import SAM, YOLO
|
||||
|
||||
|
||||
def auto_annotate(data, det_model="yolo11x.pt", sam_model="sam_b.pt", device="", output_dir=None):
|
||||
def auto_annotate(
|
||||
data, det_model="yolo11x.pt", sam_model="sam_b.pt", device="", conf=0.25, iou=0.45, imgsz=640, output_dir=None
|
||||
):
|
||||
"""
|
||||
Automatically annotates images using a YOLO object detection model and a SAM segmentation model.
|
||||
|
||||
|
|
@ -17,6 +19,9 @@ def auto_annotate(data, det_model="yolo11x.pt", sam_model="sam_b.pt", device="",
|
|||
det_model (str): Path or name of the pre-trained YOLO detection model.
|
||||
sam_model (str): Path or name of the pre-trained SAM segmentation model.
|
||||
device (str): Device to run the models on (e.g., 'cpu', 'cuda', '0').
|
||||
conf (float): Confidence threshold for detection model; default is 0.25.
|
||||
iou (float): IoU threshold for filtering overlapping boxes in detection results; default is 0.45.
|
||||
imgsz (int): Input image resize dimension; default is 640.
|
||||
output_dir (str | None): Directory to save the annotated results. If None, a default directory is created.
|
||||
|
||||
Examples:
|
||||
|
|
@ -36,7 +41,7 @@ def auto_annotate(data, det_model="yolo11x.pt", sam_model="sam_b.pt", device="",
|
|||
output_dir = data.parent / f"{data.stem}_auto_annotate_labels"
|
||||
Path(output_dir).mkdir(exist_ok=True, parents=True)
|
||||
|
||||
det_results = det_model(data, stream=True, device=device)
|
||||
det_results = det_model(data, stream=True, device=device, conf=conf, iou=iou, imgsz=imgsz)
|
||||
|
||||
for result in det_results:
|
||||
class_ids = result.boxes.cls.int().tolist() # noqa
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue