跳到主要内容

train-ai

title: "Step 4: Train Your AI Model" sidebar_position: 9 slug: /guides/ov10i/train-ai

第 4 步:训练您的 AI 模型

时间:5–10 分钟

Your inspection regions are set. Now it's time to teach the AI what "good" and "bad" look like.

The three cardinal rules of training

Before anything else, internalize these three rules. They apply whether you're training a classifier or a segmenter, with 5 images or 500.

Rule 1: Label from the image only

Never look at the physical part (or put it under a microscope) to decide whether it's good or bad. If you can't see the defect in the camera image, the AI cannot learn it.

The AI is not magic. It can only work with what the camera sees. If you label a part as "defective" based on something you noticed by touching it or zooming in under a magnifier, but the camera image looks fine, you're teaching the AI to see something that isn't there.

If you can't label it from the image alone, go back to the Install step and fix the physical setup: better lens, better lighting, closer mounting, different angle.

Rule 2: Double and triple check your labels

Mislabels happen to everyone; experienced engineers do it too. But one bad label in a small dataset can destroy your results.

With 5 training images, one mislabel corrupts 20% of your training data. That's catastrophic.

Before every training run: Click View All ROIs and verify every single annotation. This is the easiest thing to fix and the most impactful.

Rule 3: Start small, iterate fast

Don't label 50 images and hit train. Instead, create a tight loop: Label 3-5 images per class, train in development mode (approximately 30 seconds), test and try to break it, then add targeted data where it fails. Repeat this cycle 2-4 times in development mode, then switch to production mode.

This loop is your fastest path to a good model. Run it 2-4 times in development mode, then switch to production mode.

Step-by-step training workflow

1. Capture initial training images

With your recipe active and parts flowing (or placed manually), capture images. You need a minimum of 3-5 images per class to start.

For a simple pass/fail inspection:

  • 3-5 images of good parts
  • 3-5 images of defective parts

2. Label the images

标注与训练界面

For each ROI in each image, assign the correct class label:

  • Classifier(分类器): 从下拉菜单中选择类别(例如 "pass" 或 "fail")
OV10i 仅支持 classification

The OV10i supports classifiers only. Select the class from a dropdown for each ROI (e.g., "pass" or "fail"). For pixel-level segmentation, you need an OV20i or OV80i.

3. Train in Development Mode

Click 训练 and select 开发模式. This takes about 30 seconds and produces a model that's roughly 20x less accurate than production, but it's enough to check the signal.

What "checking the signal" means: Is the AI starting to learn the difference between good and bad? Or is it getting everything completely wrong?

  • 如果它大部分正确 → 信号良好,继续
  • 如果它完全错误 → 出现问题。检查错误标注、检查 ROI 大小、检查图像质量

Return ONLY the translated markdown content, preserving all formatting exactly as in the original.

4. 使用实时预览进行测试

实时预览模式:实时测试您的模型

单击 Live Preview Mode 并对部件进行测试。观察结果:

  • 它是否正确处理了简单案例?
  • 它在哪些方面存在困难?
  • 边界案例有哪些?

尽量把它搞崩溃。 找出它失败的情况。这些失败将成为改进的路线图。

5. 添加定向数据

不要添加随机的新图片。添加专门针对你发现的失效模式的图片:

  • 如果它把划痕和反射混淆,请同时增加两者的示例
  • 如果它漏检小缺陷,请增加更多小缺陷的图片
  • 如果它在角落处的部件上失效,请增加更多角落部件的示例

6. 重新训练并重新测试

重复步骤 3-5 两到四次。每次迭代都应提高准确性。

7. 切换到生产模式

当开发模式运行得相当顺利时,切换到 生产模式。这需要约 5-10 分钟,但生成的模型的准确度大约是开发模式的 20 倍

如果开发模式能正确处理约 80% 的情况,生产模式很可能达到约 95% 及以上的正确率。

增强:让 AI 应对变异

数据增强在训练过程中会随机修改你的训练图像,调整亮度、增加旋转、调整对比度等。每张图像都会在略有不同的增强条件下输入到 AI 数百次,但标签保持不变。

