跳至内容

模型试验指南

导言

对模型进行培训评估之后,就该对其进行测试了。模型测试包括评估模型在实际场景中的表现。测试考虑的因素包括准确性、可靠性、公平性以及模型决策的易懂程度。目标是确保模型按照预期执行,提供预期结果,并符合应用程序或项目的总体目标

Model testing is quite similar to model evaluation, but they are two distinct steps in a computer vision project. Model evaluation involves metrics and plots to assess the model's accuracy. On the other hand, model testing checks if the model's learned behavior is the same as expectations. In this guide, we'll explore strategies for testing your computer vision models.

模型测试与模型评估模型评估

首先,让我们通过一个例子来了解模型评估和测试之间的区别。

Suppose you have trained a computer vision model to recognize cats and dogs, and you want to deploy this model at a pet store to monitor the animals. During the model evaluation phase, you use a labeled dataset to calculate metrics like accuracy, precision, recall, and F1 score. For instance, the model might have an accuracy of 98% in distinguishing between cats and dogs in a given dataset.

评估结束后,您将使用宠物店的图片对模型进行测试,看看它在更多样、更真实的条件下识别猫狗的能力如何。您要检查的是,当猫和狗移动时、在不同的光照条件下或被玩具或家具等物体部分遮挡时,模型能否正确标示出猫和狗。模型测试检查模型在受控评估环境之外的表现是否符合预期。

准备模型测试

Computer vision models learn from datasets by detecting patterns, making predictions, and evaluating their performance. These datasets are usually divided into training and testing sets to simulate real-world conditions. Training data teaches the model while testing data verifies its accuracy.

在测试模型之前,有两点需要注意:

  • 真实呈现:之前未见过的测试数据应与模型部署时需要处理的数据相似。这有助于真实地了解模型的能力。
  • 足够大:测试数据集的规模必须足够大,以便可靠地了解模型的性能如何。

测试计算机视觉模型

以下是测试计算机视觉模型并了解其性能的关键步骤。

  • 运行预测:使用模型对测试数据集进行预测。
  • 比较预测:检查模型预测与实际标签(地面实况)的匹配程度。
  • 计算性能指标: 计算准确率、精确度、召回率和 F1 分数等指标,以了解模型的优缺点。测试的重点是这些指标如何反映真实世界的性能。
  • 结果可视化:创建混淆矩阵和 ROC 曲线等可视化辅助工具。这些可帮助您发现模型在实际应用中可能表现不佳的特定区域。

接下来,可以对测试结果进行分析:

  • 分类错误的图像:识别并查看模型分类错误的图像,以了解错误出在哪里。
  • 错误分析:进行全面的错误分析,以了解错误类型(如假阳性与假阴性)及其潜在原因。
  • 偏差与公平:检查模型预测中是否存在偏差。确保模型在不同的数据子集中表现同样出色,尤其是在包含种族、性别或年龄等敏感属性的情况下。

Testing Your YOLO11 Model

To test your YOLO11 model, you can use the validation mode. It's a straightforward way to understand the model's strengths and areas that need improvement. Also, you'll need to format your test dataset correctly for YOLO11. For more details on how to use the validation mode, check out the Model Validation docs page.

Using YOLO11 to Predict on Multiple Test Images

If you want to test your trained YOLO11 model on multiple images stored in a folder, you can easily do so in one go. Instead of using the validation mode, which is typically used to evaluate model performance on a validation set and provide detailed metrics, you might just want to see predictions on all images in your test set. For this, you can use the prediction mode.

验证模式与预测模式的区别

  • 验证模式通过将预测结果与已知标签(地面实况)进行比较来评估模型的性能。它可提供准确率、精确度、召回率和 F1 分数等详细指标。
  • 预测模式用于在未见过的新数据上运行模型以生成预测结果。它不提供详细的性能指标,但可以让你看到模型在真实世界图像上的表现。

Running YOLO11 Predictions Without Custom Training

If you are interested in testing the basic YOLO11 model to understand whether it can be used for your application without custom training, you can use the prediction mode. While the model is pre-trained on datasets like COCO, running predictions on your own dataset can give you a quick sense of how well it might perform in your specific context.

Overfitting and Underfitting in Machine Learning

在测试机器学习模型时,尤其是在计算机视觉领域,一定要注意过度拟合和拟合不足的问题。这些问题会严重影响模型处理新数据的效果。

过度拟合

过度拟合是指模型对训练数据的学习效果太好,包括对噪声和细节的学习效果,而对新数据的学习效果并不理想。在计算机视觉中,这意味着你的模型在处理训练图像时可能表现出色,但在处理新图像时却很吃力。

过度拟合的迹象

  • High Training Accuracy, Low Validation Accuracy: If your model performs very well on training data but poorly on validation or test data, it's likely overfitting.
  • 视觉检测:有时,如果模型对图像中的微小变化或无关细节过于敏感,就会出现过度拟合的情况。

不合适

当模型无法捕捉数据中的基本模式时,就会出现拟合不足的情况。在计算机视觉中,拟合不足的模型甚至可能无法正确识别训练图像中的物体。

不合适的迹象

  • 训练精确度低:如果模型在训练集上无法达到很高的精确度,则可能是拟合不足。
  • 视觉分类错误:持续无法识别明显的特征或物体,表明拟合不足。

平衡过度拟合与欠拟合

关键是要在过拟合和欠拟合之间找到平衡。理想情况下,模型应该在训练数据集和验证数据集上都表现良好。通过指标和可视化检查定期监控模型的性能,同时采用正确的策略,可以帮助您取得最佳结果。

过拟合和欠拟合概述

