Free Ebook cover Computer Vision Basics: Understanding Images, Features, and Modern Pipelines

Computer Vision Basics: Understanding Images, Features, and Modern Pipelines

New course

10 pages

Reasoning About Deployment: From Model Output to Decision-Making

Capítulo 10

Estimated reading time: 10 minutes

+ Exercise

1) Mapping Model Outputs to Decisions

In deployment, the model’s output is rarely the final answer. A production system must convert outputs (scores, boxes, masks, embeddings) into decisions that are safe, consistent, and aligned with operational goals. This mapping is where many “good models” become unreliable systems if rules are unclear or uncertainty is ignored.

From scores to actions: define the decision contract

Start by writing a decision contract: what the system will do for every possible output pattern. For example, a classifier might output probabilities over classes; a detector outputs bounding boxes with confidence scores; a segmenter outputs per-pixel probabilities. The contract specifies how these become actions such as “accept,” “reject,” “route to human review,” or “trigger an alert.”

  • Hard thresholding: Decide positive if score ≥ T. Simple, but brittle if confidence is miscalibrated or data shifts.
  • Tiered decisions: Use multiple thresholds to create bands (auto-approve, manual review, auto-reject).
  • Business rules: Combine model outputs with non-ML constraints (e.g., “if object is detected but area is too small, ignore,” or “if two mutually exclusive classes both score high, send to review”).
  • Uncertainty handling: Explicitly define what happens when the model is unsure, conflicted, or out-of-distribution.

Step-by-step: designing thresholds and decision bands

Step 1: Identify the action set. List actions the system can take (e.g., approve, reject, review, retry capture, escalate).

Step 2: Choose the primary signal. For classification, it might be max probability; for detection, it might be per-box confidence; for segmentation, it might be mean mask probability or mask area above a probability cutoff.

Step 3: Define bands. Example for a binary decision using score s:

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

  • s ≥ 0.90 → auto-accept
  • 0.60 ≤ s < 0.90 → human review
  • s < 0.60 → auto-reject

Step 4: Add conflict rules. If top-1 and top-2 scores are close, treat as ambiguous. For example, if (p1 − p2) < 0.10, route to review even if p1 is high.

Step 5: Add input-quality gates. If the image is too blurry/dark or missing required content, do not trust the prediction; request recapture or route to review.

Step 6: Validate end-to-end behavior. Test the full decision contract on representative cases, including edge cases (multiple objects, partial occlusion, unusual lighting) and ensure the system response is acceptable.

Uncertainty beyond a single score

Many failures happen when a system treats a single confidence score as a universal truth. Consider additional uncertainty signals:

  • Margin/entropy: A high-entropy class distribution indicates uncertainty even if the top class is slightly higher.
  • Agreement checks: Compare outputs from two models (or two augmentations) and treat disagreement as uncertainty.
  • Out-of-distribution (OOD) heuristics: If embeddings are far from known training clusters or input statistics are unusual, downgrade automation.

2) Latency and Resource Constraints (Conceptual)

Deployment constraints shape what “good” means. A model that is accurate but too slow, too memory-heavy, or too expensive to run can degrade user experience and system reliability. Reasoning about latency and resources is about controlling the cost of each decision while maintaining acceptable quality.

Key levers: image size, batch size, and compute

  • Image size: Larger images often improve small-object performance but increase compute roughly with the number of pixels. Resizing changes what details are visible; it can also shift the distribution if not consistent with training.
  • Batch size: Batching improves throughput on GPUs but can increase per-request latency if requests wait to form a batch. For real-time systems, small batches (or batch=1) may be required.
  • CPU vs GPU: GPUs excel at parallel tensor operations; CPUs handle control flow and can be sufficient for lightweight models. The best choice depends on concurrency, cost, and latency targets.
  • Pre/postprocessing cost: Decoding images, resizing, NMS, mask operations, and data transfer can dominate latency if not optimized.

Step-by-step: building a latency budget

Step 1: Define the latency SLO. Example: p95 < 200 ms per request.

Step 2: Break down the pipeline. Measure or estimate time for: image decode → preprocessing → model inference → postprocessing → decision logic → response.

