Zum Inhalt springen

Einfache Hilfsprogramme

Code mit Perspektive

Die ultralytics Package bietet eine Vielzahl von Hilfsprogrammen zur Unterstützung, Verbesserung und Beschleunigung Ihrer Arbeitsabläufe. Obwohl noch viele weitere verfügbar sind, hebt dieser Leitfaden einige der nützlichsten für Entwickler hervor und dient als praktisches Nachschlagewerk für die Programmierung mit Ultralytics-Tools.



Ansehen: Ultralytics-Dienstprogramme | Auto-Annotation, Explorer-API und Dataset-Konvertierung

Daten

Automatische Beschriftung / Annotationen

Die Annotation von Datensätzen ist ein ressourcenintensiver und zeitaufwändiger Prozess. Wenn Sie ein Ultralytics YOLO Objekterkennungsmodell haben, das mit einer angemessenen Datenmenge trainiert wurde, können Sie es mit SAM verwenden, um zusätzliche Daten im Segmentierungsformat automatisch zu annotieren.

from ultralytics.data.annotator import auto_annotate

auto_annotate(
    data="path/to/new/data",
    det_model="yolo11n.pt",
    sam_model="mobile_sam.pt",
    device="cuda",
    output_dir="path/to/save_labels",
)

Diese Funktion gibt keinen Wert zurück. Für weitere Details:

Annotationen des Datensatzes visualisieren

Diese Funktion visualisiert YOLO-Annotationen auf einem Bild vor dem Training und hilft so, falsche Annotationen zu identifizieren und zu korrigieren, die zu falschen Erkennungsergebnissen führen könnten. Sie zeichnet Begrenzungsrahmen, beschriftet Objekte mit Klassennamen und passt die Textfarbe basierend auf der Luminanz des Hintergrunds an, um eine bessere Lesbarkeit zu gewährleisten.

from ultralytics.data.utils import visualize_image_annotations

label_map = {  # Define the label map with all annotated class labels.
    0: "person",
    1: "car",
}

# Visualize
visualize_image_annotations(
    "path/to/image.jpg",  # Input image path.
    "path/to/annotations.txt",  # Annotation file path for the image.
    label_map,
)

Konvertieren von Segmentierungsmasken in das YOLO-Format

Segmentierungsmasken in das YOLO-Format

Verwenden Sie dies, um einen Datensatz von Segmentierungsmaskenbildern in das Ultralytics YOLO-Segmentierungsformat zu konvertieren. Diese Funktion nimmt das Verzeichnis mit den Maskenbildern im Binärformat entgegen und konvertiert sie in das YOLO-Segmentierungsformat.

Die konvertierten Masken werden im angegebenen Ausgabeverzeichnis gespeichert.

from ultralytics.data.converter import convert_segment_masks_to_yolo_seg

# The classes here is the total classes in the dataset.
# for COCO dataset we have 80 classes.
convert_segment_masks_to_yolo_seg(masks_dir="path/to/masks_dir", output_dir="path/to/output_dir", classes=80)

Konvertieren von COCO in das YOLO-Format

Verwenden Sie dies, um zu konvertieren COCO JSON-Annotationen in das YOLO-Format. Für Objekterkennungs- (Bounding Box) Datensätze setzen Sie beides use_segments und use_keypoints zu False.

from ultralytics.data.converter import convert_coco

convert_coco(
    "coco/annotations/",
    use_segments=False,
    use_keypoints=False,
    cls91to80=True,
)

Für weitere Informationen über die convert_coco Funktion besuchen Sie die Referenzseite.

Abrufen von Bounding-Box-Dimensionen

import cv2

from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator

model = YOLO("yolo11n.pt")  # Load pretrain or fine-tune model

# Process the image
source = cv2.imread("path/to/image.jpg")
results = model(source)

# Extract results
annotator = Annotator(source, example=model.names)

for box in results[0].boxes.xyxy.cpu():
    width, height, area = annotator.get_bbox_dimension(box)
    print(f"Bounding Box Width {width.item()}, Height {height.item()}, Area {area.item()}")

Konvertieren von Bounding Boxes in Segmente

Konvertieren Sie mit vorhandenen x y w h Bounding-Box-Daten mithilfe der Funktion in Segmente. yolo_bbox2segment Funktion. Organisieren Sie die Dateien für Bilder und Anmerkungen wie folgt:

data
|__ images
    ├─ 001.jpg
    ├─ 002.jpg
    ├─ ..
    └─ NNN.jpg
