From b3b3a15086d69d27d892d9e81bd5c8cf769002ca Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 19 Jul 2024 21:02:09 +0200 Subject: [PATCH] Fix Docs pretty `__init__.py` URLs (#14550) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant --- docs/build_docs.py | 26 +++++++++---------- docs/build_reference.py | 3 ++- docs/en/reference/cfg/__init__.md | 2 +- docs/en/reference/hub/__init__.md | 2 +- docs/en/reference/utils/__init__.md | 2 +- .../action_recognition.py | 4 +++ .../YOLOv8-OpenCV-int8-tflite-Python/main.py | 4 +++ ultralytics/data/dataset.py | 2 ++ ultralytics/data/explorer/explorer.py | 4 +++ ultralytics/nn/modules/block.py | 2 ++ ultralytics/nn/modules/head.py | 2 ++ ultralytics/solutions/parking_management.py | 4 +++ ultralytics/utils/benchmarks.py | 2 ++ ultralytics/utils/loss.py | 8 +++--- ultralytics/utils/metrics.py | 2 ++ ultralytics/utils/tal.py | 2 ++ 16 files changed, 49 insertions(+), 22 deletions(-) diff --git a/docs/build_docs.py b/docs/build_docs.py index 171495ef25..47d328a31e 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -5,23 +5,23 @@ projects with multilingual content. It streamlines the workflow for generating l and updating HTML links to ensure they are correctly formatted. Key Features: -- Automated building of MkDocs documentation: The script compiles both the main documentation and - any localized versions specified in separate MkDocs configuration files. -- Post-processing of generated HTML files: After the documentation is built, the script updates all - HTML files to remove the '.md' extension from internal links. This ensures that links in the built - HTML documentation correctly point to other HTML pages rather than Markdown files, which is crucial - for proper navigation within the web-based documentation. + - Automated building of MkDocs documentation: The script compiles both the main documentation and + any localized versions specified in separate MkDocs configuration files. + - Post-processing of generated HTML files: After the documentation is built, the script updates all + HTML files to remove the '.md' extension from internal links. This ensures that links in the built + HTML documentation correctly point to other HTML pages rather than Markdown files, which is crucial + for proper navigation within the web-based documentation. Usage: -- Run the script from the root directory of your MkDocs project. -- Ensure that MkDocs is installed and that all MkDocs configuration files (main and localized versions) - are present in the project directory. -- The script first builds the documentation using MkDocs, then scans the generated HTML files in the 'site' - directory to update the internal links. -- It's ideal for projects where the documentation is written in Markdown and needs to be served as a static website. + - Run the script from the root directory of your MkDocs project. + - Ensure that MkDocs is installed and that all MkDocs configuration files (main and localized versions) + are present in the project directory. + - The script first builds the documentation using MkDocs, then scans the generated HTML files in the 'site' + directory to update the internal links. + - It's ideal for projects where the documentation is written in Markdown and needs to be served as a static website. Note: -- This script is built to be run in an environment where Python and MkDocs are installed and properly configured. + - This script is built to be run in an environment where Python and MkDocs are installed and properly configured. """ import os diff --git a/docs/build_reference.py b/docs/build_reference.py index 47fe5457de..6de5a5dbd6 100644 --- a/docs/build_reference.py +++ b/docs/build_reference.py @@ -56,10 +56,11 @@ def create_markdown(py_filepath: Path, module_path: str, classes: list, function module_path = module_path.replace(".", "/") url = f"https://github.com/{GITHUB_REPO}/blob/main/{module_path}.py" edit = f"https://github.com/{GITHUB_REPO}/edit/main/{module_path}.py" + pretty = url.replace("__init__.py", "\\_\\_init\\_\\_.py") # properly display __init__.py filenames title_content = ( f"# Reference for `{module_path}.py`\n\n" f"!!! Note\n\n" - f" This file is available at [{url}]({url}). If you spot a problem please help fix it by [contributing]" + f" This file is available at [{pretty}]({url}). If you spot a problem please help fix it by [contributing]" f"(https://docs.ultralytics.com/help/contributing/) a [Pull Request]({edit}) 🛠️. Thank you 🙏!\n\n" ) md_content = ["

\n"] + [f"## ::: {module_name}.{class_name}\n\n

\n" for class_name in classes] diff --git a/docs/en/reference/cfg/__init__.md b/docs/en/reference/cfg/__init__.md index 6f012b3031..85af8a626c 100644 --- a/docs/en/reference/cfg/__init__.md +++ b/docs/en/reference/cfg/__init__.md @@ -7,7 +7,7 @@ keywords: Ultralytics, YOLO, configuration, cfg2dict, get_cfg, check_cfg, save_d !!! Note - This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/__init__.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/cfg/__init__.py) 🛠️. Thank you 🙏! + This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/\_\_init\_\_.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/cfg/__init__.py) 🛠️. Thank you 🙏!

diff --git a/docs/en/reference/hub/__init__.md b/docs/en/reference/hub/__init__.md index 194fb17da8..f68de0bbf9 100644 --- a/docs/en/reference/hub/__init__.md +++ b/docs/en/reference/hub/__init__.md @@ -7,7 +7,7 @@ keywords: Ultralytics HUB API, login, logout, reset model, export model, check d !!! Note - This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/__init__.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/hub/__init__.py) 🛠️. Thank you 🙏! + This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/\_\_init\_\_.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/hub/__init__.py) 🛠️. Thank you 🙏!

