|
|
|
@ -7,27 +7,28 @@ from pathlib import Path |
|
|
|
|
import cv2 |
|
|
|
|
import numpy as np |
|
|
|
|
import pytest |
|
|
|
|
import requests |
|
|
|
|
import torch |
|
|
|
|
import yaml |
|
|
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
|
from tests import CFG, IS_TMP_WRITEABLE, MODEL, SOURCE, TMP |
|
|
|
|
from ultralytics import RTDETR, YOLO |
|
|
|
|
from ultralytics.cfg import MODELS, TASKS, TASK2DATA |
|
|
|
|
from ultralytics.cfg import MODELS, TASK2DATA, TASKS |
|
|
|
|
from ultralytics.data.build import load_inference_source |
|
|
|
|
from ultralytics.utils import ( |
|
|
|
|
ASSETS, |
|
|
|
|
DEFAULT_CFG, |
|
|
|
|
DEFAULT_CFG_PATH, |
|
|
|
|
LOGGER, |
|
|
|
|
ONLINE, |
|
|
|
|
ROOT, |
|
|
|
|
WEIGHTS_DIR, |
|
|
|
|
WINDOWS, |
|
|
|
|
Retry, |
|
|
|
|
checks, |
|
|
|
|
) |
|
|
|
|
from ultralytics.utils.downloads import download, is_url |
|
|
|
|
from ultralytics.utils.downloads import download |
|
|
|
|
from ultralytics.utils.torch_utils import TORCH_1_9 |
|
|
|
|
from tests import CFG, IS_TMP_WRITEABLE, MODEL, SOURCE, TMP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_model_forward(): |
|
|
|
@ -130,16 +131,19 @@ def test_predict_grey_and_4ch(): |
|
|
|
|
|
|
|
|
|
@pytest.mark.slow |
|
|
|
|
@pytest.mark.skipif(not ONLINE, reason="environment is offline") |
|
|
|
|
@pytest.mark.skipif(not is_url("https://youtu.be/G17sBkb38XQ"), reason="YouTube URL issue") |
|
|
|
|
@Retry(times=3, delay=10) |
|
|
|
|
def test_youtube(): |
|
|
|
|
""" |
|
|
|
|
Test YouTube inference. |
|
|
|
|
|
|
|
|
|
Marked --slow to reduce YouTube API rate limits risk. |
|
|
|
|
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. |
|
|
|
|
""" |
|
|
|
|
model = YOLO(MODEL) |
|
|
|
|
model.predict("https://youtu.be/G17sBkb38XQ", imgsz=96, save=True) |
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not ONLINE, reason="environment is offline") |
|
|
|
|