Step 3: Allocate a budget per stage. Example: decode 20 ms, preprocess 20 ms, inference 120 ms, postprocess 30 ms, decision 10 ms.

Step 4: Identify bottlenecks and trade-offs. If inference is too slow, consider smaller input size, a lighter model, quantization, or GPU. If postprocessing is too slow, optimize NMS settings, reduce candidate boxes, or simplify mask refinement.

Step 5: Validate under realistic load. Latency changes with concurrency. Test with expected request rates and measure tail latency (p95/p99), not just averages.

Reliability under constraints: graceful degradation

When resources are constrained (GPU unavailable, load spike, memory pressure), define fallback behaviors:

  • Route more cases to human review temporarily.
  • Use a faster “backup” model with stricter thresholds.
  • Reduce input resolution for non-critical requests while flagging reduced-confidence decisions.

3) Calibration and Confidence: When Probabilities Can’t Be Trusted

Many models output numbers that look like probabilities, but these values may not reflect true likelihood. A system that uses these scores for thresholds, ranking, or risk decisions can behave unpredictably if the scores are miscalibrated.

What calibration means in practice

A calibrated score means: among predictions with confidence 0.8, about 80% are correct (for the relevant notion of correctness). Calibration is not guaranteed by training and can degrade after deployment due to distribution shift, new sensors, or changes in user behavior.

Common reasons confidence becomes unreliable

  • Distribution shift: New lighting, backgrounds, camera optics, or object variants change the relationship between score and correctness.
  • Class imbalance changes: If the base rate of positives changes, a fixed threshold may no longer produce the intended decision rate.
  • Overconfident models: Some training setups produce sharp probabilities even when uncertain, especially under shift.
  • Postprocessing effects: NMS and mask thresholding can make the final output appear more certain than it is.

Step-by-step: validating calibration before using scores for decisions

Step 1: Collect a representative validation set. It should match deployment conditions (camera, environment, user behavior). If that’s not possible, create multiple slices that approximate expected variation.

Step 2: Bin predictions by confidence. For example, group scores into bins: [0.0–0.1), [0.1–0.2), …, [0.9–1.0].

Step 3: Compute empirical accuracy per bin. Compare average confidence in the bin to observed correctness.

Step 4: Inspect calibration by slice. Repeat the analysis for important segments (device type, lighting condition, region, object size). A model can be calibrated overall but miscalibrated in critical slices.

Step 5: Decide how to use scores. If calibration is poor, avoid interpreting scores as probabilities. Use them as ranking signals and rely more on validation-driven thresholds and decision bands.

Practical calibration approaches (conceptual)

  • Post-hoc calibration: Fit a simple mapping from raw scores to calibrated probabilities using a held-out set. This can improve decision stability without retraining the model.
  • Temperature scaling for softmax outputs: A lightweight method that adjusts confidence sharpness while preserving ranking.
  • Per-slice calibration: If different devices behave differently, calibrate per device family (only if you can reliably detect the slice at runtime).

4) Postprocessing Pitfalls: How Settings Change Precision/Recall

Postprocessing is not a minor detail; it can redefine what the system outputs. Small changes in NMS thresholds, score cutoffs, or mask refinement can shift precision/recall and create unexpected failure modes.

NMS (Non-Maximum Suppression): the trade-off knob

Detectors often produce multiple overlapping boxes for the same object. NMS removes duplicates by keeping the highest-scoring box and suppressing others that overlap beyond a threshold (IoU threshold).

  • Too aggressive NMS (low IoU threshold): Can suppress true distinct objects that are close together (hurts recall in crowded scenes).
  • Too lenient NMS (high IoU threshold): Can keep duplicates (hurts precision and downstream counting/logic).
  • Class-wise vs class-agnostic NMS: Class-agnostic NMS can suppress boxes of different classes that overlap (bad when classes overlap naturally).

Mask refinement and thresholding: segmentation outputs are not binary by default

