Standardize license headers in Python files (#13490)

* Refactor code for speed and clarity

* Auto-format by https://ultralytics.com/actions

---------

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
pull/13491/head
Paula Derrenger 2025-01-15 15:31:19 +01:00 committed by GitHub
parent 6420a1db87
commit c568972d59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
52 changed files with 67 additions and 64 deletions

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Run YOLOv5 benchmarks on all supported export formats.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Run YOLOv5 classification inference on images, videos, directories, globs, YouTube, webcam, streams, etc.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Train a YOLOv5 classifier model on a classification dataset.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Validate a trained YOLOv5 classification model on a classification dataset.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Run YOLOv5 detection inference on images, videos, directories, globs, YouTube, webcam, streams, etc.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Export a YOLOv5 PyTorch model to other formats. TensorFlow exports authored by https://github.com/zldrobit.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
PyTorch Hub models https://pytorch.org/hub/ultralytics_yolov5.

View File

@ -0,0 +1 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Common modules."""
import ast
@ -750,9 +750,8 @@ class DetectMultiBackend(nn.Module):
scale, zero_point = output["quantization"]
x = (x.astype(np.float32) - zero_point) * scale # re-scale
y.append(x)
if len(y) == 2: # segment with (det, proto) output order reversed
if len(y[1].shape) != 4:
y = list(reversed(y)) # should be y = (1, 116, 8400), (1, 160, 160, 32)
if len(y) == 2 and len(y[1].shape) != 4:
y = list(reversed(y))
y = [x if isinstance(x, np.ndarray) else x.numpy() for x in y]
y[0][..., :4] *= [w, h, w, h] # xywh normalized to pixels

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Experimental modules."""
import math

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
TensorFlow, Keras and TFLite versions of YOLOv5
Authored by https://github.com/zldrobit in PR https://github.com/ultralytics/yolov5/pull/1127.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
YOLO-specific modules.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Run YOLOv5 segmentation inference on images, videos, directories, streams, etc.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Train a YOLOv5 segment model on a segment dataset Models and datasets download automatically from the latest YOLOv5
release.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Validate a trained YOLOv5 segment model on a segment dataset.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Train a YOLOv5 model on a custom dataset. Models and datasets download automatically from the latest YOLOv5 release.

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""utils/initialization."""
import contextlib

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Activation functions."""
import torch

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Image augmentation functions."""
import math

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""AutoAnchor utils."""
import random

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Auto-batch utils."""
from copy import deepcopy

View File

@ -0,0 +1 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

View File

@ -1,4 +1,5 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# Resume all interrupted trainings in yolov5/ dir including DDP trainings
# Usage: $ python utils/aws/resume.py

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Callback utils."""
import threading

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Dataloaders and dataset utils."""
import contextlib
@ -355,9 +355,9 @@ class LoadImages:
self._new_video(videos[0]) # new video
else:
self.cap = None
assert (
self.nf > 0
), f"No images or videos found in {p}. Supported formats are:\nimages: {IMG_FORMATS}\nvideos: {VID_FORMATS}"
assert self.nf > 0, (
f"No images or videos found in {p}. Supported formats are:\nimages: {IMG_FORMATS}\nvideos: {VID_FORMATS}"
)
def __iter__(self):
"""Initializes iterator by resetting count and returns the iterator object itself."""

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Download utils."""
import logging

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Perform test request."""
import pprint

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Run a Flask REST API exposing one or more YOLOv5s models."""
import argparse

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""General utils."""
import contextlib
@ -495,9 +495,9 @@ def check_file(file, suffix=""):
assert Path(file).exists() and Path(file).stat().st_size > 0, f"File download failed: {url}" # check
return file
elif file.startswith("clearml://"): # ClearML Dataset ID
assert (
"clearml" in sys.modules
), "ClearML is not installed, so cannot use ClearML dataset. Try running 'pip install clearml'."
assert "clearml" in sys.modules, (
"ClearML is not installed, so cannot use ClearML dataset. Try running 'pip install clearml'."
)
return file
else: # search
files = []

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Logging utils."""
import json

View File

@ -4,7 +4,7 @@
## About ClearML
[ClearML](https://clear.ml/) is an [open-source](https://github.com/allegroai/clearml) toolbox designed to save you time ⏱️.
[ClearML](https://clear.ml/) is an [open-source](https://github.com/clearml/clearml) toolbox designed to save you time ⏱️.
🔨 Track every YOLOv5 training run in the <b>experiment manager</b>

View File

@ -0,0 +1 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Main Logger class for ClearML experiment tracking."""
import glob
@ -41,11 +41,9 @@ def construct_dataset(clearml_info_string):
with open(yaml_filenames[0]) as f:
dataset_definition = yaml.safe_load(f)
assert set(
dataset_definition.keys()
).issuperset(
{"train", "test", "val", "nc", "names"}
), "The right keys were not found in the yaml file, make sure it at least has the following keys: ('train', 'test', 'val', 'nc', 'names')"
assert set(dataset_definition.keys()).issuperset({"train", "test", "val", "nc", "names"}), (
"The right keys were not found in the yaml file, make sure it at least has the following keys: ('train', 'test', 'val', 'nc', 'names')"
)
data_dict = {
"train": (

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
from clearml import Task

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import glob
import json

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import logging
import os

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import argparse
import json

View File

@ -0,0 +1 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# WARNING ⚠️ wandb is deprecated and will be removed in future release.
# See supported integrations at https://github.com/ultralytics/yolov5#integrations

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Loss functions."""
import torch

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Model validation metrics."""
import math

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Plotting utils."""
import contextlib

View File

@ -0,0 +1 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Image augmentation functions."""
import math

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Dataloaders."""
import os

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import cv2
import numpy as np

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import torch
import torch.nn as nn

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Model validation metrics."""
import numpy as np

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import contextlib
import math

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""PyTorch utils."""
import math
@ -121,9 +121,9 @@ def select_device(device="", batch_size=0, newline=True):
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # force torch.cuda.is_available() = False
elif device: # non-cpu device requested
os.environ["CUDA_VISIBLE_DEVICES"] = device # set environment variable - must be before assert is_available()
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(
device.replace(",", "")
), f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(",", "")), (
f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"
)
if not cpu and not mps and torch.cuda.is_available(): # prefer GPU if available
devices = device.split(",") if device else "0" # range(torch.cuda.device_count()) # i.e. 0,1,6,7

View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""Utils to interact with the Triton Inference Server."""
import typing

2
val.py
View File

@ -1,4 +1,4 @@
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
"""
Validate a trained YOLOv5 detection model on a detection dataset.