docs: Wrap all placeholder paths in quotes and code expressions (#2128)
* Wrap all placeholder paths in quotes across documentation and code examples for consistency * Update pre-commit config to exclude `docs/deprecated.md` from mdformat check
This commit is contained in:
parent
d925cdf666
commit
2abdccbe1d
|
|
@ -49,8 +49,9 @@ repos:
|
|||
- id: mdformat
|
||||
additional_dependencies:
|
||||
- "mdformat-mkdocs[recommended]>=2.1.0"
|
||||
- "mdformat-ruff"
|
||||
args: ["--number"]
|
||||
exclude: ^docs/
|
||||
exclude: ^(docs/changelog\.md|docs/deprecated\.md)$
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.19.1
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ comments: true
|
|||
# Datasets
|
||||
|
||||
!!! warning
|
||||
|
||||
Dataset API is still fluid and may change. If you use Dataset API in your project until further notice, freeze the
|
||||
`supervision` version in your `requirements.txt` or `setup.py`.
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
box_annotator = sv.BoxAnnotator()
|
||||
annotated_frame = box_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
round_box_annotator = sv.RoundBoxAnnotator()
|
||||
annotated_frame = round_box_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
corner_annotator = sv.BoxCornerAnnotator()
|
||||
annotated_frame = corner_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
color_annotator = sv.ColorAnnotator()
|
||||
annotated_frame = color_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
circle_annotator = sv.CircleAnnotator()
|
||||
annotated_frame = circle_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
dot_annotator = sv.DotAnnotator()
|
||||
annotated_frame = dot_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
triangle_annotator = sv.TriangleAnnotator()
|
||||
annotated_frame = triangle_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
ellipse_annotator = sv.EllipseAnnotator()
|
||||
annotated_frame = ellipse_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
halo_annotator = sv.HaloAnnotator()
|
||||
annotated_frame = halo_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
percentage_bar_annotator = sv.PercentageBarAnnotator()
|
||||
annotated_frame = percentage_bar_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
mask_annotator = sv.MaskAnnotator()
|
||||
annotated_frame = mask_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -248,7 +248,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
polygon_annotator = sv.PolygonAnnotator()
|
||||
annotated_frame = polygon_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -268,15 +268,15 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
|
||||
labels = [
|
||||
f"{class_name} {confidence:.2f}"
|
||||
for class_name, confidence
|
||||
in zip(detections['class_name'], detections.confidence)
|
||||
for class_name, confidence in zip(
|
||||
detections["class_name"],
|
||||
detections.confidence,
|
||||
)
|
||||
]
|
||||
|
||||
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
|
||||
annotated_frame = label_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections,
|
||||
labels=labels
|
||||
scene=image.copy(), detections=detections, labels=labels
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -296,18 +296,20 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
|
||||
labels = [
|
||||
f"{class_name} {confidence:.2f}"
|
||||
for class_name, confidence
|
||||
in zip(detections['class_name'], detections.confidence)
|
||||
for class_name, confidence in zip(
|
||||
detections["class_name"],
|
||||
detections.confidence,
|
||||
)
|
||||
]
|
||||
|
||||
rich_label_annotator = sv.RichLabelAnnotator(
|
||||
font_path="<TTF_FONT_PATH>",
|
||||
text_position=sv.Position.CENTER
|
||||
font_path="TTF_FONT_PATH",
|
||||
text_position=sv.Position.CENTER,
|
||||
)
|
||||
annotated_frame = rich_label_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections,
|
||||
labels=labels
|
||||
labels=labels,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -325,16 +327,13 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
image = ...
|
||||
detections = sv.Detections(...)
|
||||
|
||||
icon_paths = [
|
||||
"<ICON_PATH>"
|
||||
for _ in detections
|
||||
]
|
||||
icon_paths = ["<ICON_PATH>" for _ in detections]
|
||||
|
||||
icon_annotator = sv.IconAnnotator()
|
||||
annotated_frame = icon_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections,
|
||||
icon_path=icon_paths
|
||||
icon_path=icon_paths,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -346,23 +345,25 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
|
||||
<!-- === "Crop"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
image = ...
|
||||
detections = sv.Detections(...)
|
||||
image = ...
|
||||
detections = sv.Detections(...)
|
||||
|
||||
crop_annotator = sv.CropAnnotator()
|
||||
annotated_frame = crop_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
)
|
||||
```
|
||||
<div class="result" markdown>
|
||||
crop_annotator = sv.CropAnnotator()
|
||||
annotated_frame = crop_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
{ align=center width="800" }
|
||||
<div class="result" markdown>
|
||||
|
||||
{ align=center width="800" }
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
-->
|
||||
|
||||
=== "Blur"
|
||||
|
|
@ -374,10 +375,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
detections = sv.Detections(...)
|
||||
|
||||
blur_annotator = sv.BlurAnnotator()
|
||||
annotated_frame = blur_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
)
|
||||
annotated_frame = (blur_annotator.annotate(scene=image.copy(), detections=detections),)
|
||||
```
|
||||
|
||||
<div class="result" markdown>
|
||||
|
|
@ -397,7 +395,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
pixelate_annotator = sv.PixelateAnnotator()
|
||||
annotated_frame = pixelate_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -413,22 +411,23 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO('yolov8x.pt')
|
||||
model = YOLO("yolov8x.pt")
|
||||
|
||||
trace_annotator = sv.TraceAnnotator()
|
||||
|
||||
video_info = sv.VideoInfo.from_video_path(video_path='...')
|
||||
frames_generator = sv.get_video_frames_generator(source_path='...')
|
||||
video_info = sv.VideoInfo.from_video_path(video_path="...")
|
||||
frames_generator = sv.get_video_frames_generator(source_path="...")
|
||||
tracker = sv.ByteTrack()
|
||||
|
||||
with sv.VideoSink(target_path='...', video_info=video_info) as sink:
|
||||
with sv.VideoSink(target_path="...", video_info=video_info) as sink:
|
||||
for frame in frames_generator:
|
||||
result = model(frame)[0]
|
||||
detections = sv.Detections.from_ultralytics(result)
|
||||
detections = tracker.update_with_detections(detections)
|
||||
annotated_frame = trace_annotator.annotate(
|
||||
scene=frame.copy(),
|
||||
detections=detections)
|
||||
detections=detections,
|
||||
)
|
||||
sink.write_frame(frame=annotated_frame)
|
||||
```
|
||||
|
||||
|
|
@ -444,20 +443,21 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO('yolov8x.pt')
|
||||
model = YOLO("yolov8x.pt")
|
||||
|
||||
heat_map_annotator = sv.HeatMapAnnotator()
|
||||
|
||||
video_info = sv.VideoInfo.from_video_path(video_path='...')
|
||||
frames_generator = sv.get_video_frames_generator(source_path='...')
|
||||
video_info = sv.VideoInfo.from_video_path(video_path="...")
|
||||
frames_generator = sv.get_video_frames_generator(source_path="...")
|
||||
|
||||
with sv.VideoSink(target_path='...', video_info=video_info) as sink:
|
||||
with sv.VideoSink(target_path="...", video_info=video_info) as sink:
|
||||
for frame in frames_generator:
|
||||
result = model(frame)[0]
|
||||
detections = sv.Detections.from_ultralytics(result)
|
||||
annotated_frame = heat_map_annotator.annotate(
|
||||
scene=frame.copy(),
|
||||
detections=detections)
|
||||
detections=detections,
|
||||
)
|
||||
sink.write_frame(frame=annotated_frame)
|
||||
```
|
||||
|
||||
|
|
@ -478,7 +478,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
background_overlay_annotator = sv.BackgroundOverlayAnnotator()
|
||||
annotated_frame = background_overlay_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections=detections
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -501,7 +501,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti
|
|||
annotated_frame = comparison_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
detections_1=detections_1,
|
||||
detections_2=detections_2
|
||||
detections_2=detections_2,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ from roboflow import Roboflow
|
|||
|
||||
rf = Roboflow(api_key="<YOUR_API_KEY>")
|
||||
project = rf.workspace("<WORKSPACE_NAME>").project("<PROJECT_NAME>")
|
||||
dataset = project.version(<DATASET_VERSION_NUMBER>).download("<FORMAT>")
|
||||
dataset = project.version("<DATASET_VERSION_NUMBER>").download("<FORMAT>")
|
||||
```
|
||||
|
||||
If your dataset is from Universe, go to `Dataset` > `Download Dataset` > select the format (e.g. `YOLOv11`) > `Show download code`.
|
||||
|
|
@ -148,7 +148,7 @@ We'll use `supervision` to create a dataset iterator, and then run the model on
|
|||
test_set = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml"
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
|
||||
image_paths = []
|
||||
|
|
@ -172,7 +172,7 @@ We'll use `supervision` to create a dataset iterator, and then run the model on
|
|||
test_set = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml"
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
|
||||
image_paths = []
|
||||
|
|
@ -199,14 +199,16 @@ We need to remap them to match the dataset classes. Here's how to do it:
|
|||
def remap_classes(
|
||||
detections: sv.Detections,
|
||||
class_ids_from_to: dict[int, int],
|
||||
class_names_from_to: dict[str, str]
|
||||
class_names_from_to: dict[str, str],
|
||||
) -> None:
|
||||
new_class_ids = [
|
||||
class_ids_from_to.get(class_id, class_id) for class_id in detections.class_id]
|
||||
class_ids_from_to.get(class_id, class_id) for class_id in detections.class_id
|
||||
]
|
||||
detections.class_id = np.array(new_class_ids)
|
||||
|
||||
new_class_names = [
|
||||
class_names_from_to.get(name, name) for name in detections["class_name"]]
|
||||
class_names_from_to.get(name, name) for name in detections["class_name"]
|
||||
]
|
||||
predictions["class_name"] = np.array(new_class_names)
|
||||
```
|
||||
|
||||
|
|
@ -222,7 +224,7 @@ Let's also remove the predictions that are not in the dataset classes.
|
|||
test_set = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml"
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
|
||||
image_paths = []
|
||||
|
|
@ -236,11 +238,9 @@ Let's also remove the predictions that are not in the dataset classes.
|
|||
remap_classes(
|
||||
detections=predictions,
|
||||
class_ids_from_to={16: 0},
|
||||
class_names_from_to={"dog": "Corgi"}
|
||||
class_names_from_to={"dog": "Corgi"},
|
||||
)
|
||||
predictions = predictions[
|
||||
np.isin(predictions["class_name"], test_set.classes)
|
||||
]
|
||||
predictions = predictions[np.isin(predictions["class_name"], test_set.classes),]
|
||||
|
||||
image_paths.append(image_path)
|
||||
predictions_list.append(predictions)
|
||||
|
|
@ -260,7 +260,7 @@ Let's also remove the predictions that are not in the dataset classes.
|
|||
test_set = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml"
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
|
||||
image_paths = []
|
||||
|
|
@ -274,11 +274,9 @@ Let's also remove the predictions that are not in the dataset classes.
|
|||
remap_classes(
|
||||
detections=predictions,
|
||||
class_ids_from_to={16: 0},
|
||||
class_names_from_to={"dog": "Corgi"}
|
||||
class_names_from_to={"dog": "Corgi"},
|
||||
)
|
||||
predictions = predictions[
|
||||
np.isin(predictions["class_name"], test_set.classes)
|
||||
]
|
||||
predictions = predictions[np.isin(predictions["class_name"], test_set.classes),]
|
||||
|
||||
image_paths.append(image_path)
|
||||
predictions_list.append(predictions)
|
||||
|
|
@ -297,16 +295,22 @@ N = 9
|
|||
GRID_SIZE = (3, 3)
|
||||
|
||||
target_annotator = sv.PolygonAnnotator(color=sv.Color.from_hex("#8315f9"), thickness=8)
|
||||
prediction_annotator = sv.PolygonAnnotator(color=sv.Color.from_hex("#00cfc6"), thickness=6)
|
||||
prediction_annotator = sv.PolygonAnnotator(
|
||||
color=sv.Color.from_hex("#00cfc6"), thickness=6
|
||||
)
|
||||
|
||||
|
||||
annotated_images = []
|
||||
for image_path, predictions, targets in zip(
|
||||
image_paths[:N], predictions_list[:N], targets_list[:N]
|
||||
image_paths[:N], predictions_list[:N], targets_list[:N]
|
||||
):
|
||||
annotated_image = cv2.imread(image_path)
|
||||
annotated_image = target_annotator.annotate(scene=annotated_image, detections=targets)
|
||||
annotated_image = prediction_annotator.annotate(scene=annotated_image, detections=prediction)
|
||||
annotated_image = target_annotator.annotate(
|
||||
scene=annotated_image, detections=targets
|
||||
)
|
||||
annotated_image = prediction_annotator.annotate(
|
||||
scene=annotated_image, detections=prediction
|
||||
)
|
||||
annotated_images.append(annotated_image)
|
||||
|
||||
sv.plot_images_grid(images=annotated_images, grid_size=GRID_SIZE)
|
||||
|
|
|
|||
|
|
@ -20,26 +20,29 @@ First, you'll need to obtain predictions from your object detection or segmentat
|
|||
model.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```python
|
||||
import torch
|
||||
from PIL import Image
|
||||
|
|
@ -48,7 +51,7 @@ model.
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -57,7 +60,8 @@ model.
|
|||
width, height = image.size
|
||||
target_size = torch.tensor([[height, width]])
|
||||
results = processor.post_process_object_detection(
|
||||
outputs=outputs, target_sizes=target_size)[0]
|
||||
outputs=outputs, target_sizes=target_size
|
||||
)[0]
|
||||
```
|
||||
|
||||
## Load Predictions into Supervision
|
||||
|
|
@ -65,6 +69,7 @@ model.
|
|||
Now that we have predictions from a model, we can load them into Supervision.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
We can do so using the [`sv.Detections.from_inference`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_inference) method, which accepts model results from both detection and segmentation models.
|
||||
|
||||
```{ .py hl_lines="2 8" }
|
||||
|
|
@ -73,12 +78,13 @@ Now that we have predictions from a model, we can load them into Supervision.
|
|||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
We can do so using the [`sv.Detections.from_ultralytics`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_ultralytics) method, which accepts model results from both detection and segmentation models.
|
||||
|
||||
```{ .py hl_lines="2 8" }
|
||||
|
|
@ -87,12 +93,13 @@ Now that we have predictions from a model, we can load them into Supervision.
|
|||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
We can do so using the [`sv.Detections.from_transformers`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_transformers) method, which accepts model results from both detection and segmentation models.
|
||||
|
||||
```{ .py hl_lines="2 19-21" }
|
||||
|
|
@ -104,7 +111,7 @@ Now that we have predictions from a model, we can load them into Supervision.
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -132,13 +139,14 @@ You can load predictions from other computer vision frameworks and libraries usi
|
|||
Finally, we can annotate the image with the predictions. Since we are working with an object detection model, we will use the [`sv.BoxAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.BoxAnnotator) and [`sv.LabelAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.LabelAnnotator) classes.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="10-16" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
|
||||
|
|
@ -152,13 +160,14 @@ Finally, we can annotate the image with the predictions. Since we are working wi
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="10-16" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
||||
|
|
@ -172,6 +181,7 @@ Finally, we can annotate the image with the predictions. Since we are working wi
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="23-30" }
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -181,7 +191,7 @@ Finally, we can annotate the image with the predictions. Since we are working wi
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -213,13 +223,14 @@ will label each detection with its `class_name` (if possible) or `class_id`. You
|
|||
override this behavior by passing a list of custom `labels` to the `annotate` method.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="13-17 22" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
|
||||
|
|
@ -239,13 +250,14 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="13-17 22" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
||||
|
|
@ -265,6 +277,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="26-30 35" }
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -274,7 +287,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -314,13 +327,14 @@ is a drop-in replacement for
|
|||
that will allow you to draw masks instead of boxes.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-seg-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
|
||||
|
|
@ -328,19 +342,24 @@ that will allow you to draw masks instead of boxes.
|
|||
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER_OF_MASS)
|
||||
|
||||
annotated_image = mask_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
scene=image,
|
||||
detections=detections,
|
||||
)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections)
|
||||
scene=annotated_image,
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n-seg.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
||||
|
|
@ -348,12 +367,17 @@ that will allow you to draw masks instead of boxes.
|
|||
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER_OF_MASS)
|
||||
|
||||
annotated_image = mask_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
scene=image,
|
||||
detections=detections,
|
||||
)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections)
|
||||
scene=annotated_image,
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```python
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -363,7 +387,7 @@ that will allow you to draw masks instead of boxes.
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50-panoptic")
|
||||
model = DetrForSegmentation.from_pretrained("facebook/detr-resnet-50-panoptic")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -372,24 +396,27 @@ that will allow you to draw masks instead of boxes.
|
|||
width, height = image.size
|
||||
target_size = torch.tensor([[height, width]])
|
||||
results = processor.post_process_segmentation(
|
||||
outputs=outputs, target_sizes=target_size)[0]
|
||||
outputs=outputs, target_sizes=target_size
|
||||
)[0]
|
||||
detections = sv.Detections.from_transformers(
|
||||
transformers_results=results,
|
||||
id2label=model.config.id2label)
|
||||
transformers_results=results, id2label=model.config.id2label
|
||||
)
|
||||
|
||||
mask_annotator = sv.MaskAnnotator()
|
||||
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER_OF_MASS)
|
||||
|
||||
labels = [
|
||||
f"{class_name} {confidence:.2f}"
|
||||
for class_name, confidence
|
||||
in zip(detections['class_name'], detections.confidence)
|
||||
for class_name, confidence in zip(
|
||||
detections["class_name"],
|
||||
detections.confidence,
|
||||
)
|
||||
]
|
||||
|
||||
annotated_image = mask_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
annotated_image = mask_annotator.annotate(scene=image, detections=detections)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections, labels=labels)
|
||||
scene=annotated_image, detections=detections, labels=labels
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ Small object detection in high-resolution images presents challenges due to the
|
|||
size relative to the image resolution.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8x-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
|
||||
|
|
@ -34,19 +35,24 @@ size relative to the image resolution.
|
|||
label_annotator = sv.LabelAnnotator()
|
||||
|
||||
annotated_image = box_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
scene=image,
|
||||
detections=detections,
|
||||
)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections)
|
||||
scene=annotated_image,
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8x.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
||||
|
|
@ -54,12 +60,17 @@ size relative to the image resolution.
|
|||
label_annotator = sv.LabelAnnotator()
|
||||
|
||||
annotated_image = box_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
scene=image,
|
||||
detections=detections,
|
||||
)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections)
|
||||
scene=annotated_image,
|
||||
detections=detections,
|
||||
)
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```python
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -69,7 +80,7 @@ size relative to the image resolution.
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForSegmentation.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -78,22 +89,19 @@ size relative to the image resolution.
|
|||
width, height = image_slice.size
|
||||
target_size = torch.tensor([[width, height]])
|
||||
results = processor.post_process_object_detection(
|
||||
outputs=outputs, target_sizes=target_size)[0]
|
||||
outputs=outputs, target_sizes=target_size
|
||||
)[0]
|
||||
detections = sv.Detections.from_transformers(results)
|
||||
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
label_annotator = sv.LabelAnnotator()
|
||||
|
||||
labels = [
|
||||
model.config.id2label[class_id]
|
||||
for class_id
|
||||
in detections.class_id
|
||||
]
|
||||
labels = [model.config.id2label[class_id] for class_id in detections.class_id]
|
||||
|
||||
annotated_image = box_annotator.annotate(
|
||||
scene=image, detections=detections)
|
||||
annotated_image = box_annotator.annotate(scene=image, detections=detections)
|
||||
annotated_image = label_annotator.annotate(
|
||||
scene=annotated_image, detections=detections, labels=labels)
|
||||
scene=annotated_image, detections=detections, labels=labels
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
|
|
@ -105,13 +113,14 @@ identification at the cost of processing speed and increased memory usage. This
|
|||
is less effective for ultra-high-resolution images (4K and above).
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="5" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8x-1280")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
|
||||
|
|
@ -125,13 +134,14 @@ is less effective for ultra-high-resolution images (4K and above).
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="7" }
|
||||
import cv2
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8x.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image, imgsz=1280)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
||||
|
|
@ -157,6 +167,7 @@ objects within each, and aggregating the results.
|
|||
</video>
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="9-14" }
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
|
@ -164,7 +175,7 @@ objects within each, and aggregating the results.
|
|||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8x-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
def callback(image_slice: np.ndarray) -> sv.Detections:
|
||||
results = model.infer(image_slice)[0]
|
||||
|
|
@ -183,6 +194,7 @@ objects within each, and aggregating the results.
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="9-14" }
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
|
@ -190,7 +202,7 @@ objects within each, and aggregating the results.
|
|||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8x.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
def callback(image_slice: np.ndarray) -> sv.Detections:
|
||||
result = model(image_slice)[0]
|
||||
|
|
@ -209,6 +221,7 @@ objects within each, and aggregating the results.
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="13-28" }
|
||||
import cv2
|
||||
import torch
|
||||
|
|
@ -220,7 +233,7 @@ objects within each, and aggregating the results.
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
def callback(image_slice: np.ndarray) -> sv.Detections:
|
||||
image_slice = cv2.cvtColor(image_slice, cv2.COLOR_BGR2RGB)
|
||||
|
|
@ -261,6 +274,7 @@ objects within each, and aggregating the results.
|
|||
[`InferenceSlicer`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/#supervision.detection.tools.inference_slicer.InferenceSlicer) can perform segmentation tasks too.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="6 16 19-20" }
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
|
@ -268,7 +282,7 @@ objects within each, and aggregating the results.
|
|||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8x-seg-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
def callback(image_slice: np.ndarray) -> sv.Detections:
|
||||
results = model.infer(image_slice)[0]
|
||||
|
|
@ -287,6 +301,7 @@ objects within each, and aggregating the results.
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="6 16 19-20" }
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
|
@ -294,7 +309,7 @@ objects within each, and aggregating the results.
|
|||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8x-seg.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
def callback(image_slice: np.ndarray) -> sv.Detections:
|
||||
result = model(image_slice)[0]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ the filters in their applications.
|
|||
Allows you to select detections that belong only to one selected class.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ Allows you to select detections that belong only to one selected class.
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -47,6 +49,7 @@ Allows you to select detections that belong only to one selected class.
|
|||
Allows you to select detections that belong only to selected set of classes.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import supervision as sv
|
||||
|
|
@ -63,6 +66,7 @@ Allows you to select detections that belong only to selected set of classes.
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import supervision as sv
|
||||
|
|
@ -83,6 +87,7 @@ Allows you to select detections that belong only to selected set of classes.
|
|||
Allows you to select detections with specific confidence value, for example higher than selected threshold.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -97,6 +102,7 @@ Allows you to select detections with specific confidence value, for example high
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -116,6 +122,7 @@ Allows you to select detections based on their size. We define the area as the n
|
|||
detection in the image. In the example below, we have sifted out the detections that are too small.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -130,6 +137,7 @@ detection in the image. In the example below, we have sifted out the detections
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -151,6 +159,7 @@ but small on a 3840x2160 image. In such cases, we can filter out detections base
|
|||
occupied by them. In the example below, we remove too large detections.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -169,6 +178,7 @@ occupied by them. In the example below, we remove too large detections.
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -193,6 +203,7 @@ can be criteria for rejecting detection. Implementing such filtering requires a
|
|||
simple and fast.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -209,6 +220,7 @@ simple and fast.
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -230,6 +242,7 @@ Allows you to use `Detections` in combination with `PolygonZone` to weed out bou
|
|||
zone. In the example below you can see how to filter out all detections located in the lower part of the image.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -246,6 +259,7 @@ zone. In the example below you can see how to filter out all detections located
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -266,6 +280,7 @@ zone. In the example below you can see how to filter out all detections located
|
|||
`Detections`' greatest strength, however, is that you can build arbitrarily complex logical conditions by simply combining separate conditions using `&` or `|`.
|
||||
|
||||
=== "After"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
@ -282,6 +297,7 @@ zone. In the example below you can see how to filter out all detections located
|
|||
</div>
|
||||
|
||||
=== "Before"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ your workspace ID, project ID, and version number.
|
|||
roboflow.login()
|
||||
|
||||
rf = roboflow.Roboflow()
|
||||
project = rf.workspace('<WORKSPACE_ID>').project('<PROJECT_ID>')
|
||||
dataset = project.version('<PROJECT_VERSION>').download("coco")
|
||||
project = rf.workspace("<WORKSPACE_ID>").project("<PROJECT_ID>")
|
||||
dataset = project.version("<PROJECT_VERSION>").download("coco")
|
||||
```
|
||||
|
||||
=== "YOLO"
|
||||
|
|
@ -44,8 +44,8 @@ your workspace ID, project ID, and version number.
|
|||
roboflow.login()
|
||||
|
||||
rf = roboflow.Roboflow()
|
||||
project = rf.workspace('<WORKSPACE_ID>').project('<PROJECT_ID>')
|
||||
dataset = project.version('<PROJECT_VERSION>').download("yolov8")
|
||||
project = rf.workspace("<WORKSPACE_ID>").project("<PROJECT_ID>")
|
||||
dataset = project.version("<PROJECT_VERSION>").download("yolov8")
|
||||
```
|
||||
|
||||
=== "Pascal VOC"
|
||||
|
|
@ -56,8 +56,8 @@ your workspace ID, project ID, and version number.
|
|||
roboflow.login()
|
||||
|
||||
rf = roboflow.Roboflow()
|
||||
project = rf.workspace('<WORKSPACE_ID>').project('<PROJECT_ID>')
|
||||
dataset = project.version('<PROJECT_VERSION>').download("voc")
|
||||
project = rf.workspace("<WORKSPACE_ID>").project("<PROJECT_ID>")
|
||||
dataset = project.version("<PROJECT_VERSION>").download("voc")
|
||||
```
|
||||
|
||||
## Load Dataset
|
||||
|
|
@ -75,16 +75,16 @@ instances.
|
|||
import supervision as sv
|
||||
|
||||
ds_train = sv.DetectionDataset.from_coco(
|
||||
images_directory_path=f'{dataset.location}/train',
|
||||
annotations_path=f'{dataset.location}/train/_annotations.coco.json',
|
||||
images_directory_path=f"{dataset.location}/train",
|
||||
annotations_path=f"{dataset.location}/train/_annotations.coco.json",
|
||||
)
|
||||
ds_valid = sv.DetectionDataset.from_coco(
|
||||
images_directory_path=f'{dataset.location}/valid',
|
||||
annotations_path=f'{dataset.location}/valid/_annotations.coco.json',
|
||||
images_directory_path=f"{dataset.location}/valid",
|
||||
annotations_path=f"{dataset.location}/valid/_annotations.coco.json",
|
||||
)
|
||||
ds_test = sv.DetectionDataset.from_coco(
|
||||
images_directory_path=f'{dataset.location}/test',
|
||||
annotations_path=f'{dataset.location}/test/_annotations.coco.json',
|
||||
images_directory_path=f"{dataset.location}/test",
|
||||
annotations_path=f"{dataset.location}/test/_annotations.coco.json",
|
||||
)
|
||||
|
||||
ds_train.classes
|
||||
|
|
@ -102,19 +102,19 @@ instances.
|
|||
import supervision as sv
|
||||
|
||||
ds_train = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f'{dataset.location}/train/images',
|
||||
annotations_directory_path=f'{dataset.location}/train/labels',
|
||||
data_yaml_path=f'{dataset.location}/data.yaml'
|
||||
images_directory_path=f"{dataset.location}/train/images",
|
||||
annotations_directory_path=f"{dataset.location}/train/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
ds_valid = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f'{dataset.location}/valid/images',
|
||||
annotations_directory_path=f'{dataset.location}/valid/labels',
|
||||
data_yaml_path=f'{dataset.location}/data.yaml'
|
||||
images_directory_path=f"{dataset.location}/valid/images",
|
||||
annotations_directory_path=f"{dataset.location}/valid/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
ds_test = sv.DetectionDataset.from_yolo(
|
||||
images_directory_path=f'{dataset.location}/test/images',
|
||||
annotations_directory_path=f'{dataset.location}/test/labels',
|
||||
data_yaml_path=f'{dataset.location}/data.yaml'
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
data_yaml_path=f"{dataset.location}/data.yaml",
|
||||
)
|
||||
|
||||
ds_train.classes
|
||||
|
|
@ -132,16 +132,16 @@ instances.
|
|||
import supervision as sv
|
||||
|
||||
ds_train = sv.DetectionDataset.from_pascal_voc(
|
||||
images_directory_path=f'{dataset.location}/train/images',
|
||||
annotations_directory_path=f'{dataset.location}/train/labels'
|
||||
images_directory_path=f"{dataset.location}/train/images",
|
||||
annotations_directory_path=f"{dataset.location}/train/labels",
|
||||
)
|
||||
ds_valid = sv.DetectionDataset.from_pascal_voc(
|
||||
images_directory_path=f'{dataset.location}/valid/images',
|
||||
annotations_directory_path=f'{dataset.location}/valid/labels'
|
||||
images_directory_path=f"{dataset.location}/valid/images",
|
||||
annotations_directory_path=f"{dataset.location}/valid/labels",
|
||||
)
|
||||
ds_test = sv.DetectionDataset.from_pascal_voc(
|
||||
images_directory_path=f'{dataset.location}/test/images',
|
||||
annotations_directory_path=f'{dataset.location}/test/labels'
|
||||
images_directory_path=f"{dataset.location}/test/images",
|
||||
annotations_directory_path=f"{dataset.location}/test/labels",
|
||||
)
|
||||
|
||||
ds_train.classes
|
||||
|
|
@ -294,12 +294,12 @@ ds = sv.DetectionDataset(...)
|
|||
|
||||
# Option 1
|
||||
for image_path, image, annotations in ds:
|
||||
... # Process each image and its annotations
|
||||
... # Process each image and its annotations
|
||||
|
||||
# Option 2
|
||||
for idx in range(len(ds)):
|
||||
image_path, image, annotations = ds[idx]
|
||||
... # Process the image and annotations at index `idx`
|
||||
... # Process the image and annotations at index `idx`
|
||||
```
|
||||
|
||||
## Visualize Dataset
|
||||
|
|
@ -351,8 +351,8 @@ sv.plot_images_grid(
|
|||
ds = sv.DetectionDataset(...)
|
||||
|
||||
ds.as_coco(
|
||||
images_directory_path='<IMAGE_DIRECTORY_PATH>',
|
||||
annotations_path='<ANNOTATIONS_PATH>'
|
||||
images_directory_path="<IMAGE_DIRECTORY_PATH>",
|
||||
annotations_path="<ANNOTATIONS_PATH>",
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -366,9 +366,9 @@ sv.plot_images_grid(
|
|||
ds = sv.DetectionDataset(...)
|
||||
|
||||
ds.as_yolo(
|
||||
images_directory_path='<IMAGE_DIRECTORY_PATH>',
|
||||
annotations_directory_path='<ANNOTATIONS_DIRECTORY_PATH>',
|
||||
data_yaml_path='<DATA_YAML_PATH>'
|
||||
images_directory_path="<IMAGE_DIRECTORY_PATH>",
|
||||
annotations_directory_path="<ANNOTATIONS_DIRECTORY_PATH>",
|
||||
data_yaml_path="<DATA_YAML_PATH>",
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -382,8 +382,8 @@ sv.plot_images_grid(
|
|||
ds = sv.DetectionDataset(...)
|
||||
|
||||
ds.as_pascal_voc(
|
||||
images_directory_path='<IMAGE_DIRECTORY_PATH>',
|
||||
annotations_directory_path='<ANNOTATIONS_DIRECTORY_PATH>'
|
||||
images_directory_path="<IMAGE_DIRECTORY_PATH>",
|
||||
annotations_directory_path="<ANNOTATIONS_DIRECTORY_PATH>",
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -413,11 +413,11 @@ augmentation = A.Compose(
|
|||
transforms=[
|
||||
A.Perspective(p=0.1),
|
||||
A.HorizontalFlip(p=0.5),
|
||||
A.RandomBrightnessContrast(p=0.5)
|
||||
A.RandomBrightnessContrast(p=0.5),
|
||||
],
|
||||
bbox_params=A.BboxParams(
|
||||
format='pascal_voc',
|
||||
label_fields=['category']
|
||||
format="pascal_voc",
|
||||
label_fields=["category"],
|
||||
),
|
||||
)
|
||||
```
|
||||
|
|
@ -437,14 +437,14 @@ _, original_image, original_annotations = ds[0]
|
|||
output = augmentation(
|
||||
image=original_image,
|
||||
bboxes=original_annotations.xyxy,
|
||||
category=original_annotations.class_id
|
||||
category=original_annotations.class_id,
|
||||
)
|
||||
|
||||
augmented_image = output['image']
|
||||
augmented_image = output["image"]
|
||||
augmented_annotations = replace(
|
||||
original_annotations,
|
||||
xyxy=np.array(output['bboxes']),
|
||||
class_id=np.array(output['category'])
|
||||
xyxy=np.array(output["bboxes"]),
|
||||
class_id=np.array(output["category"]),
|
||||
)
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -19,34 +19,35 @@ model. You can learn more on this topic in our
|
|||
[How to Detect and Annotate](https://supervision.roboflow.com/latest/how_to/detect_and_annotate/) guide.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
for frame in frames_generator:
|
||||
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```python
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
for frame in frames_generator:
|
||||
|
||||
results = model(frame)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```python
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -54,10 +55,9 @@ model. You can learn more on this topic in our
|
|||
|
||||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
for frame in frames_generator:
|
||||
|
||||
frame = sv.cv2_to_pillow(frame)
|
||||
inputs = processor(images=frame, return_tensors="pt")
|
||||
|
||||
|
|
@ -67,7 +67,8 @@ model. You can learn more on this topic in our
|
|||
width, height = frame.size
|
||||
target_size = torch.tensor([[height, width]])
|
||||
results = processor.post_process_object_detection(
|
||||
outputs=outputs, target_sizes=target_size)[0]
|
||||
outputs=outputs, target_sizes=target_size
|
||||
)[0]
|
||||
detections = sv.Detections.from_transformers(results)
|
||||
```
|
||||
|
||||
|
|
@ -80,14 +81,15 @@ and then pass the
|
|||
object resulting from the inference to it. Its fields are parsed and saved on disk.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="7 12" }
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame in frames_generator:
|
||||
|
||||
results = model.infer(image)[0]
|
||||
|
|
@ -96,14 +98,15 @@ object resulting from the inference to it. Its fields are parsed and saved on di
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="7 12" }
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame in frames_generator:
|
||||
|
||||
results = model(frame)[0]
|
||||
|
|
@ -112,6 +115,7 @@ object resulting from the inference to it. Its fields are parsed and saved on di
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="9 23" }
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -119,9 +123,9 @@ object resulting from the inference to it. Its fields are parsed and saved on di
|
|||
|
||||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame in frames_generator:
|
||||
|
||||
frame = sv.cv2_to_pillow(frame)
|
||||
|
|
@ -154,14 +158,15 @@ also allows you to add custom information to each row, which can be passed via t
|
|||
frame index from which the detections originate.
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="8 12" }
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
results = model.infer(image)[0]
|
||||
|
|
@ -170,14 +175,15 @@ frame index from which the detections originate.
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="8 12" }
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
results = model(frame)[0]
|
||||
|
|
@ -186,6 +192,7 @@ frame index from which the detections originate.
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="10 23" }
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -193,9 +200,9 @@ frame index from which the detections originate.
|
|||
|
||||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.CSVSink(<TARGET_CSV_PATH>) as sink:
|
||||
with sv.CSVSink("<TARGET_CSV_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
frame = sv.cv2_to_pillow(frame)
|
||||
|
|
@ -227,14 +234,15 @@ with
|
|||
[`sv.JSONSink`](https://supervision.roboflow.com/latest/detection/tools/save_detections/#supervision.detection.tools.csv_sink.JSONSink).
|
||||
|
||||
=== "Inference"
|
||||
|
||||
```{ .py hl_lines="7" }
|
||||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.JSONSink(<TARGET_JSON_PATH>) as sink:
|
||||
with sv.JSONSink("<TARGET_JSON_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
results = model.infer(image)[0]
|
||||
|
|
@ -243,14 +251,15 @@ with
|
|||
```
|
||||
|
||||
=== "Ultralytics"
|
||||
|
||||
```{ .py hl_lines="7" }
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.JSONSink(<TARGET_JSON_PATH>) as sink:
|
||||
with sv.JSONSink("<TARGET_JSON_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
results = model(frame)[0]
|
||||
|
|
@ -259,6 +268,7 @@ with
|
|||
```
|
||||
|
||||
=== "Transformers"
|
||||
|
||||
```{ .py hl_lines="9" }
|
||||
import torch
|
||||
import supervision as sv
|
||||
|
|
@ -266,9 +276,9 @@ with
|
|||
|
||||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.JSONSink(<TARGET_JSON_PATH>) as sink:
|
||||
with sv.JSONSink("<TARGET_JSON_PATH>") as sink:
|
||||
for frame_index, frame in enumerate(frames_generator):
|
||||
|
||||
frame = sv.cv2_to_pillow(frame)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ it will be modified to include tracking, labeling, and trace annotations.
|
|||
import supervision as sv
|
||||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key=<ROBOFLOW API KEY>)
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
||||
def callback(frame: np.ndarray, _: int) -> np.ndarray:
|
||||
|
|
@ -133,7 +133,7 @@ enabling the continuous following of the object's motion path across different f
|
|||
import supervision as sv
|
||||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key=<ROBOFLOW API KEY>)
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
tracker = sv.ByteTrack()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ offering a clear visual representation of each object's class and unique identif
|
|||
import supervision as sv
|
||||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key=<ROBOFLOW API KEY>)
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
tracker = sv.ByteTrack()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
label_annotator = sv.LabelAnnotator()
|
||||
|
|
@ -285,7 +285,7 @@ movement patterns and interactions between objects in the video.
|
|||
import supervision as sv
|
||||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key=<ROBOFLOW API KEY>)
|
||||
model = get_roboflow_model(model_id="yolov8n-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
tracker = sv.ByteTrack()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
label_annotator = sv.LabelAnnotator()
|
||||
|
|
@ -381,7 +381,7 @@ Let's immediately visualize the results with our [`EdgeAnnotator`](https://super
|
|||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(
|
||||
model_id="yolov8m-pose-640", api_key=<ROBOFLOW API KEY>)
|
||||
model_id="yolov8m-pose-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
edge_annotator = sv.EdgeAnnotator()
|
||||
vertex_annotator = sv.VertexAnnotator()
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ Let's convert to detections and visualize the results with our [`BoxAnnotator`](
|
|||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(
|
||||
model_id="yolov8m-pose-640", api_key=<ROBOFLOW API KEY>)
|
||||
model_id="yolov8m-pose-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
edge_annotator = sv.EdgeAnnotator()
|
||||
vertex_annotator = sv.VertexAnnotator()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
|
@ -531,7 +531,7 @@ Now that we have a `Detections` object, we can track it throughout the video. Ut
|
|||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(
|
||||
model_id="yolov8m-pose-640", api_key=<ROBOFLOW API KEY>)
|
||||
model_id="yolov8m-pose-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
edge_annotator = sv.EdgeAnnotator()
|
||||
vertex_annotator = sv.VertexAnnotator()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
|
@ -616,7 +616,7 @@ We could stop here as we have successfully tracked the object detected by the ke
|
|||
from inference.models.utils import get_roboflow_model
|
||||
|
||||
model = get_roboflow_model(
|
||||
model_id="yolov8m-pose-640", api_key=<ROBOFLOW API KEY>)
|
||||
model_id="yolov8m-pose-640", api_key="<ROBOFLOW_API_KEY>")
|
||||
edge_annotator = sv.EdgeAnnotator()
|
||||
vertex_annotator = sv.VertexAnnotator()
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ You can install `supervision` in a
|
|||
!!! example "Installation"
|
||||
|
||||
=== "pip (recommended)"
|
||||
|
||||
[](https://badge.fury.io/py/supervision)
|
||||
[](https://pypistats.org/packages/supervision)
|
||||
[](../LICENSE.md)
|
||||
|
|
@ -52,6 +53,7 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
=== "poetry"
|
||||
|
||||
[](https://badge.fury.io/py/supervision)
|
||||
[](https://pypistats.org/packages/supervision)
|
||||
[](../LICENSE.md)
|
||||
|
|
@ -62,6 +64,7 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
=== "uv"
|
||||
|
||||
[](https://badge.fury.io/py/supervision)
|
||||
[](https://pypistats.org/packages/supervision)
|
||||
[](../LICENSE.md)
|
||||
|
|
@ -78,6 +81,7 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
=== "rye"
|
||||
|
||||
[](https://badge.fury.io/py/supervision)
|
||||
[](https://pypistats.org/packages/supervision)
|
||||
[](../LICENSE.md)
|
||||
|
|
@ -87,9 +91,10 @@ You can install `supervision` in a
|
|||
rye add supervision
|
||||
```
|
||||
|
||||
|
||||
!!! example "conda/mamba install"
|
||||
|
||||
=== "conda"
|
||||
|
||||
[](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision)
|
||||
|
||||
```bash
|
||||
|
|
@ -97,6 +102,7 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
=== "mamba"
|
||||
|
||||
[](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision) [](https://anaconda.org/conda-forge/supervision)
|
||||
|
||||
```bash
|
||||
|
|
@ -104,7 +110,9 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
!!! example "git clone (for development)"
|
||||
|
||||
=== "virtualenv"
|
||||
|
||||
```bash
|
||||
# clone repository and navigate to root directory
|
||||
git clone --depth 1 -b develop https://github.com/roboflow/supervision.git
|
||||
|
|
@ -120,6 +128,7 @@ You can install `supervision` in a
|
|||
```
|
||||
|
||||
=== "uv"
|
||||
|
||||
```bash
|
||||
# clone repository and navigate to root directory
|
||||
git clone --depth 1 -b develop https://github.com/roboflow/supervision.git
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ comments: true
|
|||
|
||||
vertex_annotator = sv.VertexAnnotator(
|
||||
color=sv.Color.GREEN,
|
||||
radius=10
|
||||
radius=10,
|
||||
)
|
||||
annotated_frame = vertex_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
key_points=key_points
|
||||
key_points=key_points,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -38,11 +38,11 @@ comments: true
|
|||
|
||||
edge_annotator = sv.EdgeAnnotator(
|
||||
color=sv.Color.GREEN,
|
||||
thickness=5
|
||||
thickness=5,
|
||||
)
|
||||
annotated_frame = edge_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
key_points=key_points
|
||||
key_points=key_points,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -63,11 +63,11 @@ comments: true
|
|||
vertex_label_annotator = sv.VertexLabelAnnotator(
|
||||
color=sv.Color.GREEN,
|
||||
text_color=sv.Color.BLACK,
|
||||
border_radius=5
|
||||
border_radius=5,
|
||||
)
|
||||
annotated_frame = vertex_label_annotator.annotate(
|
||||
scene=image.copy(),
|
||||
key_points=key_points
|
||||
key_points=key_points,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ class OrientedBoxAnnotator(BaseAnnotator):
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO("yolov8n-obb.pt")
|
||||
|
||||
result = model(image)[0]
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class Detections:
|
|||
from inference import get_model
|
||||
|
||||
model = get_model(model_id="yolov8n-640")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model.infer(image)[0]
|
||||
detections = sv.Detections.from_inference(results)
|
||||
```
|
||||
|
|
@ -90,7 +90,7 @@ class Detections:
|
|||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO("yolov8n.pt")
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
```
|
||||
|
|
@ -109,7 +109,7 @@ class Detections:
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -225,7 +225,7 @@ class Detections:
|
|||
import torch
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
|
||||
result = model(image)
|
||||
detections = sv.Detections.from_yolov5(result)
|
||||
|
|
@ -265,7 +265,7 @@ class Detections:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO('yolov8s.pt')
|
||||
results = model(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(results)
|
||||
|
|
@ -338,7 +338,7 @@ class Detections:
|
|||
from super_gradients.training import models
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = models.get('yolo_nas_l', pretrained_weights="coco")
|
||||
|
||||
result = list(model.predict(image, conf=0.35))[0]
|
||||
|
|
@ -452,8 +452,8 @@ class Detections:
|
|||
import supervision as sv
|
||||
from mmdet.apis import init_detector, inference_detector
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
model = init_detector(<CONFIG_PATH>, <WEIGHTS_PATH>, device=<DEVICE>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = init_detector("<CONFIG_PATH>", "<WEIGHTS_PATH>", device="<DEVICE>")
|
||||
|
||||
result = inference_detector(model, image)
|
||||
detections = sv.Detections.from_mmdetection(result)
|
||||
|
|
@ -501,7 +501,7 @@ class Detections:
|
|||
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
||||
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
||||
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
inputs = processor(images=image, return_tensors="pt")
|
||||
|
||||
with torch.no_grad():
|
||||
|
|
@ -570,10 +570,10 @@ class Detections:
|
|||
from detectron2.config import get_cfg
|
||||
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
cfg = get_cfg()
|
||||
cfg.merge_from_file(<CONFIG_PATH>)
|
||||
cfg.MODEL.WEIGHTS = <WEIGHTS_PATH>
|
||||
cfg.merge_from_file("<CONFIG_PATH>")
|
||||
cfg.MODEL.WEIGHTS = "<WEIGHTS_PATH>"
|
||||
predictor = DefaultPredictor(cfg)
|
||||
|
||||
result = predictor(image)
|
||||
|
|
@ -616,7 +616,7 @@ class Detections:
|
|||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = get_model(model_id="yolov8s-640")
|
||||
|
||||
result = model.infer(image)[0]
|
||||
|
|
@ -1689,7 +1689,7 @@ class Detections:
|
|||
import easyocr
|
||||
|
||||
reader = easyocr.Reader(['en'])
|
||||
results = reader.readtext(<SOURCE_IMAGE_PATH>)
|
||||
results = reader.readtext("<SOURCE_IMAGE_PATH>")
|
||||
detections = sv.Detections.from_easyocr(results)
|
||||
detected_text = detections["class_name"]
|
||||
```
|
||||
|
|
@ -1734,7 +1734,7 @@ class Detections:
|
|||
from ncnn.model_zoo import get_model
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = get_model(
|
||||
"yolov8s",
|
||||
target_size=640
|
||||
|
|
@ -2037,7 +2037,7 @@ class Detections:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO('yolov8s.pt')
|
||||
|
||||
result = model(image)[0]
|
||||
|
|
@ -2300,7 +2300,7 @@ def merge_inner_detection_object_pair(
|
|||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = get_model(model_id="yolov8s-640")
|
||||
|
||||
result = model.infer(image)[0]
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ class LineZone:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO(<SOURCE_MODEL_PATH>)
|
||||
model = YOLO("<SOURCE_MODEL_PATH>")
|
||||
tracker = sv.ByteTrack()
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
start, end = sv.Point(x=0, y=1080), sv.Point(x=3840, y=1080)
|
||||
line_zone = sv.LineZone(start=start, end=end)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,15 +28,15 @@ class JSONSink:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO(<SOURCE_MODEL_PATH>)
|
||||
model = YOLO("<SOURCE_MODEL_PATH>")
|
||||
json_sink = sv.JSONSink(<RESULT_JSON_FILE_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with json_sink as sink:
|
||||
for frame in frames_generator:
|
||||
result = model(frame)[0]
|
||||
detections = sv.Detections.from_ultralytics(result)
|
||||
sink.append(detections, custom_data={'<CUSTOM_LABEL>':'<CUSTOM_DATA>'})
|
||||
sink.append(detections, custom_data={"<CUSTOM_LABEL>":"<CUSTOM_DATA>"})
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class PolygonZone:
|
|||
import numpy as np
|
||||
import cv2
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO("yolo11s")
|
||||
tracker = sv.ByteTrack()
|
||||
|
||||
|
|
|
|||
|
|
@ -35,16 +35,17 @@ class DetectionsSmoother:
|
|||
|
||||
from ultralytics import YOLO
|
||||
|
||||
video_info = sv.VideoInfo.from_video_path(video_path=<SOURCE_FILE_PATH>)
|
||||
frame_generator = sv.get_video_frames_generator(source_path=<SOURCE_FILE_PATH>)
|
||||
video_info = sv.VideoInfo.from_video_path(video_path="<SOURCE_FILE_PATH>")
|
||||
frame_generator = sv.get_video_frames_generator(
|
||||
source_path="<SOURCE_FILE_PATH>")
|
||||
|
||||
model = YOLO(<MODEL_PATH>)
|
||||
model = YOLO("<MODEL_PATH>")
|
||||
tracker = sv.ByteTrack(frame_rate=video_info.fps)
|
||||
smoother = sv.DetectionsSmoother()
|
||||
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
||||
with sv.VideoSink(<TARGET_FILE_PATH>, video_info=video_info) as sink:
|
||||
with sv.VideoSink("<TARGET_FILE_PATH>", video_info=video_info) as sink:
|
||||
for frame in frame_generator:
|
||||
result = model(frame)[0]
|
||||
detections = sv.Detections.from_ultralytics(result)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO('yolo11s-pose.pt')
|
||||
|
||||
result = model(image)[0]
|
||||
|
|
@ -49,8 +49,8 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
model = get_model(model_id=<POSE_MODEL_ID>, api_key=<ROBOFLOW_API_KEY>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = get_model(model_id="<POSE_MODEL_ID>", api_key="<ROBOFLOW_API_KEY>")
|
||||
|
||||
result = model.infer(image)[0]
|
||||
key_points = sv.KeyPoints.from_inference(result)
|
||||
|
|
@ -68,7 +68,7 @@ class KeyPoints:
|
|||
import mediapipe as mp
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
image_height, image_width, _ = image.shape
|
||||
mediapipe_image = mp.Image(
|
||||
image_format=mp.ImageFormat.SRGB,
|
||||
|
|
@ -106,7 +106,7 @@ class KeyPoints:
|
|||
)
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
DETECTION_MODEL_ID = "PekingU/rtdetr_r50vd_coco_o365"
|
||||
|
||||
|
|
@ -228,8 +228,8 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from inference import get_model
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
model = get_model(model_id=<POSE_MODEL_ID>, api_key=<ROBOFLOW_API_KEY>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = get_model(model_id="<POSE_MODEL_ID>", api_key="<ROBOFLOW_API_KEY>")
|
||||
|
||||
result = model.infer(image)[0]
|
||||
key_points = sv.KeyPoints.from_inference(result)
|
||||
|
|
@ -240,13 +240,13 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from inference_sdk import InferenceHTTPClient
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
client = InferenceHTTPClient(
|
||||
api_url="https://detect.roboflow.com",
|
||||
api_key=<ROBOFLOW_API_KEY>
|
||||
api_key="<ROBOFLOW_API_KEY>"
|
||||
)
|
||||
|
||||
result = client.infer(image, model_id=<POSE_MODEL_ID>)
|
||||
result = client.infer(image, model_id="<POSE_MODEL_ID>")
|
||||
key_points = sv.KeyPoints.from_inference(result)
|
||||
```
|
||||
"""
|
||||
|
|
@ -320,7 +320,7 @@ class KeyPoints:
|
|||
import mediapipe as mp
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
image_height, image_width, _ = image.shape
|
||||
mediapipe_image = mp.Image(
|
||||
image_format=mp.ImageFormat.SRGB,
|
||||
|
|
@ -346,7 +346,7 @@ class KeyPoints:
|
|||
import mediapipe as mp
|
||||
import supervision as sv
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
image_height, image_width, _ = image.shape
|
||||
mediapipe_image = mp.Image(
|
||||
image_format=mp.ImageFormat.SRGB,
|
||||
|
|
@ -436,7 +436,7 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO('yolov8s-pose.pt')
|
||||
|
||||
result = model(image)[0]
|
||||
|
|
@ -475,7 +475,7 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
import super_gradients
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
model = super_gradients.training.models.get(
|
||||
|
|
@ -535,10 +535,10 @@ class KeyPoints:
|
|||
from detectron2.config import get_cfg
|
||||
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
cfg = get_cfg()
|
||||
cfg.merge_from_file(<CONFIG_PATH>)
|
||||
cfg.MODEL.WEIGHTS = <WEIGHTS_PATH>
|
||||
cfg.merge_from_file("<CONFIG_PATH>")
|
||||
cfg.MODEL.WEIGHTS = "<WEIGHTS_PATH>"
|
||||
predictor = DefaultPredictor(cfg)
|
||||
|
||||
result = predictor(image)
|
||||
|
|
@ -591,7 +591,7 @@ class KeyPoints:
|
|||
)
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
image = Image.open(<SOURCE_IMAGE_PATH>)
|
||||
image = Image.open("<SOURCE_IMAGE_PATH>")
|
||||
|
||||
DETECTION_MODEL_ID = "PekingU/rtdetr_r50vd_coco_o365"
|
||||
|
||||
|
|
@ -728,7 +728,7 @@ class KeyPoints:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
image = cv2.imread(<SOURCE_IMAGE_PATH>)
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO('yolov8s.pt')
|
||||
|
||||
result = model(image)[0]
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class ByteTrack:
|
|||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO(<MODEL_PATH>)
|
||||
model = YOLO("<MODEL_PATH>")
|
||||
tracker = sv.ByteTrack()
|
||||
|
||||
box_annotator = sv.BoxAnnotator()
|
||||
|
|
@ -95,8 +95,8 @@ class ByteTrack:
|
|||
return annotated_frame
|
||||
|
||||
sv.process_video(
|
||||
source_path=<SOURCE_VIDEO_PATH>,
|
||||
target_path=<TARGET_VIDEO_PATH>,
|
||||
source_path="<SOURCE_VIDEO_PATH>",
|
||||
target_path="<TARGET_VIDEO_PATH>",
|
||||
callback=callback
|
||||
)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class VideoInfo:
|
|||
```python
|
||||
import supervision as sv
|
||||
|
||||
video_info = sv.VideoInfo.from_video_path(video_path=<SOURCE_VIDEO_FILE>)
|
||||
video_info = sv.VideoInfo.from_video_path(video_path="<SOURCE_VIDEO_FILE>")
|
||||
|
||||
video_info
|
||||
# VideoInfo(width=3840, height=2160, fps=25, total_frames=538)
|
||||
|
|
@ -78,10 +78,10 @@ class VideoSink:
|
|||
```python
|
||||
import supervision as sv
|
||||
|
||||
video_info = sv.VideoInfo.from_video_path(<SOURCE_VIDEO_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
|
||||
video_info = sv.VideoInfo.from_video_path("<SOURCE_VIDEO_PATH>")
|
||||
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
|
||||
|
||||
with sv.VideoSink(target_path=<TARGET_VIDEO_PATH>, video_info=video_info) as sink:
|
||||
with sv.VideoSink(target_path="<TARGET_VIDEO_PATH>", video_info=video_info) as sink:
|
||||
for frame in frames_generator:
|
||||
sink.write_frame(frame=frame)
|
||||
```
|
||||
|
|
@ -182,7 +182,7 @@ def get_video_frames_generator(
|
|||
```python
|
||||
import supervision as sv
|
||||
|
||||
for frame in sv.get_video_frames_generator(source_path=<SOURCE_VIDEO_PATH>):
|
||||
for frame in sv.get_video_frames_generator(source_path="<SOURCE_VIDEO_PATH>"):
|
||||
...
|
||||
```
|
||||
"""
|
||||
|
|
@ -379,7 +379,8 @@ class FPSMonitor:
|
|||
```python
|
||||
import supervision as sv
|
||||
|
||||
frames_generator = sv.get_video_frames_generator(source_path=<SOURCE_FILE_PATH>)
|
||||
frames_generator = sv.get_video_frames_generator(
|
||||
source_path="<SOURCE_FILE_PATH>")
|
||||
fps_monitor = sv.FPSMonitor()
|
||||
|
||||
for frame in frames_generator:
|
||||
|
|
@ -387,7 +388,7 @@ class FPSMonitor:
|
|||
fps_monitor.tick()
|
||||
fps = fps_monitor.fps
|
||||
```
|
||||
""" # noqa: E501 // docs
|
||||
"""
|
||||
self.all_timestamps: deque[float] = deque(maxlen=sample_size)
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in New Issue