Segmentation models often output per-pixel probabilities. Turning these into a final mask requires a threshold and sometimes morphological operations (e.g., removing small holes, smoothing edges). These choices affect metrics and, more importantly, downstream decisions like area measurement or collision avoidance.

  • High mask threshold: Cleaner masks but may miss thin structures (lower recall).
  • Low mask threshold: Captures more pixels but can include background noise (lower precision).
  • Hole filling / smoothing: Can improve visual quality but may distort measurements if the system relies on exact boundaries.

Step-by-step: tuning postprocessing without breaking behavior

Step 1: Identify the downstream decision dependency. Are you counting objects? Measuring area? Triggering an alert if any object exists? Different goals require different postprocessing.

Step 2: Choose a small set of candidate settings. For detection: score threshold and NMS IoU. For segmentation: probability threshold and small-object removal threshold.

Step 3: Evaluate on targeted slices. Crowded scenes for NMS; thin structures and low-contrast regions for masks. Ensure you include “near-miss” cases where small changes flip decisions.

Step 4: Check stability. A robust setting should not cause large output swings for tiny input perturbations (slight blur, small resize, compression). If it does, consider adding uncertainty bands and routing unstable cases to review.

Step 5: Lock settings with versioning. Treat postprocessing parameters as part of the model version. Changing them is a deployment change that needs validation.

5) Monitoring in Production: Drift, Relabeling, and Feedback Loops

Once deployed, the environment changes. Monitoring is how you detect when the model’s decision quality is likely degrading, even before you have ground truth for every prediction. The goal is not just dashboards; it is a feedback loop that drives data collection, relabeling, and controlled updates.

What to monitor when labels are delayed or sparse

  • Input drift indicators: Changes in image statistics (brightness, contrast), resolution distribution, compression artifacts, camera model mix, or scene composition.
  • Output drift indicators: Shifts in predicted class frequencies, average confidence, number of detections per image, box sizes, mask areas, or “unknown/abstain” rates.
  • Uncertainty and conflict rates: Growth in ambiguous predictions (small margins, high entropy) can signal drift.
  • Operational metrics: Human review rate, override rate, user-reported issues, time-to-decision, and retry/recapture frequency.

Step-by-step: setting up a practical monitoring loop

Step 1: Define monitoring slices. Segment by device type, geography, time of day, lighting condition proxies, or product category—whatever correlates with performance differences.

Step 2: Establish baselines. Record distributions of key input/output metrics from a known-good period.

Step 3: Set alerts on meaningful changes. Use thresholds on distribution shifts (e.g., predicted positive rate changes by X%, average confidence drops, detection count spikes). Alerts should be actionable, not noisy.

Step 4: Implement sampling for relabeling. Periodically select examples for labeling using a mix of: random sampling (coverage), uncertainty sampling (ambiguous cases), and slice-based sampling (underrepresented or drifting segments).

Step 5: Close the loop with controlled updates. When you retrain or recalibrate, run an offline validation and then a staged rollout (e.g., shadow mode or limited traffic) while monitoring the same indicators.

Periodic relabeling: keeping ground truth aligned with reality

Relabeling is not only for new data; it also catches label policy drift and ambiguous cases. Practical guidelines:

  • Refresh labeling guidelines: Ensure annotators follow the same decision definitions used in production.
  • Audit label consistency: Track disagreement rates and re-review contentious categories.
  • Prioritize high-impact errors: Focus labeling on cases that trigger costly actions or safety risks.

Maintaining a feedback loop for continuous improvement

A reliable deployment process treats model outputs, postprocessing, and decision logic as a single system. The feedback loop should connect: monitoring signals → targeted data collection → labeling → model/calibration/postprocessing updates → staged deployment → monitoring again. This makes improvements measurable and reduces the chance that a “better model” creates worse real-world behavior.

Now answer the exercise about the content:

When converting a model’s confidence score into production actions, which approach best improves reliability compared to using a single hard threshold?

You are right! Congratulations, now go to the next page

You missed! Try again.

A reliable system maps outputs to actions via a decision contract: bands (auto-accept/review/reject) plus rules for conflicts, uncertainty, and input-quality gates, rather than relying on a brittle single threshold.

Download the app to earn free Certification and listen to the courses in the background, even with the screen off.