|__ labels
    ├─ 001.txt
    ├─ 002.txt
    ├─ ..
    └─ NNN.txt
from ultralytics.data.converter import yolo_bbox2segment

yolo_bbox2segment(
    im_dir="path/to/images",
    save_dir=None,  # saved to "labels-segment" in images directory
    sam_model="sam_b.pt",
)

Besuchen Sie die yolo_bbox2segment Referenzseite für weitere Informationen bezüglich der Funktion.

Konvertieren von Segmenten in Bounding Boxes

Wenn Sie einen Datensatz haben, der das Segmentierungsdatensatzformat, können Sie diese einfach in aufrechte (oder horizontale) Begrenzungsrahmen umwandeln (x y w h Format) konvertieren.

import numpy as np

from ultralytics.utils.ops import segments2boxes

segments = np.array(
    [
        [805, 392, 797, 400, ..., 808, 714, 808, 392],
        [115, 398, 113, 400, ..., 150, 400, 149, 298],
        [267, 412, 265, 413, ..., 300, 413, 299, 412],
    ]
)

segments2boxes([s.reshape(-1, 2) for s in segments])
# >>> array([[ 741.66, 631.12, 133.31, 479.25],
#           [ 146.81, 649.69, 185.62, 502.88],
#           [ 281.81, 636.19, 118.12, 448.88]],
#           dtype=float32) # xywh bounding boxes

Um zu verstehen, wie diese Funktion funktioniert, besuchen Sie die Referenzseite.

Dienstprogramme

Bildkomprimierung

Komprimieren Sie eine einzelne Bilddatei auf eine reduzierte Größe, während Sie das Seitenverhältnis und die Qualität beibehalten. Wenn das Eingangsbild kleiner als die maximale Abmessung ist, wird es nicht skaliert.

from pathlib import Path

from ultralytics.data.utils import compress_one_image

for f in Path("path/to/dataset").rglob("*.jpg"):
    compress_one_image(f)

Auto-Split-Datensatz

Automatisches Aufteilen eines Datensatzes in train/val/test Splits und Speichern der resultierenden Splits in autosplit_*.txt Dateien. Diese Funktion verwendet eine Zufallsstichprobe, die bei Verwendung der Option ausgeschlossen wird fraction für das Training nicht enthalten ist..

from ultralytics.data.utils import autosplit

autosplit(
    path="path/to/images",
    weights=(0.9, 0.1, 0.0),  # (train, validation, test) fractional splits
    annotated_only=False,  # split only images with annotation file when True
)

Weitere Informationen zu dieser Funktion finden Sie auf der Referenzseite.

Segmentpolygon zu Binärmaske

Konvertiert ein einzelnes Polygon (als Liste) in eine binäre Maske der angegebenen Bildgröße. Das Polygon sollte die Form haben [N, 2], wobei N ist die Anzahl der (x, y) Punkte, die die Polygonkontur definieren.

Warnung

N muss immer gerade sein.

import numpy as np

from ultralytics.data.utils import polygon2mask

imgsz = (1080, 810)
polygon = np.array([805, 392, 797, 400, ..., 808, 714, 808, 392])  # (238, 2)

mask = polygon2mask(
    imgsz,  # tuple
    [polygon],  # input as list
    color=255,  # 8-bit binary
    downsample_ratio=1,
)

Bounding Boxes

Bounding-Box-Instanzen (horizontal)

Zur Verwaltung von Bounding-Box-Daten hilft die Klasse Bboxes Klasse hilft bei der Konvertierung zwischen Box-Koordinatenformaten, der Skalierung von Box-Dimensionen, der Berechnung von Flächen, dem Einbeziehen von Offsets und mehr.

import numpy as np

from ultralytics.utils.instance import Bboxes

boxes = Bboxes(
    bboxes=np.array(
        [
            [22.878, 231.27, 804.98, 756.83],
            [48.552, 398.56, 245.35, 902.71],
            [669.47, 392.19, 809.72, 877.04],
            [221.52, 405.8, 344.98, 857.54],
            [0, 550.53, 63.01, 873.44],
            [0.0584, 254.46, 32.561, 324.87],
        ]
    ),
    format="xyxy",
)

boxes.areas()
# >>> array([ 4.1104e+05,       99216,       68000,       55772,       20347,      2288.5])