这对于提升鲁棒性极为强大。如果你的照明在班次之间变化,亮度增强能教会 AI 如何处理它。如果部件可能以任意角度到达,旋转增强会使定向不再重要。

何时使用数据增强

增强项适用情形示例场景
亮度照明变化(白天/夜晚、阴影)车间顶灯整日变化
旋转部件可能以任意角度到达螺丝孔,方向不重要
运动模糊部件移动快速或相机发生抖动高速传送带
饱和度颜色不是检查的一部分同一部件在不同颜色下应同样通过
对比度环境照明波动窗边的季节性光线变化

何时不要使用数据增强

不要对你正在检查的对象进行数据增强

这是把双刃剑。如果你添加旋转增强,但你正在检查的是部件是否正确定向,你会让 AI 认为翻转的部件仍然“良好”。

  • 检查颜色一致性?不要使用饱和度增强
  • 检查模糊/清晰度?不要使用运动模糊增强
  • 检查定向?不要使用旋转增强

规则:除了你正在检查的特定属性之外,其他属性都进行增强。

数据多样性很重要

你的训练数据应覆盖 AI 在生产中可能看到的全部范围:

  • 不同时间段的光照(若照明变化)
  • 不同批次的部件(表面处理可能略有差异)
  • 部件在画面中的不同位置
  • 既有简单也有困难的案例

聚焦于最难的案例。 如果你的训练数据包含 10 个最难分类的部件,那么对 AI 来说,简单部分的 90% 将变得微不足道。

高学习能力

OV 相机的 AI 设计为通过更多数据不断提升。 与在看到 20 张图像后就趋于稳定的 AI 系统不同,该模型在 50、100,甚至 500 张以上的图像下仍在提升。

大多数检测在 5-10 张图像下就能很好地工作,但如果您遇到复杂的多缺陷问题,请不要犹豫,继续添加数据。

通过合成数据加速:Defect Studio

如果您需要针对极少见的缺陷进行训练怎么办?比如需要故意移除某颗螺丝以制造缺陷、需要制造一条划痕、每千件才会出现一次的裂纹?等待数月以收集足够的样本并不现实。

The OV Auto-Defect Creator Studio 位于 tools.overview.ai,可以解决这个问题。它生成具有照片级真实感的合成缺陷图像,生成速度比在生产线上等待真实缺陷出现快多达 10,000 倍。

工作原理:5 个简单步骤

  1. 上传 您部件的高质量图像
  2. 标记 应出现缺陷的区域
  3. 描述 缺陷,使用简单英文(例如“表面上的深划痕”或“焊点缺失”)
  4. 生成 缺陷变体(AI 会生成照片级真实的结果)
  5. 导出 合成图像直接进入您的训练集

为什么合成数据有效

生成的图像不仅仅是“粘贴上去”的伪影。它们是与您实际照明、相机角度和部件表面相匹配的照片级真实变体。AI 理解在您特定成像条件下缺陷的外观物理规律。

用例:

  • 罕见缺陷: 针对您从未(或极少)见过的失效模式进行训练
  • 新产品上线: 在第一块有缺陷的部件下线前建立检测
  • 边缘情况: 生成边界样本以提升 AI 的判定边界
  • 数据增强: 用合成多样性来补充小型数据集

查看实际效果

以真实数据为起点,使用合成数据加速

最佳做法:先用您初始的 3-5 张真实图像进行训练,识别 AI 的薄弱点,然后使用 Defect Studio 为这些特定的失效模式生成定向的合成示例。真实数据建立基线;合成数据弥补差距。

训练清单

在继续之前,请确认:

  • 图像已捕获,每类至少 3-5 张
  • 所有标签已双重检查(查看所有 ROI)
  • 已在开发模式下完成训练并使用 Live Preview 进行测试
  • 已识别失效模式并添加针对性数据
  • 已完成 2-4 次“标注 → 训练 → 测试”循环
  • 已在生产模式下完成训练;结果符合预期

模型训练完成且效果良好吗?请移至 Step 5: Setting Up Outputs