From 69cfc8aa228dbf1267975f82fcae9a24665f23b9 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Thu, 27 Jun 2024 00:28:43 +0800 Subject: [PATCH] `ultralytics 8.2.45` Fix YOLOv8 `augment` inference (#14017) Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- docs/en/guides/model-training-tips.md | 14 +++++++------- docs/mkdocs_github_authors.yaml | 1 + tests/test_python.py | 2 +- ultralytics/__init__.py | 2 +- ultralytics/nn/tasks.py | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/en/guides/model-training-tips.md b/docs/en/guides/model-training-tips.md index ff230240..7457154e 100644 --- a/docs/en/guides/model-training-tips.md +++ b/docs/en/guides/model-training-tips.md @@ -28,14 +28,14 @@ Now that we know what is happening behind the scenes when we train a model, let' ## Training on Large Datasets -There are a few different aspects to think about when you are planning on using a large dataset to train a model. For example, you can adjust the batch size, control the GPU utilization, choose to use multi-scale training, etc. Let’s walk through each of these options in detail. +There are a few different aspects to think about when you are planning on using a large dataset to train a model. For example, you can adjust the batch size, control the GPU utilization, choose to use multi-scale training, etc. Let's walk through each of these options in detail. ### Batch Size and GPU Utilization When training models on large datasets, efficiently utilizing your GPU is key. Batch size is an important factor. It is the number of data samples that a machine learning model processes in a single training iteration. Using the maximum batch size supported by your GPU, you can fully take advantage of its capabilities and reduce the time model training takes. However, you want to avoid running out of GPU memory. If you encounter memory errors, reduce the batch size incrementally until the model trains smoothly. -With respect to YOLOv8, you can set the `batch_size` parameter in the [training configuration](../modes/train.md) to match your GPU’s capacity. Also, setting `batch=-1` in your training script will automatically determine the batch size that can be efficiently processed based on your device's capabilities. By fine-tuning the batch size, you can make the most of your GPU resources and improve the overall training process. +With respect to YOLOv8, you can set the `batch_size` parameter in the [training configuration](../modes/train.md) to match your GPU's capacity. Also, setting `batch=-1` in your training script will automatically determine the batch size that can be efficiently processed based on your device's capabilities. By fine-tuning the batch size, you can make the most of your GPU resources and improve the overall training process. ### Subset Training @@ -96,13 +96,13 @@ However, the ideal number of epochs can vary based on your dataset's size and pr Early stopping is a valuable technique for optimizing model training. By monitoring validation performance, you can halt training once the model stops improving. You can save computational resources and prevent overfitting. -The process involves setting a patience parameter that determines how many epochs to wait for an improvement in validation metrics before stopping training. If the model’s performance doesn’t improve within these epochs, training is stopped to avoid wasting time and resources. +The process involves setting a patience parameter that determines how many epochs to wait for an improvement in validation metrics before stopping training. If the model's performance doesn't improve within these epochs, training is stopped to avoid wasting time and resources.

Early Stopping Overview

-For YOLOv8, you can enable early stopping by setting the patience parameter in your training configuration. For example, `patience=5` means training will stop if there’s no improvement in validation metrics for 5 consecutive epochs. Using this method ensures the training process remains efficient and achieves optimal performance without excessive computation. +For YOLOv8, you can enable early stopping by setting the patience parameter in your training configuration. For example, `patience=5` means training will stop if there's no improvement in validation metrics for 5 consecutive epochs. Using this method ensures the training process remains efficient and achieves optimal performance without excessive computation. ## Choosing Between Cloud and Local Training @@ -110,7 +110,7 @@ There are two options for training your model: cloud training and local training Cloud training offers scalability and powerful hardware and is ideal for handling large datasets and complex models. Platforms like Google Cloud, AWS, and Azure provide on-demand access to high-performance GPUs and TPUs, speeding up training times and enabling experiments with larger models. However, cloud training can be expensive, especially for long periods, and data transfer can add to costs and latency. -Local training provides greater control and customization, letting you tailor your environment to specific needs and avoid ongoing cloud costs. It can be more economical for long-term projects, and since your data stays on-premises, it’s more secure. However, local hardware may have resource limitations and require maintenance, which can lead to longer training times for large models. +Local training provides greater control and customization, letting you tailor your environment to specific needs and avoid ongoing cloud costs. It can be more economical for long-term projects, and since your data stays on-premises, it's more secure. However, local hardware may have resource limitations and require maintenance, which can lead to longer training times for large models. ## Selecting an Optimizer @@ -120,7 +120,7 @@ You can also fine-tune optimizer parameters to improve model performance. Adjust ### Common Optimizers -Different optimizers have various strengths and weaknesses. Let’s take a glimpse at a few common optimizers. +Different optimizers have various strengths and weaknesses. Let's take a glimpse at a few common optimizers. - **SGD (Stochastic Gradient Descent)**: @@ -146,7 +146,7 @@ For YOLOv8, the `optimizer` parameter lets you choose from various optimizers, i - **A1:** The size of training images can indeed impact the prediction accuracy of high-resolution images. Training on low-resolution images might not capture the finer details that high-resolution images contain, potentially leading to less accurate predictions when the model is applied to high-resolution images. To achieve optimal performance, it's generally recommended to train your model on images that are similar in resolution to those you expect to encounter during inference. -- **Q2:** Does ‘Auto’ Optimizer Switch Between during Training? +- **Q2:** Does 'Auto' Optimizer Switch Between during Training? - **A2:** No, the 'Auto' setting does not switch between different optimizers during training. It selects a single optimizer at the start of the training process and uses it consistently throughout the entire training session, ensuring stability and consistency in the optimization process. diff --git a/docs/mkdocs_github_authors.yaml b/docs/mkdocs_github_authors.yaml index 58c37a25..440fc64c 100644 --- a/docs/mkdocs_github_authors.yaml +++ b/docs/mkdocs_github_authors.yaml @@ -9,6 +9,7 @@ 39910262+ChaoningZhang@users.noreply.github.com: ChaoningZhang 40165666+berry-ding@users.noreply.github.com: berry-ding 47978446+sergiuwaxmann@users.noreply.github.com: sergiuwaxmann +48149018+zhixuwei@users.noreply.github.com: zhixuwei 49699333+dependabot[bot]@users.noreply.github.com: dependabot 61612323+Laughing-q@users.noreply.github.com: Laughing-q 62214284+Burhan-Q@users.noreply.github.com: Burhan-Q diff --git a/tests/test_python.py b/tests/test_python.py index b06969aa..4b7076e4 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -95,7 +95,7 @@ def test_predict_img(model_name): Image.open(SOURCE), # PIL np.zeros((320, 640, 3), dtype=np.uint8), # numpy ] - assert len(model(batch, imgsz=32)) == len(batch) # multiple sources in a batch + assert len(model(batch, imgsz=32, augment=True)) == len(batch) # multiple sources in a batch @pytest.mark.parametrize("model", MODELS) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index 40bb34d8..48f6ce3d 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.44" +__version__ = "8.2.45" import os diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index d52ecad7..970ce0fe 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -337,7 +337,7 @@ class DetectionModel(BaseModel): def _predict_augment(self, x): """Perform augmentations on input image x and return augmented inference and train outputs.""" - if self.end2end: + if getattr(self, "end2end", False): LOGGER.warning( "WARNING ⚠️ End2End model does not support 'augment=True' prediction. " "Reverting to single-scale prediction."