Repository: ultralytics/ultralytics
Issue category: Performance Issue

Issue:
Significant mAP Drop When Using Bottom-Right Padding Instead of Center Padding in YOLOv8 Training
### Search before asking

- [X] I have searched the Ultralytics YOLO [issues](https://github.com/ultralytics/ultralytics/issues) and [discussions](https://github.com/ultralytics/ultralytics/discussions) and found no similar questions.


### Question

Hi, I'm training a YOLOv8 model on the same dataset, but noticed a significant difference in mAP when changing the padding strategy.

    When using center padding (default), the mAP@50 after the first epoch is around 0.88.
    When using bottom-right padding instead, the mAP@50 drops to 0.0001.

I ensured that:

    The same data augmentation and other settings were used in both cases.

However, the bottom-right padding leads to poor performance. What could be causing such a drastic performance drop? Is it related to padding affecting feature distribution, anchor design, or augmentation strategies? Any suggestions for improving performance in this case would be appreciated!

Thanks!
I changed "center=True" to "center=False",augment.py line1500
![2024-11-23 16-09-01 的屏幕截图](https://github.com/user-attachments/assets/b2c6c27d-2518-45cf-819b-40e6e6de87ce)
![2024-11-23 16-09-40 的屏幕截图](https://github.com/user-attachments/assets/fa10d8b8-2a61-4212-b709-2c213133bac4)
![2024-11-23 16-09-29 的屏幕截图](https://github.com/user-attachments/assets/2b2c9fd2-f53d-47ca-977f-7db6cd00f1c8)


### Additional

_No response_


Hints:
👋 Hello @Gebbap, thank you for bringing your findings to the Ultralytics community's attention 🚀!

We recommend checking out our [Docs](https://docs.ultralytics.com), where you can find comprehensive information on [Python](https://docs.ultralytics.com/usage/python/) and [CLI](https://docs.ultralytics.com/usage/cli/) usage, which may offer some insights into your padding strategy question.

Given this is a deep technical question related to padding strategies, we would appreciate if you could provide a [minimum reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/). This will greatly assist our team in diagnosing and addressing the issue more effectively.

Meanwhile, please ensure that you're running the most up-to-date version of the `ultralytics` package. You can upgrade using the following command:

```bash
pip install -U ultralytics
```

This ensures that any recent fixes or improvements are integrated into your environment.

For additional support and insights from both engineers and experienced community members, feel free to join the conversation on our [Discord](https://ultralytics.com/discord) 🎧, or start a discussion on [Discourse](https://community.ultralytics.com) or our [Subreddit](https://reddit.com/r/ultralytics).

An Ultralytics engineer will soon review your question to provide further assistance. Thank you for your patience and support 👍!

## Environments

YOLO can be executed in various verified environments, which come pre-installed with all dependencies, including [CUDA](https://developer.nvidia.com/cuda)/[CUDNN](https://developer.nvidia.com/cudnn), [Python](https://www.python.org/), and [PyTorch](https://pytorch.org/):

- **Notebooks** with free GPU: <a href="https://console.paperspace.com/github/ultralytics/ultralytics"><img src="https://assets.paperspace.io/img/gradient-badge.svg" alt="Run on Gradient"/></a> <a href="https://colab.research.google.com/github/ultralytics/ultralytics/blob/main/examples/tutorial.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> <a href="https://www.kaggle.com/models/ultralytics/yolo11"><img src="https://kaggle.com/static/images/open-in-kaggle.svg" alt="Open In Kaggle"></a>
- **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/google_cloud_quickstart_tutorial/)
- **Amazon** Deep Learning AMI. See [AWS Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/aws_quickstart_tutorial/)
- **Docker Image**. See [Docker Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/docker_image_quickstart_tutorial/) <a href="https://hub.docker.com/r/ultralytics/ultralytics"><img src="https://img.shields.io/docker/pulls/ultralytics/ultralytics?logo=docker" alt="Docker Pulls"></a>

## Status

<a href="https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml?query=event%3Aschedule"><img src="https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml/badge.svg" alt="Ultralytics CI"></a>

A green badge indicates all [Ultralytics CI](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml?query=event%3Aschedule) tests are passing. CI tests ensure the correct operation of all YOLO [Modes](https://docs.ultralytics.com/modes/) and [Tasks](https://docs.ultralytics.com/tasks/) on macOS, Windows, and Ubuntu every 24 hours and upon each commit.
Did you check if the training labels are correct in the plots?
yes,it is correct.two results used the same dateset and labels
I checked the labels after setting `center=False` and they're wrong. So this modification is incorrect and breaks the training labels which is why you're getting low scores.

![train_batch0.jpg](https://github.com/user-attachments/assets/7ec598d9-8140-4dd7-bd7f-fa2764061ce9)


Thank you! Simply modifying the value of "center" only changes the position of the plot but doesn’t adjust the labels correctly. How can I change the padding method? Should I modify the source code, or is there an official way to achieve this?

Patch:
diff --git a/ultralytics/data/augment.py b/ultralytics/data/augment.py
index d092e3c3703..bd821de28de 100644
--- a/ultralytics/data/augment.py
+++ b/ultralytics/data/augment.py
@@ -1591,7 +1591,7 @@ def __call__(self, labels=None, image=None):
             labels["ratio_pad"] = (labels["ratio_pad"], (left, top))  # for evaluation
 
         if len(labels):
-            labels = self._update_labels(labels, ratio, dw, dh)
+            labels = self._update_labels(labels, ratio, left, top)
             labels["img"] = img
             labels["resized_shape"] = new_shape
             return labels


Test patch: