Skip to content

Commit

Permalink
Standardize license headers in Python files (#13490)
Browse files Browse the repository at this point in the history
* Refactor code for speed and clarity

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

---------

Co-authored-by: Glenn Jocher <[email protected]>
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 6420a1d commit c568972
Show file tree
Hide file tree
Showing 52 changed files with 67 additions and 64 deletions.
2 changes: 1 addition & 1 deletion benchmarks.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion classify/predict.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion classify/train.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion classify/val.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion detect.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion export.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion hubconf.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
7 changes: 3 additions & 4 deletions models/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Common modules."""

import ast
Expand Down Expand Up @@ -750,9 +750,8 @@ def forward(self, im, augment=False, visualize=False):
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

Expand Down
2 changes: 1 addition & 1 deletion models/experimental.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Experimental modules."""

import math
Expand Down
2 changes: 1 addition & 1 deletion models/tf.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""
YOLO-specific modules.
Expand Down
2 changes: 1 addition & 1 deletion segment/predict.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion segment/train.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion segment/val.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""utils/initialization."""

import contextlib
Expand Down
2 changes: 1 addition & 1 deletion utils/activations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Activation functions."""

import torch
Expand Down
2 changes: 1 addition & 1 deletion utils/augmentations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Image augmentation functions."""

import math
Expand Down
2 changes: 1 addition & 1 deletion utils/autoanchor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""AutoAnchor utils."""

import random
Expand Down
2 changes: 1 addition & 1 deletion utils/autobatch.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions utils/aws/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
3 changes: 2 additions & 1 deletion utils/aws/resume.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion utils/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Callback utils."""

import threading
Expand Down
8 changes: 4 additions & 4 deletions utils/dataloaders.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -355,9 +355,9 @@ def __init__(self, path, img_size=640, stride=32, auto=True, transforms=None, vi
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."""
Expand Down
2 changes: 1 addition & 1 deletion utils/downloads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Download utils."""

import logging
Expand Down
2 changes: 1 addition & 1 deletion utils/flask_rest_api/example_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Perform test request."""

import pprint
Expand Down
2 changes: 1 addition & 1 deletion utils/flask_rest_api/restapi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions utils/general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""General utils."""

import contextlib
Expand Down Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Logging utils."""

import json
Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/clearml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions utils/loggers/clearml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
10 changes: 4 additions & 6 deletions utils/loggers/clearml/clearml_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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": (
Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/clearml/hpo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

from clearml import Task

Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/comet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

import glob
import json
Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/comet/comet_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion utils/loggers/comet/hpo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

import argparse
import json
Expand Down
1 change: 1 addition & 0 deletions utils/loggers/wandb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
2 changes: 1 addition & 1 deletion utils/loggers/wandb/wandb_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/loss.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Loss functions."""

import torch
Expand Down
2 changes: 1 addition & 1 deletion utils/metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Model validation metrics."""

import math
Expand Down
2 changes: 1 addition & 1 deletion utils/plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Plotting utils."""

import contextlib
Expand Down
1 change: 1 addition & 0 deletions utils/segment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
2 changes: 1 addition & 1 deletion utils/segment/augmentations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Image augmentation functions."""

import math
Expand Down
2 changes: 1 addition & 1 deletion utils/segment/dataloaders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""Dataloaders."""

import os
Expand Down
2 changes: 1 addition & 1 deletion utils/segment/general.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/segment/loss.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/segment/metrics.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/segment/plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

import contextlib
import math
Expand Down
8 changes: 4 additions & 4 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ultralytics YOLOv5 πŸš€, AGPL-3.0 license
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license
"""PyTorch utils."""

import math
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/triton.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion val.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit c568972

Please sign in to comment.