跳至内容

Data Preprocessing Techniques for Annotated Computer Vision Data

导言

定义计算机视觉 项目的目标收集和批注数据后,下一步是预处理批注数据,并为模型训练做好准备。干净一致的数据对于创建性能良好的模型至关重要。

预处理是 计算机视觉项目工作流 中的一个步骤,包括调整图像大小、规范化像素值、扩充数据集以及将数据拆分为训练集、验证集和测试集。让我们来探讨清理数据的基本技术和最佳实践!

数据预处理的重要性

我们已经在仔细收集和注释我们的数据,并考虑到了多种因素。那么,是什么让数据预处理对计算机视觉项目如此重要呢?好吧,数据预处理就是将数据转换为适合训练的格式,从而减少计算负载并有助于提高模型性能。以下是预处理解决的原始数据中的一些常见问题:

  • 噪声:数据中不相关或随机的变化。
  • 不一致:图像大小、格式和质量的变化。
  • 不平衡:数据集中类或类别的分布不均。

数据预处理技术

数据预处理的首要步骤之一是调整大小。某些型号设计用于处理可变的输入大小,但许多型号需要一致的输入大小。调整图像大小可使它们统一并降低计算复杂性。

调整图像大小

您可以使用以下方法调整图像大小:

  • 双线性插值:通过对四个最接近的像素值进行加权平均来平滑像素值。
  • 最近邻:在不平均的情况下分配最接近的像素值,从而产生块状图像,但计算速度更快。

若要使调整大小任务更简单,可以使用以下工具:

  • OpenCV: A popular computer vision library with extensive functions for image processing.
  • PIL(枕头):A Python 用于打开、操作和保存图像文件的映像库。

With respect to YOLO11, the 'imgsz' parameter during model training allows for flexible input sizes. When set to a specific size, such as 640, the model will resize input images so their largest dimension is 640 pixels while maintaining the original aspect ratio.

通过评估模型和数据集的特定需求,您可以确定调整大小是否是必要的预处理步骤,或者模型是否可以有效地处理不同大小的图像。

规范化像素值

另一种预处理技术是归一化。归一化将像素值缩放到标准范围,这有助于在训练期间更快地收敛并提高模型性能。以下是一些常见的规范化技术:

  • 最小-最大缩放:将像素值缩放到 0 到 1 的范围内。
  • Z 分数归一化:根据像素值的平均值和标准差缩放像素值。

With respect to YOLO11, normalization is seamlessly handled as part of its preprocessing pipeline during model training. YOLO11 automatically performs several preprocessing steps, including conversion to RGB, scaling pixel values to the range [0, 1], and normalization using predefined mean and standard deviation values.

拆分数据集

清理数据后,即可拆分数据集。将数据拆分为训练集、验证集和测试集,以确保可以在看不见的数据上评估模型,以评估其泛化性能。常见的拆分是 70% 用于训练,20% 用于验证,10% 用于测试。您可以使用各种工具和库来拆分数据,例如 scikit-learn 或 TensorFlow.

拆分数据集时,请考虑以下事项:

  • 维护数据分布:确保在训练集、验证集和测试集之间维护类的数据分布。
  • 避免数据泄露:通常,数据增强是在数据集拆分后完成的。数据增强和任何其他预处理应仅应用于训练集,以防止来自验证或测试集的信息影响模型训练。- 平衡类:对于不平衡的数据集,请考虑在训练集中对少数类进行过采样或对多数类进行欠采样等技术。

什么是数据增强?

最常讨论的数据预处理步骤是数据增强。数据增强通过创建图像的修改版本来人为地增加数据集的大小。通过扩充数据,可以减少过度拟合并改进模型泛化。

以下是数据增强的其他一些好处:

  • 创建更强大的数据集:数据增强可以使模型对输入数据中的变化和失真更加鲁棒。这包括照明、方向和比例的变化。
  • Cost-Effective: Data augmentation is a cost-effective way to increase the amount of training data without collecting and labeling new data.
  • 更好地利用数据:通过创建新的变体,每个可用的数据点都发挥其最大潜力

数据增强方法

常见的增强技术包括翻转、旋转、缩放和颜色调整。多个库,例如 Albumentations、Imgaug 和 TensorFlow的 ImageDataGenerator,可以生成这些增强。

数据增强概述

With respect to YOLO11, you can augment your custom dataset by modifying the dataset configuration file, a .yaml file. In this file, you can add an augmentation section with parameters that specify how you want to augment your data.

The Ultralytics YOLO11 repository supports a wide range of data augmentations. You can apply various transformations such as:

  • 随机作物
  • 翻转:图像可以水平或垂直翻转。
  • 旋转:图像可以按特定角度旋转。
  • 失真

此外,您还可以通过特定参数调整这些增强技术的强度,以生成更多数据种类。

预处理案例研究

Consider a project aimed at developing a model to detect and classify different types of vehicles in traffic images using YOLO11. We've collected traffic images and annotated them with bounding boxes and labels.

以下是此项目的每个预处理步骤的样子:

  • Resizing Images: Since YOLO11 handles flexible input sizes and performs resizing automatically, manual resizing is not required. The model will adjust the image size according to the specified 'imgsz' parameter during training.
  • Normalizing Pixel Values: YOLO11 automatically normalizes pixel values to a range of 0 to 1 during preprocessing, so it's not required.
  • 拆分数据集:使用 scikit-learn 等工具将数据集分为训练 (70%)、验证 (20%) 和测试 (10%) 集。
  • Data Augmentation: Modify the dataset configuration file (.yaml) to include data augmentation techniques such as random crops, horizontal flips, and brightness adjustments.