计算机视觉中的数据泄露及如何避免

在测试模型时,需要注意的是数据泄漏。当训练数据集之外的信息不小心被用于训练模型时,就会发生数据泄漏。在训练过程中,模型可能看起来非常准确,但当数据泄漏发生时,它在新的、未见过的数据上就不会有很好的表现。

为什么会发生数据泄漏

数据泄漏很难发现,通常来自训练数据中隐藏的偏差。以下是计算机视觉中发生数据泄露的几种常见方式:

  • 摄像机偏差:不同的角度、光线、阴影和摄像机移动都会带来不必要的模式。
  • 叠加偏差:图像中的徽标、时间戳或其他叠加物会误导模型。
  • 字体和对象偏差:经常出现在某些类别中的特定字体或对象会影响模型的学习。
  • Spatial Bias: Imbalances in foreground-background, bounding box distributions, and object locations can affect training.
  • 标签和域偏差:不正确的标签或数据类型的变化会导致泄漏。

检测数据泄漏

要查找数据泄漏,您可以

  • 检查性能:如果模型的结果出乎意料地好,则可能是泄漏。
  • 查看特征重要性:如果某个特征比其他特征重要得多,则可能表明存在泄漏。
  • 目视检查:仔细检查模型的决策是否直观合理。
  • 验证数据分离:在进行任何处理之前,确保数据已正确分割。

避免数据泄露

为防止数据泄露,应使用不同的数据集,包括来自不同相机和环境的图像或视频。仔细查看数据,检查是否存在隐藏的偏差,例如所有阳性样本都是在一天中的某个特定时间拍摄的。避免数据泄露将有助于提高计算机视觉模型在真实世界中的可靠性和有效性。

模型试验之后的工作

测试完模型后,接下来的步骤取决于测试结果。如果模型表现良好,您就可以将其部署到实际环境中。如果结果不尽如人意,就需要进行改进。这可能涉及分析误差、收集更多数据、提高数据质量、调整超参数以及重新训练模型。

加入人工智能对话

成为计算机视觉爱好者社区的一员有助于更有效地解决问题和学习。以下是一些联系、寻求帮助和分享想法的方法。

社区资源

  • GitHub Issues: Explore the YOLO11 GitHub repository and use the Issues tab to ask questions, report bugs, and suggest new features. The community and maintainers are very active and ready to help.
  • Ultralytics Discord 服务器:加入Ultralytics Discord 服务器,与其他用户和开发人员聊天,获得支持并分享经验。

官方文件

  • Ultralytics YOLO11 Documentation: Check out the official YOLO11 documentation for detailed guides and helpful tips on various computer vision projects.

这些资源将帮助您应对挑战,了解计算机视觉领域的最新趋势和实践。

综述

Building trustworthy computer vision models relies on rigorous model testing. By testing the model with previously unseen data, we can analyze it and spot weaknesses like overfitting and data leakage. Addressing these issues before deployment helps the model perform well in real-world applications. It's important to remember that model testing is just as crucial as model evaluation in guaranteeing the model's long-term success and effectiveness.

常见问题

计算机视觉中模型评估和模型测试的主要区别是什么?

Model evaluation and model testing are distinct steps in a computer vision project. Model evaluation involves using a labeled dataset to compute metrics such as accuracy, precision, recall, and F1 score, providing insights into the model's performance with a controlled dataset. Model testing, on the other hand, assesses the model's performance in real-world scenarios by applying it to new, unseen data, ensuring the model's learned behavior aligns with expectations outside the evaluation environment. For a detailed guide, refer to the steps in a computer vision project.

How can I test my Ultralytics YOLO11 model on multiple images?

To test your Ultralytics YOLO11 model on multiple images, you can use the prediction mode. This mode allows you to run the model on new, unseen data to generate predictions without providing detailed metrics. This is ideal for real-world performance testing on larger image sets stored in a folder. For evaluating performance metrics, use the validation mode instead.

如果计算机视觉模型出现拟合过度或拟合不足的迹象,该怎么办?

解决过度拟合问题:

  • Regularization techniques like dropout.
  • 增加训练数据集的规模。
  • 简化模型结构。

解决拟合不足的问题:

  • 使用更复杂的模型。
  • 提供更多相关功能。
  • Increase training iterations or epochs.

检查错误分类的图像,进行彻底的误差分析,并定期跟踪性能指标以保持平衡。有关这些概念的更多信息,请浏览我们的过度拟合和欠拟合部分。

如何检测和避免计算机视觉中的数据泄漏?

检测数据泄漏:

  • 验证测试性能是否异常高。
  • 检查功能的重要性,获得意想不到的见解。
  • 直观审查模型决策。
  • 确保在处理前正确划分数据。

避免数据泄漏:

  • 使用各种环境下的不同数据集。
  • 仔细审查数据,找出隐藏的偏见。
  • 确保训练集和测试集之间没有重叠信息。

有关防止数据泄漏的详细策略,请参阅我们的 "计算机视觉中的数据泄漏"部分。

测试计算机视觉模型后应采取哪些步骤?

测试后,如果模型性能符合项目目标,则继续部署。如果结果不理想,则应考虑:

从 "模型测试与模型评估 "部分获得见解,以完善和提高模型在实际应用中的有效性。从模型测试与模型评估部分获得见解,以完善和提高模型在实际应用中的有效性。

How do I run YOLO11 predictions without custom training?

You can run predictions using the pre-trained YOLO11 model on your dataset to see if it suits your application needs. Utilize the prediction mode to get a quick sense of performance results without diving into custom training.

📅 Created 3 months ago ✏️ Updated 20 days ago

评论