diff --git a/docs/en/reference/utils/__init__.md b/docs/en/reference/utils/__init__.md index 3756835e57..269437ef57 100644 --- a/docs/en/reference/utils/__init__.md +++ b/docs/en/reference/utils/__init__.md @@ -7,7 +7,7 @@ keywords: Ultralytics, utils, TQDM, Python, ML, Machine Learning utilities, YOLO !!! Note - This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/__init__.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/utils/__init__.py) 🛠️. Thank you 🙏! + This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/\_\_init\_\_.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/__init__.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/utils/__init__.py) 🛠️. Thank you 🙏!

diff --git a/examples/YOLOv8-Action-Recognition/action_recognition.py b/examples/YOLOv8-Action-Recognition/action_recognition.py index 612d23a2e3..13007eb7fc 100644 --- a/examples/YOLOv8-Action-Recognition/action_recognition.py +++ b/examples/YOLOv8-Action-Recognition/action_recognition.py @@ -18,6 +18,8 @@ from ultralytics.utils.torch_utils import select_device class TorchVisionVideoClassifier: + """Classifies videos using pretrained TorchVision models; see https://pytorch.org/vision/stable/.""" + from torchvision.models.video import ( MViT_V1_B_Weights, MViT_V2_S_Weights, @@ -133,6 +135,8 @@ class TorchVisionVideoClassifier: class HuggingFaceVideoClassifier: + """Zero-shot video classifier using Hugging Face models for various devices.""" + def __init__( self, labels: List[str], diff --git a/examples/YOLOv8-OpenCV-int8-tflite-Python/main.py b/examples/YOLOv8-OpenCV-int8-tflite-Python/main.py index 521a1e5bc4..0cd5786b60 100644 --- a/examples/YOLOv8-OpenCV-int8-tflite-Python/main.py +++ b/examples/YOLOv8-OpenCV-int8-tflite-Python/main.py @@ -15,6 +15,8 @@ img_height = 640 class LetterBox: + """Resizes and reshapes images while maintaining aspect ratio by adding padding, suitable for YOLO models.""" + def __init__( self, new_shape=(img_width, img_height), auto=False, scaleFill=False, scaleup=True, center=True, stride=32 ): @@ -86,6 +88,8 @@ class LetterBox: class Yolov8TFLite: + """Class for performing object detection using YOLOv8 model converted to TensorFlow Lite format.""" + def __init__(self, tflite_model, input_image, confidence_thres, iou_thres): """ Initializes an instance of the Yolov8TFLite class. diff --git a/ultralytics/data/dataset.py b/ultralytics/data/dataset.py index 3ed6a21962..717654d483 100644 --- a/ultralytics/data/dataset.py +++ b/ultralytics/data/dataset.py @@ -280,6 +280,8 @@ class YOLOMultiModalDataset(YOLODataset): class GroundingDataset(YOLODataset): + """Handles object detection tasks by loading annotations from a specified JSON file, supporting YOLO format.""" + def __init__(self, *args, task="detect", json_file, **kwargs): """Initializes a GroundingDataset for object detection, loading annotations from a specified JSON file.""" assert task == "detect", "`GroundingDataset` only support `detect` task for now!" diff --git a/ultralytics/data/explorer/explorer.py b/ultralytics/data/explorer/explorer.py index 1852b89b3f..21e03c33d5 100644 --- a/ultralytics/data/explorer/explorer.py +++ b/ultralytics/data/explorer/explorer.py @@ -21,6 +21,8 @@ from .utils import get_sim_index_schema, get_table_schema, plot_query_result, pr class ExplorerDataset(YOLODataset): + """Extends YOLODataset for advanced data exploration and manipulation in model training workflows.""" + def __init__(self, *args, data: dict = None, **kwargs) -> None: """Initializes the ExplorerDataset with the provided data arguments, extending the YOLODataset class.""" super().__init__(*args, data=data, **kwargs) @@ -54,6 +56,8 @@ class ExplorerDataset(YOLODataset): class Explorer: + """Utility class for image embedding, table creation, and similarity querying using LanceDB and YOLO models.""" + def __init__( self, data: Union[str, Path] = "coco128.yaml", diff --git a/ultralytics/nn/modules/block.py b/ultralytics/nn/modules/block.py index 9b54353e38..672f0964a1 100644 --- a/ultralytics/nn/modules/block.py +++ b/ultralytics/nn/modules/block.py @@ -930,6 +930,8 @@ class PSA(nn.Module): class SCDown(nn.Module): + """Spatial Channel Downsample (SCDown) module for reducing spatial and channel dimensions.""" + def __init__(self, c1, c2, k, s): """ Spatial Channel Downsample (SCDown) module. diff --git a/ultralytics/nn/modules/head.py b/ultralytics/nn/modules/head.py index d80864844d..2add5654aa 100644 --- a/ultralytics/nn/modules/head.py +++ b/ultralytics/nn/modules/head.py @@ -281,6 +281,8 @@ class Classify(nn.Module): class WorldDetect(Detect): + """Head for integrating YOLOv8 detection models with semantic understanding from text embeddings.""" + def __init__(self, nc=80, embed=512, with_bn=False, ch=()): """Initialize YOLOv8 detection layer with nc classes and layer channels ch.""" super().__init__(nc, ch) diff --git a/ultralytics/solutions/parking_management.py b/ultralytics/solutions/parking_management.py index c19f994d79..7ee9f9a126 100644 --- a/ultralytics/solutions/parking_management.py +++ b/ultralytics/solutions/parking_management.py @@ -10,6 +10,8 @@ from ultralytics.utils.plotting import Annotator class ParkingPtsSelection: + """Class for selecting and managing parking zone points on images using a Tkinter-based UI.""" + def __init__(self): """Initializes the UI for selecting parking zone points in a tkinter window.""" check_requirements("tkinter") @@ -154,6 +156,8 @@ class ParkingPtsSelection: class ParkingManagement: + """Manages parking occupancy and availability using YOLOv8 for real-time monitoring and visualization.""" + def __init__( self, model_path, diff --git a/ultralytics/utils/benchmarks.py b/ultralytics/utils/benchmarks.py index db4a28dfed..a6af7afd07 100644 --- a/ultralytics/utils/benchmarks.py +++ b/ultralytics/utils/benchmarks.py @@ -164,6 +164,8 @@ def benchmark( class RF100Benchmark: + """Benchmark YOLO model performance across formats for speed and accuracy.""" + def __init__(self): """Function for initialization of RF100Benchmark.""" self.ds_names = [] diff --git a/ultralytics/utils/loss.py b/ultralytics/utils/loss.py index 9f13f63b40..3c3d3b71e2 100644 --- a/ultralytics/utils/loss.py +++ b/ultralytics/utils/loss.py @@ -607,12 +607,10 @@ class v8ClassificationLoss: class v8OBBLoss(v8DetectionLoss): - def __init__(self, model): - """ - Initializes v8OBBLoss with model, assigner, and rotated bbox loss. + """Calculates losses for object detection, classification, and box distribution in rotated YOLO models.""" - Note model must be de-paralleled. - """ + def __init__(self, model): + """Initializes v8OBBLoss with model, assigner, and rotated bbox loss; note model must be de-paralleled.""" super().__init__(model) self.assigner = RotatedTaskAlignedAssigner(topk=10, num_classes=self.nc, alpha=0.5, beta=6.0) self.bbox_loss = RotatedBboxLoss(self.reg_max).to(self.device) diff --git a/ultralytics/utils/metrics.py b/ultralytics/utils/metrics.py index ad4ff397a3..80c2f66083 100644 --- a/ultralytics/utils/metrics.py +++ b/ultralytics/utils/metrics.py @@ -1221,6 +1221,8 @@ class ClassifyMetrics(SimpleClass): class OBBMetrics(SimpleClass): + """Metrics for evaluating oriented bounding box (OBB) detection, see https://arxiv.org/pdf/2106.06072.pdf.""" + def __init__(self, save_dir=Path("."), plot=False, on_plot=None, names=()) -> None: """Initialize an OBBMetrics instance with directory, plotting, callback, and class names.""" self.save_dir = save_dir diff --git a/ultralytics/utils/tal.py b/ultralytics/utils/tal.py index 9cee05008f..4640533e5f 100644 --- a/ultralytics/utils/tal.py +++ b/ultralytics/utils/tal.py @@ -259,6 +259,8 @@ class TaskAlignedAssigner(nn.Module): class RotatedTaskAlignedAssigner(TaskAlignedAssigner): + """Assigns ground-truth objects to rotated bounding boxes using a task-aligned metric.""" + def iou_calculation(self, gt_bboxes, pd_bboxes): """IoU calculation for rotated bounding boxes.""" return probiou(gt_bboxes, pd_bboxes).squeeze(-1).clamp_(0)