boxes.convert("xywh")
print(boxes.bboxes)
# >>> array(
#     [[ 413.93, 494.05,  782.1, 525.56],
#      [ 146.95, 650.63,  196.8, 504.15],
#      [  739.6, 634.62, 140.25, 484.85],
#      [ 283.25, 631.67, 123.46, 451.74],
#      [ 31.505, 711.99,  63.01, 322.91],
#      [  16.31, 289.67, 32.503,  70.41]]
# )

Siehe die Bboxes Referenzbereich für weitere Attribute und Methoden.

Tipp

Viele der folgenden Funktionen (und weitere) können über die Bboxes Klasse, aber wenn Sie lieber direkt mit den Funktionen arbeiten möchten, finden Sie in den nächsten Unterabschnitten, wie Sie diese unabhängig voneinander importieren können.

Skalieren von Boxen

Beim Vergrößern oder Verkleinern eines Bildes können Sie die entsprechenden Begrenzungsboxkoordinaten entsprechend anpassen, um sie mit dem folgenden Wert abzugleichen: ultralytics.utils.ops.scale_boxes.

import cv2 as cv
import numpy as np

from ultralytics.utils.ops import scale_boxes

image = cv.imread("ultralytics/assets/bus.jpg")
h, w, c = image.shape
resized = cv.resize(image, None, (), fx=1.2, fy=1.2)
new_h, new_w, _ = resized.shape

xyxy_boxes = np.array(
    [
        [22.878, 231.27, 804.98, 756.83],
        [48.552, 398.56, 245.35, 902.71],
        [669.47, 392.19, 809.72, 877.04],
        [221.52, 405.8, 344.98, 857.54],
        [0, 550.53, 63.01, 873.44],
        [0.0584, 254.46, 32.561, 324.87],
    ]
)

new_boxes = scale_boxes(
    img1_shape=(h, w),  # original image dimensions
    boxes=xyxy_boxes,  # boxes from original image
    img0_shape=(new_h, new_w),  # resized image dimensions (scale to)
    ratio_pad=None,
    padding=False,
    xywh=False,
)

print(new_boxes)
# >>> array(
#     [[  27.454,  277.52,  965.98,   908.2],
#     [   58.262,  478.27,  294.42,  1083.3],
#     [   803.36,  470.63,  971.66,  1052.4],
#     [   265.82,  486.96,  413.98,    1029],
#     [        0,  660.64,  75.612,  1048.1],
#     [   0.0701,  305.35,  39.073,  389.84]]
# )

Bounding Box Formatkonvertierungen

XYXY → XYWH

Konvertiert Bounding-Box-Koordinaten vom Format (x1, y1, x2, y2) in das Format (x, y, Breite, Höhe), wobei (x1, y1) die obere linke Ecke und (x2, y2) die untere rechte Ecke ist.

import numpy as np

from ultralytics.utils.ops import xyxy2xywh

xyxy_boxes = np.array(
    [
        [22.878, 231.27, 804.98, 756.83],
        [48.552, 398.56, 245.35, 902.71],
        [669.47, 392.19, 809.72, 877.04],
        [221.52, 405.8, 344.98, 857.54],
        [0, 550.53, 63.01, 873.44],
        [0.0584, 254.46, 32.561, 324.87],
    ]
)
xywh = xyxy2xywh(xyxy_boxes)

print(xywh)
# >>> array(
#     [[ 413.93,  494.05,   782.1, 525.56],
#     [  146.95,  650.63,   196.8, 504.15],
#     [   739.6,  634.62,  140.25, 484.85],
#     [  283.25,  631.67,  123.46, 451.74],
#     [  31.505,  711.99,   63.01, 322.91],
#     [   16.31,  289.67,  32.503,  70.41]]
# )

Alle Bounding Box Konvertierungen

from ultralytics.utils.ops import (
    ltwh2xywh,
    ltwh2xyxy,
    xywh2ltwh,  # xywh → top-left corner, w, h
    xywh2xyxy,
    xywhn2xyxy,  # normalized → pixel
    xyxy2ltwh,  # xyxy → top-left corner, w, h
    xyxy2xywhn,  # pixel → normalized
)

for func in (ltwh2xywh, ltwh2xyxy, xywh2ltwh, xywh2xyxy, xywhn2xyxy, xyxy2ltwh, xyxy2xywhn):
    print(help(func))  # print function docstrings

Siehe den Docstring für jede Funktion oder besuchen Sie die ultralytics.utils.ops Referenzseite um mehr zu lesen.

Plotten

Annotation-Dienstprogramme

