Tag: CV

  • MSD0005 Surveillance Video Anomaly Detection

    

    How would you design an end-to-end surveillance system that automatically detects and alerts security personnel to ‘anomalous events’ (e.g., break-ins, fainting, or prohibited movements) in a large shopping mall?

    Line-art scene: a shopping mall corridor watched by a wall-mounted camera, with a walking person and a question mark callout asking normal or anomaly

    The Problem: dozens of cameras stream continuously. Spot the rare anomalous event (break-in, fainting, prohibited movement) in real time, knowing you have no labeled anomalies to train on.

    Answer

    A surveillance anomaly detection system captures video streams, preprocesses them into clips, and uses a deep learning model (typically a pretrained video backbone plus a lightweight anomaly scoring head) to identify unusual behavior. It operates in a semi-supervised setup trained on normal data, runs in real time with sliding windows and temporal smoothing, and wraps the model in alerting, monitoring, and a human-in-the-loop feedback loop for calibration and retraining.

    (1) Ingestion & Preprocessing: Capture real-time streams from many cameras; resize frames and normalize pixels before clipping them into short windows.
    (2) Feature Extraction: A pretrained backbone (2D CNN (EfficientNet), optical flow, 3D CNN (I3D), or a Video Transformer (Swin, TimeSformer)) turns each clip into features.
    (3) Semi-Supervised Normal Model: An autoencoder or GAN trained on months of “normal” mall activity; high reconstruction error on new footage flags an anomaly against a calibrated threshold.
    (4) Alerting & Human-In-The-Loop: Real-time alerts send anomalous frames to operators, whose “Not an Anomaly” clicks feed recalibration and retraining.
    (5) System Design: Edge devices do preliminary processing to save bandwidth, the cloud does heavy computation; evaluation tracks precision, recall, F1 and false-alarm rates.

    Three-panel mechanism diagram: clips flow into a pretrained video backbone for feature extraction, an autoencoder trained on normal activity reconstructs them, and a reconstruction error curve crossing a threshold line flags anomalies

    Figure 1: The detection mechanism: backbone features feed a model trained to reconstruct normal activity; when reconstruction error crosses the calibrated threshold, the clip is flagged anomalous.

    Clarify Before Designing:
    (1) Scale: how many cameras, what fps and resolution, and how many concurrent clips must be scored?
    (2) Alert Latency: how many seconds from event to operator notification?
    (3) Anomaly Definition: a closed list of event types, or anything unusual; and are any labels available (frame-level, video-level, none)?
    (4) False-Alarm Budget: how many false alerts per camera per day can guards tolerate before they start ignoring the system?
    (5) Deployment: on-prem edge hardware available, or cloud-only?


    Login to view more content
  • MSD0002 Image to Video Classification

    

    You are given a pretrained image classification network, such as ResNet. How would you adapt it to perform video classification, ensuring that both spatial and temporal information are captured?

    Please discuss possible architectural modifications and trade-offs between different approaches.

    Problem framing diagram: a pretrained 2D ResNet that sees frames independently flows into a question mark, with the target video classification requiring both spatial and temporal cues

    The Problem: a pretrained 2D CNN understands each frame in isolation. Fill the question mark with an adaptation that adds temporal modeling without throwing away what the image network already knows.

    Answer

    The missing ingredient is temporal modeling: a 2D CNN sees each frame independently, so any adaptation must add a mechanism that aggregates information across time. Three families cover the design space: inflate the network into 3D convolutions, keep the 2D CNN as a per-frame encoder and add a sequence model on top, or simply pool or attend over per-frame features. The right choice trades temporal modeling power against compute cost and data hunger.

    (1) 3D CNNs (C3D / I3D): Extend 2D convolutions into 3D to learn motion directly; I3D inflates pretrained 2D filters into 3D, keeping ImageNet weights useful.
    (2) CNN + Sequence Model: Use the 2D CNN as a per-frame feature extractor, then run an LSTM / TCN / Transformer over the feature sequence for temporal modeling.
    (3) Temporal Pooling / Attention: Aggregate per-frame features with average/max pooling or attention: cheapest, but frame order and fine motion cues fade.

    Mechanism diagram of the CNN plus sequence model option: four video frames each pass through the same pretrained CNN, producing a stack of feature vectors that flows into an LSTM or Transformer temporal model, producing the class prediction

    Figure 1: The CNN + sequence model option: the pretrained 2D CNN is reused per frame, and a temporal model (LSTM/TCN/Transformer) learns how features evolve. This is the balanced default: full ImageNet leverage, moderate cost, natural variable-length handling.

    Clarify Before Designing:
    (1) Latency: real-time or offline? What is the per-clip inference budget?
    (2) Input Statistics: fps, clip duration, resolution: trimmed clips or untrimmed streams?
    (3) Data Scale: how much labeled video is available: hundreds or hundreds of thousands of clips?
    (4) Compute: can training and inference afford 3D-convolution cost?
    (5) Motion Sensitivity: do classes depend on subtle motion (opening vs closing) or mostly on scenes and objects?


    Login to view more content
  • MSD0001 Real-Time Factory Product Inspection

    

    You are tasked with designing and deploying a deep learning-based computer vision system for real-time quality control on a high-speed manufacturing assembly line. The system must classify each product as ‘Pass’ or ‘Fail’ due to surface defects (scratches, cracks, misalignments).

    Describe the complete end-to-end system design, from data acquisition and model selection to deployment and post-deployment maintenance.

    Crucially, how would you address the challenges of real-time inference speed and the severe class imbalance due to the fact that defects are rare?

    Problem framing diagram: a high-speed line producing 600 units per minute with surface defects flows into a question mark, with required outputs Pass or Fail within a 100 millisecond per unit budget at a 0.1 percent defect rate

    The Problem: 600 units per minute stream past a camera. Design the system that fills the question mark: real-time Pass/Fail within 100ms per unit, with defects occurring at only ~0.1%.

    Answer

    The solution is an Edge-AI Computer Vision Pipeline. It starts with a controlled imaging setup to capture consistent, high-quality images. The core is a lightweight CNN (e.g., MobileNetV2) fine-tuned via transfer learning, trained with a specialized loss (Focal Loss) to handle the rare-defect imbalance. Deployment runs on a local Edge GPU to guarantee low-latency inference, and a continuous MLOps loop monitors performance and retrains the model against new or subtle defects (concept drift).

    (1) Data & Setup: Controlled environment (lighting/staging) plus high-resolution cameras; transfer learning reduces the need for large-scale defect collection.
    (2) Imbalance Handling: Focal Loss (or weighted loss) combined with heavy data augmentation and oversampling of the rare ‘Fail’ class.
    (3) Model Architecture: A lightweight CNN (MobileNetV2, EfficientNet-B0) chosen for speed over a large, deep network.
    (4) Real-Time Deployment: Edge deployment on an industrial GPU (e.g., NVIDIA Jetson) with ONNX/TensorRT optimization and INT8 quantization to stay inside a sub-100ms budget.
    (5) Post-Deployment MLOps: Log every classification (especially false negatives) and trigger periodic retraining to combat model drift.

    End-to-end edge-AI quality control pipeline: camera and lighting feed preprocessing, an edge CNN classifier, a pass/fail actuator, and a logging path that loops back to periodic retraining

    Figure 1: The end-to-end pipeline. Solid arrows are the real-time inference path (capture → preprocess → edge CNN → actuator); the dashed loop is the offline MLOps path: logged hard examples and low-confidence frames flow back into retraining.

    Clarify Before Designing:
    (1) Throughput: line speed in units per minute, and the per-unit latency budget?
    (2) Defect Ontology: a closed set of defect types, or can new types appear in production?
    (3) Deployment Constraints: is cloud inference acceptable, or must everything run on-prem at the line?
    (4) Data Availability: how many labeled ‘Fail’ examples exist today, and what is the true defect rate?
    (5) Cost Asymmetry: the business cost of a false accept (defect escapes) versus a false reject (good unit scrapped)?


    Login to view more content
  • DL0039 Transformer Weight Tying

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0037 Transformer Architecture III

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0031 FFN in Transformer

    What is the purpose of the feed-forward network inside each Transformer block?

    Whiteboard question card for a 6-layer chat model. On the left, one Transformer block is drawn as tokens flowing into multi-head attention and then into a feed-forward box marked with question marks. On the right, a pull request proposes deleting the feed-forward sub-layer from all six blocks and asks whether to approve or reject it.

    The Problem: A team is shrinking a 6-layer Transformer chat model to fit on a phone by Friday. Dana opens PR #212, which argues that attention already mixes the tokens and proposes deleting the feed-forward sub-layer from every block.

    Answer

    The feed-forward network (FFN) inside each Transformer block processes every token independently after attention: it expands the token’s features into a higher-dimensional space, applies a non-linearity, and projects back to the model dimension. Attention mixes information across tokens; the FFN then deepens each token’s representation individually. It is where most of the block’s parameters and feature transformations actually happen.

    (1) Non-Linear Transformation: Adds the only per-token non-linearity in the block, letting the model capture complex patterns that attention’s linear weighting cannot express.
    (2) Token-Wise Processing: The same MLP is applied to each position separately: no cross-position mixing, so it parallelizes trivially over the sequence.
    (3) Dimensional Expansion: The hidden layer typically expands d_{model} by a factor of 4 (e.g., 512 → 2048), giving the network capacity to re-encode features before compressing them back.

    Mathematical Formulation:
    \mathrm{FFN}(x) = \max(0,\; xW_1 + b_1)\, W_2 + b_2

    Where:

    • x \in \mathbb{R}^{d_{model}} is one token’s vector after the attention sub-layer; the same function is applied to every position.
    • W_1 \in \mathbb{R}^{d_{model} \times d_{ff}}, W_2 \in \mathbb{R}^{d_{ff} \times d_{model}} are trainable weights; typically d_{ff} = 4\, d_{model}.
    • \max(0, \cdot) is the ReLU activation of the original paper; modern models swap in GELU or gated variants like SwiGLU.
    Diagram of the FFN expanding a token vector from 512 dimensions to 2048 through the first linear layer, applying GELU, and compressing back to 512 through the second linear layer.

    Figure 1: d \to 4d \to d: expand, activate, compress. The same two-layer MLP for every token position.

    Why the Expansion Matters: Projecting up to d_{ff} gives the network a wide workspace to recombine and re-weight the features attention produced; the second matrix then distills the result back to d_{model}. Roughly two-thirds of a vanilla Transformer’s parameters live in these FFN matrices.

    Complement to Attention: Multi-head attention is a weighted average of value vectors, a linear operation per head. Without the FFN, stacking attention layers would compose mostly linear maps; the FFN’s expansion + non-linearity supplies the representational depth that makes deep stacks worthwhile.


    Login to view more content
  • DL0023 Dilated Convolution

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0019 Go Deep

    How does increasing network depth impact the learning process?

    Whiteboard question card showing a team's current 4-layer defect classifier beside two proposed plain stacks of 16 and 64 layers, with a sticky note listing 50,000 labeled photos, a fixed GPU budget and a two-week deadline, and the open question of whether to go deeper.

    The Problem: A vision team’s 4-layer defect classifier has plateaued on 50,000 labeled circuit-board photos, and the lead proposes stacking it to 16 or 64 plain layers before a two-week deadline on a fixed GPU budget. Before anyone launches a run, the team has to decide what the extra depth will change about how the model learns.

    Answer

    Increasing network depth enhances feature learning and model capacity, but brings training instability, higher computational cost, and design complexity. Deeper stacks learn hierarchical representations (edges become textures, shapes, then objects) and can express certain complex functions far more efficiently than shallow networks, yet without modern techniques like residual connections and normalization, very deep networks are difficult or impossible to train.

    Benefits of Depth:

    (1) Improved Feature Hierarchy: Each layer composes the previous layer’s features, building increasingly abstract, high-level representations.
    (2) Increased Model Capacity: More layers let the network model more complex functions and patterns.
    (3) Exponential Efficiency for Complex Functions: Deep networks can represent some functions with vastly fewer units. For example, the n-input parity function needs roughly 2^{n-1} neurons in a single hidden layer but only about n small layers in a deep network.

    Challenges of Depth:

    (1) Vanishing/Exploding Gradients: Gradients shrink or grow multiplicatively through layers; without skip connections a 100-layer network may fail to train because gradients vanish before reaching early layers.
    (2) Increased Computational Cost: Deeper networks need significantly more compute and training time.
    (3) Higher Data Requirements: More parameters mean more overfitting risk unless the dataset grows correspondingly.

    Curve comparison showing a deep network tracking a complex high-frequency target function closely while a shallow network with a single hidden layer smooths over fine structure.

    Figure 1: A 6-layer network tracks the target’s high-frequency detail that a single-hidden-layer network smooths over. Depth buys compositional expressiveness.

    Where Depth Hurts Training: Each layer multiplies gradients by its Jacobian, so gradient magnitude behaves like a product of many factors; it collapses exponentially when those factors are consistently small.

    Log-scale chart of gradient norm per layer showing a plain deep network's gradients decaying exponentially into the vanishing zone while a residual network maintains healthy gradient magnitudes.

    Figure 2: In a plain deep network gradient norms decay exponentially toward the vanishing floor; skip connections keep gradients healthy across all 50 layers.

    Mathematical Formulation:
    \frac{\partial \mathcal{L}}{\partial x_1} = \prod_{l=1}^{L} J_l \cdot \nabla_{x_L}\mathcal{L}
    \lVert g_1 \rVert \approx \lVert \nabla_{x_L}\mathcal{L} \rVert \cdot \prod_{l=1}^{L} \sigma_l

    Where:

    • J_l is the Jacobian of layer l; gradients reaching the first layer are a product of L Jacobians.
    • \sigma_l is the dominant singular value of J_l; if most \sigma_l are below 1, the product, and hence \lVert g_1 \rVert, decays exponentially in L.
    • Residual blocks replace each factor with I + J_{F_l}, keeping the identity path alive so gradient norms stay near 1 even at 50+ layers.

    Login to view more content
  • ML0045 Multi-Layer Perceptron

    What is a Multi-Layer Perceptron (MLP)? How does it overcome Perceptron limitations?

    Three-panel sketch: a ring-shaped two-class dataset with one class inside a circle of the other, the single-neuron perceptron used to classify it, and a training-accuracy plot that stays near 50 percent while the 95 percent target is never reached.

    The Problem: A team trains a single perceptron (two inputs, a weighted sum and a step output) on a dataset where one class sits inside a ring of the other. After 500 epochs, accuracy is still stuck near 50%, so what limits this model, and what change to the architecture would let it learn this pattern?

    Answer

    A Multi-Layer Perceptron (MLP) is a feedforward neural network with one or more hidden layers between the input and output layers. Its hidden layers use non-linear activation functions (ReLU, sigmoid, or tanh) to model complex relationships, and it is trained with backpropagation, which adjusts the weights to minimize errors. MLPs are used for classification, regression, and function approximation.

    (1) Hidden Layers + Non-Linearity: Each hidden unit applies a non-linear activation to its weighted sum, letting the network compose many linear maps into a curved function.
    (2) Overcomes The Perceptron: Unlike a single-layer perceptron (restricted to linearly separable problems), an MLP learns non-linear decision boundaries and handles problems such as XOR.
    (3) Universal Approximation: With enough neurons and layers, an MLP can approximate any continuous function, making it a powerful general-purpose model.

    MLP with four input nodes, two hidden layers of six and four nodes, and a three class output layer, fully connected

    Figure 1: An MLP for 3-class classification: 4 inputs, two hidden layers (6 and 4 units) with non-linear activations, and 3 softmax-style outputs. Every layer is fully connected to the next.

    Mathematical Formulation:
    h_l = f\big(W_l\, h_{l-1} + b_l\big)
    \hat{y} = g\big(W_L\, h_{L-1} + b_L\big)

    Where:

    • h_l is the activation vector of layer l (h_0 = x is the input).
    • W_l, b_l are the weight matrix and bias of layer l, learned by backpropagation.
    • f(\cdot) is the hidden non-linearity (ReLU/sigmoid/tanh); g(\cdot) is the output map (softmax for classification, identity for regression).
    XOR data with the single layer perceptron failing to separate it and the MLP carving a non-linear region that separates it

    Figure 2: The payoff: on XOR, the perceptron’s single line misclassifies half the positives, while the MLP’s hidden units carve a curved region that separates the classes perfectly.


    Login to view more content
  • ML0036 Confusion Matrix

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.