这些步骤可确保数据集已准备好,没有任何潜在问题,并已准备好进行探索性数据分析 (EDA)。

探索性数据分析技术

在对数据集进行预处理和扩充后,下一步是通过探索性数据分析获得见解。EDA 使用统计技术和可视化工具来了解数据中的模式和分布。您可以识别类不平衡或异常值等问题,并就进一步的数据预处理或模型训练调整做出明智的决策。

统计EDA技术

统计技术通常从计算基本指标开始,例如平均值、中位数、标准差和范围。通过这些指标,您可以快速了解影像数据集的属性,例如像素强度分布。了解这些基本统计数据有助于您掌握数据的整体质量和特征,让您及早发现任何异常情况。

视觉EDA技术

可视化是图像数据集 EDA 的关键。例如,类不平衡分析是 EDA 的另一个重要方面。它有助于确定某些类在数据集中的代表性是否不足,使用条形图可视化不同图像类或类别的分布可以快速揭示任何不平衡。同样,可以使用箱形图等可视化工具识别异常值,这些工具突出显示了像素强度或特征分布的异常。异常值检测可防止异常数据点扭曲结果。

常用的可视化工具包括:

  • 直方图和箱形图:有助于了解像素值的分布和识别异常值。
  • 散点图:有助于探索影像要素或注释之间的关系。
  • 热图:可有效可视化图像中像素强度的分布或带注释特征的空间分布。

用 Ultralytics 适用于 EDA 的 Explorer

Community Note ⚠️

As of ultralytics>=8.3.10, Ultralytics explorer support has been deprecated. But don't worry! You can now access similar and even enhanced functionality through Ultralytics 枢纽, our intuitive no-code platform designed to streamline your workflow. With Ultralytics HUB, you can continue exploring, visualizing, and managing your data effortlessly, all without writing a single line of code. Make sure to check it out and take advantage of its powerful features!🚀

For a more advanced approach to EDA, you can use the Ultralytics Explorer tool. It offers robust capabilities for exploring computer vision datasets. By supporting semantic search, SQL queries, and vector similarity search, the tool makes it easy to analyze and understand your data. With Ultralytics Explorer, you can create embeddings for your dataset to find similar images, run SQL queries for detailed analysis, and perform semantic searches, all through a user-friendly graphical interface.

概述 Ultralytics 资源管理器

伸出援手,建立联系

与其他计算机视觉爱好者讨论您的项目可以从不同的角度为您提供新的想法。以下是一些学习、故障排除和交流的好方法:

与社区联系的渠道

  • GitHub Issues: Visit the YOLO11 GitHub repository and use the Issues tab to raise questions, report bugs, and suggest features. The community and maintainers are there to help with any issues you face.
  • Ultralytics Discord 服务器: 加入 Ultralytics Discord 服务器 ,用于与其他用户和开发人员联系、获得支持、分享知识和集思广益。

官方文件

  • Ultralytics YOLO11 Documentation: Refer to the official YOLO11 documentation for thorough guides and valuable insights on numerous computer vision tasks and projects.

您的数据集已准备就绪!

适当调整大小、规范化和增强数据可通过减少噪声和改进泛化来提高模型性能。通过遵循本指南中概述的预处理技术和最佳实践,您可以创建实体数据集。准备好预处理的数据集后,您可以放心地继续执行项目中的后续步骤。

常见问题

数据预处理在计算机视觉项目中的重要性是什么?

数据预处理在计算机视觉项目中至关重要,因为它能确保数据干净、一致,并且格式最适合模型训练。通过解决原始数据中的噪音、不一致性和不平衡等问题,预处理步骤(如调整大小、归一化、增强和数据集分割)有助于减少计算负荷并提高模型性能。更多详情,请访问计算机视觉项目步骤

如何使用Ultralytics YOLO 进行数据扩增?

For data augmentation with Ultralytics YOLO11, you need to modify the dataset configuration file (.yaml). In this file, you can specify various augmentation techniques such as random crops, horizontal flips, and brightness adjustments. This can be effectively done using the training configurations explained here. Data augmentation helps create a more robust dataset, reduce overfitting, and improve model generalization.

计算机视觉数据的最佳数据规范化技术是什么?

归一化将像素值缩放至标准范围,以加快收敛速度并提高训练时的性能。常见的技术包括

  • 最小-最大缩放:将像素值缩放到 0 到 1 的范围内。
  • Z 分数归一化:根据像素值的平均值和标准差缩放像素值。

For YOLO11, normalization is handled automatically, including conversion to RGB and pixel value scaling. Learn more about it in the model training section.

我应该如何拆分注释数据集进行训练?

To split your dataset, a common practice is to divide it into 70% for training, 20% for validation, and 10% for testing. It is important to maintain the data distribution of classes across these splits and avoid data leakage by performing augmentation only on the training set. Use tools like scikit-learn or TensorFlow for efficient dataset splitting. See the detailed guide on dataset preparation.

Can I handle varying image sizes in YOLO11 without manual resizing?

Yes, Ultralytics YOLO11 can handle varying image sizes through the 'imgsz' parameter during model training. This parameter ensures that images are resized so their largest dimension matches the specified size (e.g., 640 pixels), while maintaining the aspect ratio. For more flexible input handling and automatic adjustments, check the model training section.

📅 Created 4 months ago ✏️ Updated 11 days ago

评论