Ultralytics beinhaltet ein Annotator Klasse zum Annotieren verschiedener Datentypen. Am besten geeignet ist sie für Begrenzungsrahmen für die Objekterkennung, Pose-Keypointsund ausgerichtete Begrenzungsrahmen.

Box-Annotation

Python-Beispiele mit Ultralytics YOLO 🚀

import cv2 as cv
import numpy as np

from ultralytics.utils.plotting import Annotator, colors

names = {
    0: "person",
    5: "bus",
    11: "stop sign",
}

image = cv.imread("ultralytics/assets/bus.jpg")
ann = Annotator(
    image,
    line_width=None,  # default auto-size
    font_size=None,  # default auto-size
    font="Arial.ttf",  # must be ImageFont compatible
    pil=False,  # use PIL, otherwise uses OpenCV
)

xyxy_boxes = np.array(
    [
        [5, 22.878, 231.27, 804.98, 756.83],  # class-idx x1 y1 x2 y2
        [0, 48.552, 398.56, 245.35, 902.71],
        [0, 669.47, 392.19, 809.72, 877.04],
        [0, 221.52, 405.8, 344.98, 857.54],
        [0, 0, 550.53, 63.01, 873.44],
        [11, 0.0584, 254.46, 32.561, 324.87],
    ]
)

for nb, box in enumerate(xyxy_boxes):
    c_idx, *box = box
    label = f"{str(nb).zfill(2)}:{names.get(int(c_idx))}"
    ann.box_label(box, label, color=colors(c_idx, bgr=True))

image_with_bboxes = ann.result()
import cv2 as cv
import numpy as np

from ultralytics.utils.plotting import Annotator, colors

obb_names = {10: "small vehicle"}
obb_image = cv.imread("datasets/dota8/images/train/P1142__1024__0___824.jpg")
obb_boxes = np.array(
    [
        [0, 635, 560, 919, 719, 1087, 420, 803, 261],  # class-idx x1 y1 x2 y2 x3 y2 x4 y4
        [0, 331, 19, 493, 260, 776, 70, 613, -171],
        [9, 869, 161, 886, 147, 851, 101, 833, 115],
    ]
)
ann = Annotator(
    obb_image,
    line_width=None,  # default auto-size
    font_size=None,  # default auto-size
    font="Arial.ttf",  # must be ImageFont compatible
    pil=False,  # use PIL, otherwise uses OpenCV
)
for obb in obb_boxes:
    c_idx, *obb = obb
    obb = np.array(obb).reshape(-1, 4, 2).squeeze()
    label = f"{obb_names.get(int(c_idx))}"
    ann.box_label(
        obb,
        label,
        color=colors(c_idx, True),
    )

image_with_obb = ann.result()

Namen können verwendet werden von model.names wenn mit Erkennungsergebnissen gearbeitet wird. Siehe auch die Annotator Referenzseite für zusätzliche Einblicke.

Ultralytics Sweep-Annotation

Sweep-Annotation mit Ultralytics-Dienstprogrammen

import cv2
import numpy as np

from ultralytics import YOLO
from ultralytics.solutions.solutions import SolutionAnnotator
from ultralytics.utils.plotting import colors

# User defined video path and model file
cap = cv2.VideoCapture("path/to/video.mp4")
model = YOLO(model="yolo11s-seg.pt")  # Model file i.e. yolo11s.pt or yolo11m-seg.pt

if not cap.isOpened():
    print("Error: Could not open video.")
    exit()

