1. Industrial inspection landscape

Industrial inspection landscape 学习卡片

Industrial visual inspection is the task of deciding, from images or signals, whether a manufactured part meets its specification. That decision sounds simple, but the operating environment is hostile to conventional machine learning: defects are rare, their appearance drifts with every process change, and the cost of a missed escape is measured in recalls rather than accuracy points. This chapter maps the problem space — what defects actually look like, how inspection is embedded in production, and why few-shot and transfer learning have become the default engineering answer rather than an academic curiosity.

1.1 What "Defect" Actually Means on a Line

Defect taxonomy drives everything downstream: annotation strategy, model architecture, augmentation policy, and the acceptance threshold. In practice, inspection engineers group defects by their geometric and statistical signature rather than by their physical cause.

Defect classTypical signatureDetection difficultyCommon modality
Scratch / abrasionElongated, low-contrast, orientation-variableHigh — blends with textureBright-field, dark-field
Dent / deformationLocal gradient change, shading shiftMedium — needs 3D or photometric cuesStructured light, photometric stereo
Contamination / foreign materialHigh-contrast blob, arbitrary shapeLow–mediumColor imaging
Missing / misplaced componentPresence–absence, positional offsetLow — structuredArea scan, template matching
Solder void / crackSub-surface, low SNRVery highX-ray, AXI, acoustic
Coating / print irregularityPeriodic texture deviationHigh — statistical, not localLine scan, spectral

Two properties of this table matter more than the individual rows. First, the classes are not equally represented: a mature line may produce thousands of good parts per defect. Second, several classes are defined by deviation from a normal appearance rather than by a positive visual signature — a scratch is "not the surrounding texture," a void is "not the expected density." This asymmetry is the root cause of the data problem that few-shot learning addresses.

1.2 The Quality Control Workflow

Inspection is not a single model; it is a pipeline with distinct decision points, each with its own latency, recall, and cost budget.

  1. Acquisition. Trigger, illumination, exposure, and focus are fixed per part type. A change in lighting angle can move a defect from detectable to invisible without any change to the part.
  2. Pre-processing. Flat-field correction, distortion removal, ROI extraction, and normalization. This stage is where most "the model stopped working" incidents actually originate.
  3. Detection / segmentation. Localize candidate defects. High recall is prioritized here; false positives are tolerated because they are filtered later.
  4. Classification. Assign a defect type and severity to each candidate. This is where precision matters and where few-shot methods are most valuable.
  5. Disposition. Accept, reject, or route to human review, governed by an acceptance threshold and a cost model.
  6. Feedback. Escapes and over-kills are fed back as new labeled examples — the loop that keeps the system alive.
Key insight: Steps 3 and 4 have opposite error priorities. A single end-to-end model trained with one loss rarely satisfies both. Production systems usually split them, and few-shot learning is applied almost exclusively at the classification and rare-class detection stages.

1.3 Why Few-Shot and Transfer Learning Matter

Consider a realistic commissioning scenario. A new product variant enters a line that already inspects three similar variants. The customer supplies 15 labeled defect images across 4 defect classes, plus roughly 200 defect-free images. A from-scratch CNN has no chance: 15 examples cannot constrain millions of parameters, and the resulting model will memorize rather than generalize.

Three forces make this the normal case rather than an edge case:

  • Label scarcity. Defects are rare by definition. Collecting 1,000 examples of a specific scratch type may take months of production.
  • Distribution shift. Tooling wear, material lot changes, and seasonal humidity alter image statistics continuously. A model trained on January data degrades by March.
  • Long-tail class structure. A typical line has 3–5 frequent defect types and 20+ rare ones. The rare ones are the expensive ones.

Transfer learning addresses the first and third forces by reusing representations learned on large source datasets (ImageNet, COCO, or an in-house corpus of millions of industrial images). Few-shot learning addresses the second by making adaptation cheap: instead of retraining, the system conditions on a small support set at inference time.

1.4 A Concrete Commissioning Example

The following example illustrates the workflow and the parameters that matter. It is a representative setup, not a measured result.

Task: classify 4 defect types on stamped metal brackets
Support set: 15 labeled images (4 classes, 3-4 images each)
Query set: 120 unlabeled images from the current shift
Backbone: ResNet-18 pretrained on ImageNet
Method: prototypical network, 5-way 1-shot evaluation

Pre-processing:
  - flat-field correction with per-lens calibration frame
  - ROI crop to bracket face (fixed coordinates per fixture)
  - resize to 224x224, ImageNet normalization

Training:
  - freeze first two stages, fine-tune stages 3-4
  - lr = 1e-4, 200 episodes, 5-way 5-shot
  - augmentation: rotation +/-15 deg, brightness +/-10%

Inference:
  - compute class prototypes from support embeddings
  - assign query to nearest prototype (cosine distance)
  - threshold: reject if max similarity < 0.62

What to observe: the similarity distribution for known defect classes should be bimodal (clear separation between correct and incorrect assignments). If it is unimodal, the support set is too small or the backbone is mismatched to the modality. A common failure symptom is that all queries collapse to one prototype — usually caused by insufficient fine-tuning or by a support set where one class dominates.

Practical rule: Before investing in a few-shot method, verify that a simple nearest-neighbor classifier on frozen pretrained features already beats your current rule-based system. In many industrial cases it does, and it establishes a baseline that any learned method must exceed.

1.5 The Inspection Decision Space

The figure below summarizes how defect characteristics, data availability, and method choice relate. It is not a flowchart to be executed step by step; it is a map of the trade-offs that determine which approach is appropriate for a given inspection task.

Inspection Decision Space: Defect Signature vs. Data Availability Labeled examples available per defect class → Defect signature strength → 0 ~10 ~100 ~1k 10k+ weak moderate strong Classical CV Template matching Blob / edge analysis Threshold + morphology Missing component, gross contamination Few-Shot Learning Prototypical / matching nets Meta-learning, MAML Frozen features + kNN Rare scratch types, new product variants Transfer Learning Fine-tune pretrained backbone Domain adaptation Feature distillation Coating irregularity, texture deviation Full Supervised Large labeled datasets Anomaly Detection (unsupervised / self-supervised) Autoencoders, PatchCore, PaDiM, normalizing flows Trained on defect-free images only Best for: unknown defect types, zero labeled defects Limitation: cannot classify, only flag deviation Hybrid Pipeline (production reality) Anomaly detector → candidate regions Few-shot classifier → defect type Rule engine → disposition High recall + high precision Zones indicate typical operating regions; boundaries are approximate and task-dependent.

1.6 What This Course Covers

The remaining chapters build on this landscape. You will work through transfer learning fundamentals (feature extraction, fine-tuning schedules, domain adaptation), few-shot methods (prototypical networks, matching networks, MAML-style meta-learning), anomaly detection as the zero-label complement, and the engineering discipline of deploying and maintaining these systems on a live line. Each chapter includes concrete parameters, failure modes, and verification criteria so that the material can be reproduced on real inspection data.

The central engineering message of this chapter is that few-shot and transfer learning are not alternatives to classical inspection — they are the tools that make classical inspection viable when defect examples are scarce and the cost of a miss is high. The next chapter begins with the mechanics of transfer learning: what a pretrained backbone actually encodes, and how to decide which layers to freeze, fine-tune, or discard.