Building practical AI
Deepak Kumar Tiwari

Deepak Kumar Tiwari

Technology & AI Leader · Building practical systems

Multimodal inspection / Guide 77

A Production-Line Visual Defect Harness That Can Abstain

Build a production-line visual defect harness that checks part identity, required views, calibration uncertainty, and review routing before accepting evidence.

Illustrative engineering guide. Examples are not client deployments, production-ready integrations, or evidence of measured results. Validate the design with your domain and security owners.

Reference workflow: Part and recipe identity; Capture coverage validation; Candidate defect regions; Measurement uncertainty gate; Quality engineer review.
Reference workflow. Steps identify responsibilities, not necessarily separate agents. Branches and recovery paths are explained below. Open full-size diagram.

A hypothetical production line photographs molded housings at a fixed station. A model marks a dark streak as a scratch, while a second housing receives no defect label because its underside never faced the camera. The dashboard calls the first part rejected and the second accepted. Both decisions exceed the evidence: one confuses appearance with a measured defect, and the other confuses missing coverage with absence.

A visual defect harness should validate the inspection evidence before suggesting disposition. It connects part identity, inspection recipe, required views, candidate regions, and specialist measurements. Its output is an advisory packet for a quality engineer. The synthetic example below tests routing logic only, not a trained vision model, camera system, measurement instrument, or real manufacturing defect rate.

Anchor Every Frame to a Part

Start with a part instance identifier from the manufacturing workflow, not an inferred serial number alone. Bind the capture to station, trigger event, lot, product revision, inspection recipe, camera settings, and original frame digest. A correct image of the wrong revision can produce an incorrect defect judgment because the expected geometry or finish has changed.

Maintain a coverage matrix by required surface and feature. Top and underside views are not interchangeable. A frame may exist but fail usability because the fixture blocks a region, illumination saturates an edge, or motion blur hides the feature. A model’s confidence should not override a missing-view rule. The car photo coverage lab demonstrates the same distinction in less controlled capture conditions.

W3C PROV offers a way to describe source entities, processing activities, and responsible agents. Use those concepts to connect a crop to its frame and a measurement to its calibration record. If an operator later changes a label, preserve the earlier label and adjudication event rather than rewriting the historical evidence silently.

Measure a Candidate, Not a Guess

A vision model can propose a region that resembles a scratch, void, missing fastener, or finish inconsistency. A specialist method then determines whether the region supports a measurement relevant to the inspection recipe. That might require calibrated imaging, a depth sensor, a gauge, or direct examination. RGB appearance alone does not establish hidden damage, structural integrity, or temperature.

OpenCV’s calibration tutorial explains the relationship between object points, image points, camera parameters, and reprojection error. Record pixel coordinates with their image dimensions and the transformation to part-local millimeters. A fixed camera does not eliminate calibration drift after lens adjustment, fixture movement, or a recipe change. Reprojection error also does not capture every source of measurement uncertainty.

For this example, a scratch-length policy boundary is two millimeters, entirely illustrative and not a cited manufacturing standard. A measurement interval wholly above that boundary routes a candidate for defect review. An interval crossing it requires remeasurement. A lower interval produces a routine review packet, not automatic acceptance. Engineering specifications and qualified quality owners must define real limits.

Synthetic Routing Harness

The harness assumes a specialist supplied a length and uncertainty half-width. It validates required top and underside coverage, part revision, coordinate frame, and provenance placeholders. It does not estimate those fields from pixels. At least three independent failure dimensions are exercised so a passing threshold comparison cannot conceal the wrong part or missing evidence.

import math

base = {"part": "housing-18", "revision": "B", "recipe": "visual-4",
        "views": {"top", "underside"}, "frames": {"top": "f1", "underside": "f2"},
        "coords": "part_local_mm", "calibration": "cal-8",
        "length_mm": 2.4, "uncertainty_mm": 0.1}

def route(record):
    if (record["part"], record["revision"], record["recipe"]) != (
            "housing-18", "B", "visual-4"):
        return "identity_mismatch"
    required = {"top", "underside"}
    if not required <= record["views"] or any(
            not record["frames"].get(view) for view in required):
        return "recapture"
    length, error = record["length_mm"], record["uncertainty_mm"]
    if (record["coords"] != "part_local_mm" or not record["calibration"]
            or not all(math.isfinite(x) for x in (length, error))
            or length < 0 or not 0 <= error <= 0.3):
        return "remeasure"
    if length - error > 2.0:
        return "defect_review"
    if length + error >= 2.0:
        return "remeasure"
    return "routine_review"

assert route(base) == "defect_review"
assert route(dict(base, views={"top"})) == "recapture"
assert route(dict(base, revision="A")) == "identity_mismatch"
assert route(dict(base, length_mm=2.0)) == "remeasure"
assert route(dict(base, uncertainty_mm=float("nan"))) == "remeasure"
assert route(dict(base, length_mm=1.0)) == "routine_review"
assert route(dict(base, calibration="")) == "remeasure"
print("synthetic part, coverage, and measurement routing checks passed")

The strings identifying frames and calibration are trusted fixture references, not proofs of origin. Production must resolve them against authenticated capture and metrology records. Likewise, the uncertainty half-width is not automatically a statistical confidence interval. Its interpretation, coverage probability where applicable, and method of estimation must be documented by the measurement owner.

Keep Inspection Separate From Control

The smallest useful architecture is one capture adapter, one candidate interpreter, a deterministic evidence validator, and a reviewer queue. A specialist sub-agent is warranted only when a different inspection discipline requires distinct tools and review criteria. Ordinary calibration lookup should be a function, not another conversational agent. The manufacturing maintenance guide can consume approved observations without turning cosmetic candidates into machine diagnoses.

Authenticate station devices and isolate data by plant and tenant. Treat visible labels and OCR instructions as untrusted content. Restrict the inspection worker to reading evidence and preparing packets. It should not change machine parameters, bypass interlocks, or command line release. Independent safety interlocks must operate without waiting for model consensus, even if process telemetry appears normal.

The example omits camera triggering, image decoding, model inference, metrology, authorization, durable queues, and transaction handling. For an approved quality ticket, bind the write to the reviewed evidence revision and use a stable operation identity. If acknowledgment is lost, reconcile rather than creating another hold ticket. Missing camera data should produce a visible coverage fault, not a quiet reduction in the denominator.

Acceptance Tests

  1. Present a top view without the underside and require recapture even when the candidate detector reports no defects.
  2. Bind a valid frame to the wrong part revision and block review readiness before threshold evaluation.
  3. Supply a measurement interval crossing the illustrative boundary and route remeasurement rather than a binary decision.
  4. Remove calibration provenance or provide nonfinite uncertainty and ensure the harness abstains.
  5. Repeat adjacent video frames and verify they remain one correlated capture event in evaluation reporting.
  6. Disconnect the inspection service and confirm independent machine safety mechanisms continue operating without it.

Evaluate Parts, Not Frames

Compare an image-score baseline with the evidence-aware workflow on held-out part instances and lots. Measure missed visible defects divided by independently confirmed visible defects, unnecessary defect reviews divided by reviewed acceptable parts, and incomplete capture events divided by all triggered parts. Report results by product revision and lighting condition. Repeated frames from one part must not inflate sample size or appear across evaluation splits.

NIST’s AI Risk Management Framework supports deliberate risk evaluation, but it does not prescribe this recipe or certify acceptance thresholds. Begin with shadow advisory packets and quality-engineer adjudication. The first AI systems engineering task is to expose missing coverage as a first-class result. Faster defect suggestions are useful only if the process still knows which parts it could not inspect.

Sources