From 22de23ec8dcd192bd9a88b20e620c385df0ae4fe Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 27 May 2024 22:35:45 +0200 Subject: [PATCH] `ultralytics 8.2.23` New YouTube Shorts inference (#13150) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant Co-authored-by: Erfan Zekri Esfahani <40582518+eze1376@users.noreply.github.com> --- docs/en/guides/triton-inference-server.md | 4 ++- docs/en/integrations/tensorrt.md | 2 +- mkdocs.yml | 4 +-- tests/test_python.py | 11 ++------ ultralytics/__init__.py | 2 +- ultralytics/data/loaders.py | 31 ++++++++++++++++++----- ultralytics/data/utils.py | 2 +- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/docs/en/guides/triton-inference-server.md b/docs/en/guides/triton-inference-server.md index f7d1a9b8..ddc9c145 100644 --- a/docs/en/guides/triton-inference-server.md +++ b/docs/en/guides/triton-inference-server.md @@ -62,8 +62,9 @@ The Triton Model Repository is a storage location where Triton can access and lo from pathlib import Path # Define paths + model_name = "yolo" triton_repo_path = Path("tmp") / "triton_repo" - triton_model_path = triton_repo_path / "yolo" + triton_model_path = triton_repo_path / model_name # Create directories (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: ```python +import contextlib import subprocess import time diff --git a/docs/en/integrations/tensorrt.md b/docs/en/integrations/tensorrt.md index 42012223..75eaa2e7 100644 --- a/docs/en/integrations/tensorrt.md +++ b/docs/en/integrations/tensorrt.md @@ -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. - - Aim to use the minimum `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). diff --git a/mkdocs.yml b/mkdocs.yml index a51b12a4..dd112aad 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -5,8 +5,8 @@ # Material theme, define the navigation structure, and enable various plugins. # Site metadata -site_name: Ultralytics YOLOv8 Docs -site_description: Explore Ultralytics YOLOv8, a cutting-edge real-time object detection and image segmentation model for various applications and hardware platforms. +site_name: Ultralytics YOLO Docs +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_author: Ultralytics repo_url: https://github.com/ultralytics/ultralytics diff --git a/tests/test_python.py b/tests/test_python.py index 2687b1d3..184f8945 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -7,7 +7,6 @@ from pathlib import Path import cv2 import numpy as np import pytest -import requests import torch import yaml from PIL import Image @@ -20,7 +19,6 @@ from ultralytics.utils import ( ASSETS, DEFAULT_CFG, DEFAULT_CFG_PATH, - LOGGER, ONLINE, ROOT, WEIGHTS_DIR, @@ -135,15 +133,10 @@ def test_youtube(): """ Test YouTube inference. - Note: YouTube connection errors frequently occur during this test due to - the nature of network instability or YouTube server availability issues. - These errors are caught and logged to avoid test failures caused by external factors. + Note: ConnectionError may occur during this test due to network instability or YouTube server availability. """ model = YOLO(MODEL) - try: - 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}") + model.predict("https://youtu.be/G17sBkb38XQ", imgsz=96, save=True) @pytest.mark.skipif(not ONLINE, reason="environment is offline") diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index edc0762b..338d4679 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.22" +__version__ = "8.2.23" from ultralytics.data.explorer.explorer import Explorer from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld diff --git a/ultralytics/data/loaders.py b/ultralytics/data/loaders.py index 587ab1f9..d3ca664e 100644 --- a/ultralytics/data/loaders.py +++ b/ultralytics/data/loaders.py @@ -325,7 +325,7 @@ class LoadImagesAndVideos: paths, imgs, info = [], [], [] while len(imgs) < self.bs: if self.count >= self.nf: # end of file list - if len(imgs) > 0: + if imgs: return paths, imgs, info # return last partial batch else: raise StopIteration @@ -522,26 +522,43 @@ def autocast_list(source): 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. - This function uses the pafy or yt_dlp library to extract the video info from YouTube. It then finds the highest - quality MP4 format that has video codec but no audio codec, and returns the URL of this video stream. + This function uses the specified method to extract the video info from YouTube. It supports the following methods: + - "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: 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: (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")) import pafy # noqa return pafy.new(url).getbestvideo(preftype="mp4").url - else: + + elif method == "yt-dlp": check_requirements("yt-dlp") import yt_dlp diff --git a/ultralytics/data/utils.py b/ultralytics/data/utils.py index 61d2edf6..fa9bfbb1 100644 --- a/ultralytics/data/utils.py +++ b/ultralytics/data/utils.py @@ -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.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 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