协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
inference-and-results【开发与工程】Use this sub-skill for Ultralytics YOLO predict workflows, source handling, streaming and batching, Results extraction, saving/plotting/cropping, and thread-safe inference.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when a task asks an agent to run Ultralytics inference or consume prediction outputs. It covers Python YOLO(...)(source), model.predict(source=...), CLI yolo predict, memory-safe streaming, batch/source choices, task-specific Results extraction, plotting/saving/cropping, and concurrent inference safety.
../data-and-configuration/.../training-and-validation/.../model-families-and-tasks/.../export-and-deployment/.../tracking-and-solutions/.../repo-development/.from ultralytics import YOLO for application code, or CLI yolo predict model=... source=... for one-off prediction runs.yolo26n.pt, yolo26n-seg.pt, or yolo26n-cls.pt may trigger downloads if the weights are not present.arg=value pairs in CLI, for example imgsz=640, conf=0.25, device=cpu, save=True, save_txt=True, project=runs/predict, name=exp.stream=True for videos, webcams, RTSP/RTMP/TCP streams, screenshots, very large directories, and long source lists; iterate the generator immediately.Results fields before access. Classification has probs and no boxes; semantic segmentation has semantic_mask and no instance boxes/masks.result.cpu(), result.numpy(), or result.to(...) before handing tensors to non-Torch post-processing or JSON/CSV/dataframe conversion.from ultralytics import YOLO
model = YOLO("weights.pt")
results = model.predict(source="image.jpg", imgsz=640, conf=0.25, device="cpu")
for result in results:
print(result.path, result.speed, result.summary(normalize=True))
from ultralytics import YOLO
model = YOLO("weights.pt")
for result in model("video.mp4", stream=True, imgsz=640):
if result.boxes is not None:
boxes = result.boxes.xyxy.cpu().tolist()
yolo predict model=weights.pt source=image.jpg imgsz=640 conf=0.25 save=True
The CLI syntax is yolo TASK MODE arg=value; TASK is optional for many models, but MODE is required. Prefer yolo predict model=... source=... unless a task-specific prefix is needed, such as yolo segment predict model=... source=....
result.boxes only after if result.boxes is not None.result.boxes and result.masks; retina_masks=True requests masks scaled to the original image shape.result.semantic_mask.data; do not expect result.boxes, result.masks.xy, or per-instance polygons.result.probs.top1, top1conf, top5, and top5conf; do not call crop/box code.result.boxes plus result.keypoints.xy, xyn, and optional conf.result.obb.xywhr or xyxyxyxy; result.obb.xyxy is the enclosing axis-aligned rectangle, not the rotated box.result.plot() returns an annotated image array; by default it is suitable for OpenCV-style BGR handling, while plot(pil=True) returns a PIL image.result.save(filename="out.jpg") writes the annotated image and creates missing parent directories.result.save_txt(path, save_conf=True) supports detection, segmentation, pose, OBB, and classification text outputs, but not semantic segmentation.result.save_crop(save_dir=...) supports box-based detection/segmentation/pose, but not classification, OBB, or semantic segmentation.save=True, save_txt=True, save_conf=True, and save_crop=True create output files under the predictor save directory; set project, name, and exist_ok=True when deterministic output paths matter.show=True on headless systems; use save=True or result.plot() and encode/display with a terminal or notebook-aware tool instead.Ultralytics predictors use an internal lock during stream_inference, but application-level threading should still avoid sharing mutable model state across threads unless access is serialized. The safest pattern is one YOLO instance per worker thread or process. If memory forces shared-model use, wrap the shared inference function with ultralytics.utils.ThreadingLocked and expect serialized throughput.
references/workflows.mdreferences/api-reference.mdreferences/troubleshooting.mdscripts/inspect_results_contract.py