Instructions to use mayanktak15/yolo8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use mayanktak15/yolo8 with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("mayanktak15/yolo8", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
File size: 1,139 Bytes
c94751c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """Trajectory rendering helpers."""
from __future__ import annotations
from collections.abc import Sequence
import cv2
import numpy as np
def draw_trajectory(
frame: np.ndarray,
points: Sequence[tuple[float, float]],
color: tuple[int, int, int],
thickness: int = 2,
) -> np.ndarray:
"""Draw a motion trail on a frame."""
if len(points) < 2:
return frame
int_points = [(int(x), int(y)) for x, y in points]
for start, end in zip(int_points[:-1], int_points[1:], strict=False):
cv2.line(frame, start, end, color, thickness, lineType=cv2.LINE_AA)
return frame
def relative_speed(points: Sequence[tuple[int, float, float]]) -> float:
"""Estimate average pixel displacement per frame for a trajectory."""
if len(points) < 2:
return 0.0
speeds: list[float] = []
for (frame_a, x_a, y_a), (frame_b, x_b, y_b) in zip(points[:-1], points[1:], strict=False):
frame_delta = max(frame_b - frame_a, 1)
distance = float(np.hypot(x_b - x_a, y_b - y_a))
speeds.append(distance / frame_delta)
return float(np.mean(speeds)) if speeds else 0.0
|