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
Download src/utils/video_reader.py from mayanktak15/yolo8: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/mayanktak15/yolo8/resolve/main/src/utils/video_reader.py
- Command line
-
hf download hf://mayanktak15/yolo8/src/utils/video_reader.py
-
curl -L -o video_reader.py https://huggingface.co/mayanktak15/yolo8/resolve/main/src/utils/video_reader.py
1.26 kB
| """Video reading wrapper around OpenCV.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Iterator | |
| import cv2 | |
| import numpy as np | |
| class VideoReader: | |
| """Iterate over frames from a video file.""" | |
| def __init__(self, video_path: str | Path) -> None: | |
| self.video_path = Path(video_path) | |
| self.capture = cv2.VideoCapture(str(self.video_path)) | |
| if not self.capture.isOpened(): | |
| raise FileNotFoundError(f"Could not open video: {self.video_path}") | |
| self.fps = float(self.capture.get(cv2.CAP_PROP_FPS) or 30.0) | |
| self.width = int(self.capture.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
| self.height = int(self.capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| self.frame_count = int(self.capture.get(cv2.CAP_PROP_FRAME_COUNT)) | |
| def __iter__(self) -> Iterator[tuple[int, np.ndarray]]: | |
| frame_index = 0 | |
| while True: | |
| ok, frame = self.capture.read() | |
| if not ok: | |
| break | |
| yield frame_index, frame | |
| frame_index += 1 | |
| def release(self) -> None: | |
| self.capture.release() | |
| def __enter__(self) -> "VideoReader": | |
| return self | |
| def __exit__(self, *_: object) -> None: | |
| self.release() | |