ultralytics 8.2.23 New YouTube Shorts inference (#13150)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Erfan Zekri Esfahani <40582518+eze1376@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2024-05-27 22:35:45 +02:00 committed by GitHub
parent c371c953d5
commit 22de23ec8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 22 deletions

View file

@ -62,8 +62,9 @@ The Triton Model Repository is a storage location where Triton can access and lo
from pathlib import Path from pathlib import Path
# Define paths # Define paths
model_name = "yolo"
triton_repo_path = Path("tmp") / "triton_repo" triton_repo_path = Path("tmp") / "triton_repo"
triton_model_path = triton_repo_path / "yolo" triton_model_path = triton_repo_path / model_name
# Create directories # Create directories
(triton_model_path / "1").mkdir(parents=True, exist_ok=True) (triton_model_path / "1").mkdir(parents=True, exist_ok=True)
@ -86,6 +87,7 @@ The Triton Model Repository is a storage location where Triton can access and lo
Run the Triton Inference Server using Docker: Run the Triton Inference Server using Docker:
```python ```python
import contextlib
import subprocess import subprocess
import time import time

View file

@ -125,7 +125,7 @@ The arguments provided when using [export](../modes/export.md) for an Ultralytic
- `workspace` : Controls the size (in GiB) of the device memory allocation while converting the model weights. - `workspace` : Controls the size (in GiB) of the device memory allocation while converting the model weights.
- Aim to use the <u>minimum</u> `workspace` value required as this prevents testing algorithms that require more `workspace` from being considered by the TensorRT builder. Setting a higher value for `workspace` may take **considerably longer** to calibrate and export. - Adjust the `workspace` value according to your calibration needs and resource availability. While a larger `workspace` may increase calibration time, it allows TensorRT to explore a wider range of optimization tactics, potentially enhancing model performance and accuracy. Conversely, a smaller `workspace` can reduce calibration time but may limit the optimization strategies, affecting the quality of the quantized model.
- Default is `workspace=4` (GiB), this value may need to be increased if calibration crashes (exits without warning). - Default is `workspace=4` (GiB), this value may need to be increased if calibration crashes (exits without warning).

View file

@ -5,8 +5,8 @@
# Material theme, define the navigation structure, and enable various plugins. # Material theme, define the navigation structure, and enable various plugins.
# Site metadata # Site metadata
site_name: Ultralytics YOLOv8 Docs site_name: Ultralytics YOLO Docs
site_description: Explore Ultralytics YOLOv8, a cutting-edge real-time object detection and image segmentation model for various applications and hardware platforms. site_description: Explore Ultralytics YOLO, a cutting-edge real-time object detection and image segmentation model for various applications and hardware platforms.
site_url: https://docs.ultralytics.com site_url: https://docs.ultralytics.com
site_author: Ultralytics site_author: Ultralytics
repo_url: https://github.com/ultralytics/ultralytics repo_url: https://github.com/ultralytics/ultralytics

View file

@ -7,7 +7,6 @@ from pathlib import Path
import cv2 import cv2
import numpy as np import numpy as np
import pytest import pytest
import requests
import torch import torch
import yaml import yaml
from PIL import Image from PIL import Image
@ -20,7 +19,6 @@ from ultralytics.utils import (
ASSETS, ASSETS,
DEFAULT_CFG, DEFAULT_CFG,
DEFAULT_CFG_PATH, DEFAULT_CFG_PATH,
LOGGER,
ONLINE, ONLINE,
ROOT, ROOT,
WEIGHTS_DIR, WEIGHTS_DIR,
@ -135,15 +133,10 @@ def test_youtube():
""" """
Test YouTube inference. Test YouTube inference.
Note: YouTube connection errors frequently occur during this test due to Note: ConnectionError may occur during this test due to network instability or YouTube server availability.
the nature of network instability or YouTube server availability issues.
These errors are caught and logged to avoid test failures caused by external factors.
""" """
model = YOLO(MODEL) model = YOLO(MODEL)
try:
model.predict("https://youtu.be/G17sBkb38XQ", imgsz=96, save=True) model.predict("https://youtu.be/G17sBkb38XQ", imgsz=96, save=True)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as e:
LOGGER.warning(f"YouTube connection error: {e}")
@pytest.mark.skipif(not ONLINE, reason="environment is offline") @pytest.mark.skipif(not ONLINE, reason="environment is offline")

View file

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license # Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = "8.2.22" __version__ = "8.2.23"
from ultralytics.data.explorer.explorer import Explorer from ultralytics.data.explorer.explorer import Explorer
from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld

View file

@ -325,7 +325,7 @@ class LoadImagesAndVideos:
paths, imgs, info = [], [], [] paths, imgs, info = [], [], []
while len(imgs) < self.bs: while len(imgs) < self.bs:
if self.count >= self.nf: # end of file list if self.count >= self.nf: # end of file list
if len(imgs) > 0: if imgs:
return paths, imgs, info # return last partial batch return paths, imgs, info # return last partial batch
else: else:
raise StopIteration raise StopIteration
@ -522,26 +522,43 @@ def autocast_list(source):
return files return files
def get_best_youtube_url(url, use_pafy=True): def get_best_youtube_url(url, method="pytube"):
""" """
Retrieves the URL of the best quality MP4 video stream from a given YouTube video. Retrieves the URL of the best quality MP4 video stream from a given YouTube video.
This function uses the pafy or yt_dlp library to extract the video info from YouTube. It then finds the highest This function uses the specified method to extract the video info from YouTube. It supports the following methods:
quality MP4 format that has video codec but no audio codec, and returns the URL of this video stream. - "pytube": Uses the pytube library to fetch the video streams.
- "pafy": Uses the pafy library to fetch the video streams.
- "yt-dlp": Uses the yt-dlp library to fetch the video streams.
The function then finds the highest quality MP4 format that has a video codec but no audio codec, and returns the
URL of this video stream.
Args: Args:
url (str): The URL of the YouTube video. url (str): The URL of the YouTube video.
use_pafy (bool): Use the pafy package, default=True, otherwise use yt_dlp package. method (str): The method to use for extracting video info. Default is "pytube". Other options are "pafy" and
"yt-dlp".
Returns: Returns:
(str): The URL of the best quality MP4 video stream, or None if no suitable stream is found. (str): The URL of the best quality MP4 video stream, or None if no suitable stream is found.
""" """
if use_pafy: if method == "pytube":
check_requirements("pytube")
from pytube import YouTube
streams = YouTube(url).streams.filter(file_extension="mp4", only_video=True)
streams = sorted(streams, key=lambda s: s.resolution, reverse=True) # sort streams by resolution
for stream in streams:
if stream.resolution and int(stream.resolution[:-1]) >= 1080: # check if resolution is at least 1080p
return stream.url
elif method == "pafy":
check_requirements(("pafy", "youtube_dl==2020.12.2")) check_requirements(("pafy", "youtube_dl==2020.12.2"))
import pafy # noqa import pafy # noqa
return pafy.new(url).getbestvideo(preftype="mp4").url return pafy.new(url).getbestvideo(preftype="mp4").url
else:
elif method == "yt-dlp":
check_requirements("yt-dlp") check_requirements("yt-dlp")
import yt_dlp import yt_dlp

View file

@ -35,7 +35,7 @@ from ultralytics.utils.checks import check_file, check_font, is_ascii
from ultralytics.utils.downloads import download, safe_download, unzip_file from ultralytics.utils.downloads import download, safe_download, unzip_file
from ultralytics.utils.ops import segments2boxes from ultralytics.utils.ops import segments2boxes
HELP_URL = "See https://docs.ultralytics.com/datasets/detect for dataset formatting guidance." HELP_URL = "See https://docs.ultralytics.com/datasets for dataset formatting guidance."
IMG_FORMATS = {"bmp", "dng", "jpeg", "jpg", "mpo", "png", "tif", "tiff", "webp", "pfm"} # image suffixes IMG_FORMATS = {"bmp", "dng", "jpeg", "jpg", "mpo", "png", "tif", "tiff", "webp", "pfm"} # image suffixes
VID_FORMATS = {"asf", "avi", "gif", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "ts", "wmv", "webm"} # video suffixes VID_FORMATS = {"asf", "avi", "gif", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "ts", "wmv", "webm"} # video suffixes
PIN_MEMORY = str(os.getenv("PIN_MEMORY", True)).lower() == "true" # global pin_memory for dataloaders PIN_MEMORY = str(os.getenv("PIN_MEMORY", True)).lower() == "true" # global pin_memory for dataloaders