# Initialize the video writer object.
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
video_writer = cv2.VideoWriter("ultralytics.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

masks = None  # Initialize variable to store masks data
f = 0  # Initialize frame count variable for enabling mouse event.
line_x = w  # Store width of line.
dragging = False  # Initialize bool variable for line dragging.
classes = model.names  # Store model classes names for plotting.
window_name = "Ultralytics Sweep Annotator"


def drag_line(event, x, _, flags, param):
    """Mouse callback function to enable dragging a vertical sweep line across the video frame."""
    global line_x, dragging
    if event == cv2.EVENT_LBUTTONDOWN or (flags & cv2.EVENT_FLAG_LBUTTON):
        line_x = max(0, min(x, w))
        dragging = True


while cap.isOpened():  # Loop over the video capture object.
    ret, im0 = cap.read()
    if not ret:
        break
    f = f + 1  # Increment frame count.
    count = 0  # Re-initialize count variable on every frame for precise counts.
    results = model.track(im0, persist=True)[0]

    if f == 1:
        cv2.namedWindow(window_name)
        cv2.setMouseCallback(window_name, drag_line)

    annotator = SolutionAnnotator(im0)

    if results.boxes.is_track:
        if results.masks is not None:
            masks = [np.array(m, dtype=np.int32) for m in results.masks.xy]

        boxes = results.boxes.xyxy.tolist()
        track_ids = results.boxes.id.int().cpu().tolist()
        clss = results.boxes.cls.cpu().tolist()

        for mask, box, cls, t_id in zip(masks or [None] * len(boxes), boxes, clss, track_ids):
            color = colors(t_id, True)  # Assign different color to each tracked object.
            label = f"{classes[cls]}:{t_id}"
            if mask is not None and mask.size > 0:
                if box[0] > line_x:
                    count += 1
                    cv2.polylines(im0, [mask], True, color, 2)
                    x, y = mask.min(axis=0)
                    (w_m, _), _ = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
                    cv2.rectangle(im0, (x, y - 20), (x + w_m, y), color, -1)
                    cv2.putText(im0, label, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
            else:
                if box[0] > line_x:
                    count += 1
                    annotator.box_label(box=box, color=color, label=label)

    # Generate draggable sweep line
    annotator.sweep_annotator(line_x=line_x, line_y=h, label=f"COUNT:{count}")

    cv2.imshow(window_name, im0)
    video_writer.write(im0)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

# Release the resources
cap.release()
video_writer.release()
cv2.destroyAllWindows()

Weitere Details finden Sie unter sweep_annotator Methode in unserem Referenzabschnitt hier.

Adaptive Label Annotation

Warnung

Beginnend mit Ultralytics v8.3.167, circle_label und text_label wurden durch eine einheitliche ersetzt adaptive_label Funktion. Sie können nun den Annotationstyp mit dem shape Argument:

  • Rechteck: annotator.adaptive_label(box, label=names[int(cls)], color=colors(cls, True), shape="rect")
  • Kreis: annotator.adaptive_label(box, label=names[int(cls)], color=colors(cls, True), shape="circle")



Ansehen: Ausführliche Anleitung zu Text- & Kreis-Annotationen mit Python Live Demos | Ultralytics Annotations 🚀

Adaptive Label Annotation mit Ultralytics Utilities

import cv2

from ultralytics import YOLO
from ultralytics.solutions.solutions import SolutionAnnotator
from ultralytics.utils.plotting import colors

model = YOLO("yolo11s.pt")
names = model.names
cap = cv2.VideoCapture("path/to/video.mp4")

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
writer = cv2.VideoWriter("Ultralytics circle annotation.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))

while True:
    ret, im0 = cap.read()
    if not ret:
        break

    annotator = SolutionAnnotator(im0)
    results = model.predict(im0)[0]
    boxes = results.boxes.xyxy.cpu()
    clss = results.boxes.cls.cpu().tolist()

    for box, cls in zip(boxes, clss):
        annotator.adaptive_label(box, label=names[int(cls)], color=colors(cls, True), shape="circle")
    writer.write(im0)
    cv2.imshow("Ultralytics circle annotation", im0)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

writer.release()
cap.release()
cv2.destroyAllWindows()
import cv2

from ultralytics import YOLO
from ultralytics.solutions.solutions import SolutionAnnotator
from ultralytics.utils.plotting import colors

model = YOLO("yolo11s.pt")
names = model.names
cap = cv2.VideoCapture("path/to/video.mp4")

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
writer = cv2.VideoWriter("Ultralytics text annotation.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))

while True:
    ret, im0 = cap.read()
    if not ret:
        break

    annotator = SolutionAnnotator(im0)
    results = model.predict(im0)[0]
    boxes = results.boxes.xyxy.cpu()
    clss = results.boxes.cls.cpu().tolist()

    for box, cls in zip(boxes, clss):
        annotator.adaptive_label(box, label=names[int(cls)], color=colors(cls, True), shape="rect")

    writer.write(im0)
    cv2.imshow("Ultralytics text annotation", im0)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

writer.release()
cap.release()
cv2.destroyAllWindows()

Siehe die SolutionAnnotator Referenzseite für zusätzliche Einblicke.

Verschiedenes

Code-Profiling

Überprüfen Sie die Laufzeit für die Ausführung/Verarbeitung von Code entweder mit with oder als Dekorator.

from ultralytics.utils.ops import Profile

with Profile(device="cuda:0") as dt:
    pass  # operation to measure

print(dt)
# >>> "Elapsed time is 9.5367431640625e-07 s"

Von Ultralytics unterstützte Formate

Müssen Sie die unterstützten Bild- oder Videoformate in Ultralytics programmgesteuert verwenden? Verwenden Sie bei Bedarf diese Konstanten:

from ultralytics.data.utils import IMG_FORMATS, VID_FORMATS

print(IMG_FORMATS)
# {'tiff', 'pfm', 'bmp', 'mpo', 'dng', 'jpeg', 'png', 'webp', 'tif', 'jpg'}

print(VID_FORMATS)
# {'avi', 'mpg', 'wmv', 'mpeg', 'm4v', 'mov', 'mp4', 'asf', 'mkv', 'ts', 'gif', 'webm'}

Teilbar machen

Berechnen Sie die nächste ganze Zahl zu x das gleichmäßig teilbar ist durch y.

from ultralytics.utils.ops import make_divisible

make_divisible(7, 3)
# >>> 9
make_divisible(7, 2)
# >>> 8

FAQ

Welche Hilfsprogramme sind im Ultralytics-Paket enthalten, um Machine-Learning-Workflows zu verbessern?

Das Ultralytics-Paket enthält Hilfsprogramme, die entwickelt wurden, um Machine-Learning-Workflows zu rationalisieren und zu optimieren. Zu den wichtigsten Hilfsprogrammen gehören die automatische Annotation zur Kennzeichnung von Datensätzen, die Konvertierung von COCO in das YOLO-Format mit convert_coco, die Komprimierung von Bildern und die automatische Aufteilung von Datensätzen. Diese Tools reduzieren den manuellen Aufwand, gewährleisten Konsistenz und verbessern die Effizienz der Datenverarbeitung.

Wie kann ich Ultralytics verwenden, um mein Dataset automatisch zu beschriften?

Wenn Sie ein vortrainiertes Ultralytics YOLO Objekterkennungsmodell haben, können Sie es mit dem SAM-Modell verwenden, um Ihr Dataset automatisch im Segmentierungsformat zu annotieren. Hier ist ein Beispiel:

from ultralytics.data.annotator import auto_annotate

auto_annotate(
    data="path/to/new/data",
    det_model="yolo11n.pt",
    sam_model="mobile_sam.pt",
    device="cuda",
    output_dir="path/to/save_labels",
)

Weitere Informationen finden Sie im Referenzabschnitt zur automatischen Annotation.

Wie konvertiere ich COCO-Dataset-Annotationen im Ultralytics-Format in das YOLO-Format?

Um COCO JSON-Annotationen für die Objekterkennung in das YOLO-Format zu konvertieren, können Sie das folgende convert_coco Dienstprogramm verwenden. Hier ist ein Beispielcode:

from ultralytics.data.converter import convert_coco

convert_coco(
    "coco/annotations/",
    use_segments=False,
    use_keypoints=False,
    cls91to80=True,
)

Für zusätzliche Informationen besuchen Sie die convert_coco Referenzseite.

Was ist der Zweck des YOLO Data Explorers im Ultralytics-Paket?

Die YOLO Explorer ist ein leistungsstarkes Werkzeug, das im 8.1.0 Update eingeführt wurde, um das Verständnis von Datensätzen zu verbessern. Es ermöglicht Ihnen, Textabfragen zu verwenden, um Objektinstanzen in Ihrem Datensatz zu finden, was die Analyse und Verwaltung Ihrer Daten vereinfacht. Dieses Tool bietet wertvolle Einblicke in die Zusammensetzung und Verteilung von Datensätzen und hilft so, das Modelltraining und die Leistung zu verbessern.

Wie kann ich Begrenzungsrahmen in Ultralytics in Segmente konvertieren?

Um vorhandene Begrenzungsbox-Daten (im x y w h Format) in Segmente zu konvertieren, können Sie die yolo_bbox2segment Funktion verwenden. Stellen Sie sicher, dass Ihre Dateien mit separaten Verzeichnissen für Bilder und Beschriftungen organisiert sind.

from ultralytics.data.converter import yolo_bbox2segment

yolo_bbox2segment(
    im_dir="path/to/images",
    save_dir=None,  # saved to "labels-segment" in the images directory
    sam_model="sam_b.pt",
)

Für weitere Informationen besuchen Sie die yolo_bbox2segment Referenzseite.



📅 Vor 1 Jahr erstellt ✏️ Vor 1 Monat aktualisiert

Kommentare