Deep and practical expertise in convolutional neural networks and their architectures for spatial and visual data tasks. Candidates should understand convolution operations including filters and kernels, feature maps and receptive field, stride and padding, pooling operations, activation functions and normalization methods, and how these components combine to form a hierarchical representation of spatial features. Know architectural building blocks such as residual connections, dense connections, bottleneck layers, inception modules, squeeze and excitation blocks, depthwise separable and grouped convolutions, dilated convolutions, and attention augmented convolutions. Be familiar with canonical model families and examples such as AlexNet, VGG, ResNet, Inception, DenseNet, MobileNet, EfficientNet and modern hybrids that combine convolutional features with transformer based components, and be able to reason about design trade offs between depth and width, representational capacity, parameter counts, computational cost, latency and memory footprint. Understand training and regularization strategies including batch normalization and layer normalization, dropout, weight decay, data augmentation, optimizers and learning rate schedules, initialization, and techniques for training from scratch versus fine tuning pretrained models. Know transfer learning and domain adaptation approaches, and model compression and deployment techniques such as pruning, quantization, knowledge distillation and low rank factorization for mobile and edge systems. Be able to select and adapt architecture choices for specific vision tasks such as classification, object detection and instance segmentation, and to evaluate models using appropriate metrics such as classification accuracy and top k accuracy, intersection over union and mean average precision on standard benchmarks such as ImageNet and Common Objects in Context.
HardTechnical
22 practiced
A CNN trained on ImageNet performs well in academic benchmarks but fails in production on images from different camera sensors, lighting, and compression. Design a domain adaptation strategy to bridge this gap that includes data collection, synthetic augmentation, model adaptation (supervised, unsupervised, or test-time adaptation), and evaluation protocols for production validation.
Sample Answer
Requirements & constraints:- Target: production images vary by sensor, lighting, compression; low latency inference; limited labeled target data; must monitor model drift and support rollback.- Success metrics: per-class accuracy, AUC, calibration (ECE), false-positive rate on safety classes, and latency/throughput.Data collection:- Collect representative target-domain samples across sensors, lighting, distances, and compression levels. Log camera metadata (ISO, exposure, white balance, model) and capture conditions. Label a stratified subset (~1–5% per class) prioritized by high-impact classes and failure modes. Maintain an unlabeled pool for unsupervised methods.Synthetic augmentation:- Photometric: varied gamma, exposure, color temperature, sensor-specific white balance shifts.- Noise & optics: sensor noise models (Poisson–Gaussian), demosaicing artifacts, lens blur/PSF.- Compression: realistic JPEG/WebP at varied Q factors, macroblocking.- Style & domain transfer: use CycleGAN / AdaIN or neural style transfer trained between source and target sensors to synthesize texture/style shifts.- Geometric & occlusion: realistic cropping, motion blur, partial occluders.- Use physically-based rendering (if possible) to simulate scenes for rare classes.Model adaptation strategy:- Supervised (when labeled target available): fine-tune last blocks + batchnorm stats on target labels with strong class reweighting; use mixup & focal loss to handle label scarcity.- Unsupervised / source-free: Domain-Adversarial Training (DANN) on unlabeled target to learn domain-invariant features; combine with entropy minimization and pseudo-labeling with confidence thresholding and temporal ensembling to avoid drift.- BatchNorm / InstanceNorm adaptation: update running mean/var using target minibatches (lightweight, effective for sensor shifts).- Test-Time Adaptation (TTA): implement a conservative TENT-like approach that adapts affine BN params by minimizing entropy per batch at inference — gated by confidence and rate limits to avoid catastrophic shift. For safety-critical classes, disable TTA or restrict to shadow evaluation.- Source-free distillation: if source data unavailable, use source model to generate pseudo-labels on augmented target and distill robust model.- Continual learning & safeguards: use replay buffer of labeled source/target exemplars and L2 regularization to prevent forgetting; maintain ensemble or EMA model for stability.Evaluation & production validation:- Offline: create holdout test sets per sensor and lighting strata; evaluate accuracy, per-class recall/precision, ECE, robustness under compression/noise sweeps. Run ablation (augmentation only, BN-adapt, DANN, TENT).- Shadow deployment: run adapted models in parallel (no impact to users) to compare predictions vs. baseline; compute online metrics and human-in-the-loop labels for flagged disagreement cases.- A/B experiments: small-percentage rollout with monitoring of core metrics and business KPIs; automated rollback triggers on metric drops.- Monitoring: deploy real-time drift detectors on input distribution (feature statistics), prediction confidence, and error rates. Trigger retraining pipeline when drift exceeds thresholds.- CI/CD and governance: version data, models, and adaptation configs; log metadata; require staged approvals for adaptive mechanisms like TTA.Why this works:- Combines physical realism (sensor/noise models) with learned style transfer to cover gaps.- Mixes lightweight normalization fixes (BN) with stronger unsupervised learning (DANN, pseudo-labels) and cautious test-time adaptation, balancing performance gains and safety.- Rigorous validation and monitoring ensure production reliability and fast remediation.
HardTechnical
26 practiced
You need to reduce wall-clock training time for a large CNN by approximately 4x without losing more than 1% absolute accuracy. Propose a concrete plan combining algorithmic, optimization, and systems techniques (for example, mixed precision, larger-batch training with adjusted LR, distillation, progressive resizing, partial freezing). Explain why each choice helps and how to validate the approach.
Sample Answer
Plan (goal: ~4x wall-clock reduction, ≤1% absolute accuracy loss). Combine systems + optimization + algorithmic changes, validate with staged ablation.1) Fast wins — hardware & pipeline- Mixed precision (AMP FP16): enable loss-scaling, use cuDNN/tensor cores. Why: ~1.5–2x throughput on modern GPUs. Validate: single-GPU throughput and convergence parity vs FP32 (train for few epochs).- Optimize data pipeline: use TFRecords / WebDataset, prefetch, parallel decoding, NVIDIA DALI or GPU augmentation, pinned memory, larger IO buffers, NVMe cache. Why: removes CPU bottleneck; improves GPU utilization. Validate: measure GPU utilization and input pipeline stall metric.2) Throughput scaling- Increase global batch size ~4x (or as needed to hit throughput target) with synchronous distributed data-parallel across multiple GPUs/nodes (NCCL, Horovod or native DDP). Why: larger effective batch increases samples/sec; distributed all-reduce scales wall-clock down. Validate: measure samples/sec and wall-clock per epoch; ensure near-linear scaling with added devices.- Adjust LR using Linear Scaling Rule: lr' = lr * (new_batch / baseline_batch), with a warmup (e.g., 5–10% of total steps). If very large batch, use LARS or LAMB optimizer to preserve generalization. Validate: run short full-protocol training and compare final val accuracy.3) Algorithmic speedups with minimal accuracy loss- Progressive resizing: start training on smaller images (e.g., 128→160→224) with corresponding LR schedule, fine-tune final epochs at full resolution. Why: initial epochs cheap, still learn broad features. Validate: train two-stage and compare final accuracy.- Partial freezing: after initial convergence (e.g., first 10-20% epochs), freeze early convolutional blocks and only update later layers (and BN stats as needed). Why: reduces backward compute, I/O of optimizer states; risk: reduced representational tuning. Validate: ablation freezing vs baseline.- Knowledge distillation (teacher = original full training run): train a smaller/shallower student or same architecture but with fewer epochs using soft targets + CE. Why: student can reach comparable accuracy faster; or use distillation as fine-tune to recover any accuracy loss from other speedups. Validate: compare student accuracy on val/test; use KD loss weight sweep.4) Training schedule and regularization- Shorten epochs with cosine LR or one-cycle schedule tuned for larger batch; use label smoothing and mixup (as used originally) to maintain generalization. Validate: track training vs validation curves.Validation & experiment design- Baseline: full FP32, baseline batch, baseline pipeline — record wall-clock/epoch, samples/sec, final test accuracy.- Staged ablations (one change at a time): mixed precision; data pipeline; batch scaling+LR; progressive resizing; freezing; distillation. Each stage measure wall-clock to target (4x) and final accuracy.- Combined run: apply all that passed ablations. If accuracy drop >1%, use KD fine-tuning or reduce batch scale / increase fine-tune epochs.- Metrics: wall-clock to target accuracy, samples/sec, GPU utilization, communication overhead, final top-1/top-5. Use multiple seeds (3) for statistical confidence.Risks & mitigations- Large-batch generalization loss → use LARS/LAMB, warmup, longer fine-tune, distillation.- BN instability with freezing/FP16 → keep BN in eval or use SyncBN; track loss spikes, use dynamic loss-scaling.- Communication overhead → overlap compute/comm, gradient fusion, gradient compression if needed.Expected contributions: mixed precision + optimized pipeline + 4x batch scaling across GPUs likely accounts for ~3–4x throughput; progressive resizing, partial freezing, and distillation recover or maintain accuracy within the 1% budget.
MediumTechnical
27 practiced
Compare unstructured magnitude pruning, structured channel pruning, and iterative pruning schedules for CNNs. For each approach explain algorithmic steps, expected effect on accuracy, sparsity patterns, and practical deployment considerations on real hardware.
Sample Answer
Unstructured magnitude pruning- Algorithmic steps: train baseline → compute weight magnitudes → zero out smallest k% (one-shot) or gradually (iterative unstructured) → fine-tune to recover accuracy.- Expected accuracy effect: can retain high accuracy at high sparsity if fine-tuned; irregular sparsity may hurt slightly but often best accuracy-vs-parameter trade-off.- Sparsity pattern: fine-grained random zeros across tensors.- Deployment: poor hardware speedup without specialized sparse kernels/hardware (CSR/CSC; overheads for indexing), memory/compression benefits but limited latency gains on CPUs/GPUs.Structured channel pruning- Algorithmic steps: score channels/filters (L1-norm, Taylor, learned gates) → remove whole channels → adjust following layers (remove corresponding filters) → fine-tune; often iterative with re-evaluation.- Expected accuracy effect: larger accuracy drop per parameter removed, but more predictable; with careful selection and retraining can maintain accuracy for moderate compression.- Sparsity pattern: coarse-grained (entire channels/filters removed), regular.- Deployment: excellent practical speedups and memory reduction on standard hardware and frameworks; simpler to export and accelerate.Iterative pruning schedules- Algorithmic steps: apply pruning in multiple small steps (either unstructured or structured) interleaved with fine-tuning; can use learning-rate resets, rewind to early weights (lottery-ticket style) or gradual magnitude thresholds.- Expected accuracy effect: better recovery and higher final sparsity for given accuracy vs. one-shot; helps preserve performance.- Sparsity pattern: depends on underlying method (structured or unstructured) but more stable/optimized distribution across layers.- Deployment: combines benefits of chosen granularity; iterative structured pruning yields best real-world speedups with minimal accuracy loss, iterative unstructured gives high compression but needs sparse-runtime support.Practical tips- Use per-layer sparsity targets, sensitivity analysis, and combine pruning with quantization/distillation.- For edge/production, prefer structured or block-sparse methods; for model storage/transfer, unstructured plus compression is attractive.
MediumTechnical
23 practiced
In PyTorch, implement a ResNet-style bottleneck block with expansion factor 4: 1x1 reduce -> 3x3 -> 1x1 expand. Support downsampling via stride and optional identity projection when channels differ. Explicitly state your BatchNorm and ReLU ordering and justify the choice (pre-activation vs original).
Sample Answer
Approach: implement a Bottleneck block with 1x1 reduce -> 3x3 -> 1x1 expand, expansion=4, optional downsampling via stride, and optional identity projection when in/out channels differ. I choose pre-activation ordering (BN -> ReLU -> Conv) as in "Identity Mappings in Deep Residual Networks" because it improves gradient flow and training stability for deep nets.
python
import torch
import torch.nn as nn
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, in_channels, out_channels, stride=1, downsample=None):
super().__init__()
mid = out_channels
# Pre-activation: BN -> ReLU -> Conv
self.bn1 = nn.BatchNorm2d(in_channels)
self.relu = nn.ReLU(inplace=True)
self.conv1 = nn.Conv2d(in_channels, mid, kernel_size=1, bias=False)
self.bn2 = nn.BatchNorm2d(mid)
self.conv2 = nn.Conv2d(mid, mid, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn3 = nn.BatchNorm2d(mid)
self.conv3 = nn.Conv2d(mid, out_channels * self.expansion, kernel_size=1, bias=False)
self.bn_out = nn.BatchNorm2d(out_channels * self.expansion)
# identity projection if needed (channel or spatial mismatch)
if downsample is None and (stride != 1 or in_channels != out_channels * self.expansion):
self.downsample = nn.Sequential(
nn.Conv2d(in_channels, out_channels * self.expansion, kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(out_channels * self.expansion),
)
else:
self.downsample = downsample
def forward(self, x):
identity = x
out = self.bn1(x)
out = self.relu(out)
out = self.conv1(out)
out = self.bn2(out)
out = self.relu(out)
out = self.conv2(out)
out = self.bn3(out)
out = self.relu(out)
out = self.conv3(out)
out = self.bn_out(out)
if self.downsample is not None:
identity = self.downsample(x)
out += identity
out = self.relu(out) # final activation after addition (keeps pre-activation behavior)
return out
Key points:- Pre-activation places BN+ReLU before convs, improving gradient flow and enabling deeper nets.- Identity projection handled by 1x1 conv+BN when stride!=1 or channel mismatch.Complexity:- Time: O(FHW) per block proportional to conv ops.- Space: O(1) extra params beyond conv/BN.Edge cases:- Ensure input batchnorm statistics warm up (use eval/train modes).- If using original ResNet (post-activation) replace conv->bn->relu ordering and move final BN out accordingly.Alternative:- Original ResNet ordering (conv->BN->ReLU) is valid for shallower models and some pretrained checkpoints.
MediumTechnical
21 practiced
BatchNorm becomes unstable when per-GPU batch size is 1 for detection tasks. Explain why batch statistics are problematic in this regime and propose at least four practical strategies to mitigate the issue during training and inference, including both algorithmic and framework-level solutions.
Sample Answer
BatchNorm relies on accurate mini-batch statistics (mean, variance). When per-GPU batch size = 1 (common in detection with large images), the per-device sample variance is zero or very noisy, so estimated moments are poor: this causes unstable gradients, collapsed activations, and mismatch between training and inference running statistics.Concrete reasons:- Variance estimation with 1 sample is undefined (zero) → gamma/beta scaling leads to extreme activations.- High noise in means/vars across steps breaks learning dynamics.- Running (EMA) statistics computed from noisy per-step moments diverge from true population stats → inference mismatch.Practical mitigation strategies (algorithmic + framework-level):1. SyncBatchNorm (cross-GPU syncing): aggregate per-GPU moments across all devices to form an effective larger batch for BN. Pros: keeps BN semantics; Cons: extra communication and latency.2. Replace BatchNorm with non-batch-dependent norms: GroupNorm or LayerNorm. Pros: stable with batch size 1; Cons: may need hyperparameter tuning (group count).3. Freeze BN parameters / use Eval mode during most of training (or after warm-up): stop updating running stats and treat BN as affine transform. Pros: removes noisy updates; Cons: may hurt adaptability early—combine with short warm-up where BN is trained.4. Use Batch Renormalization or Ghost BatchNorm: BatchRenorm constrains instantaneous stats to be close to running stats; Ghost BatchNorm splits a large logical batch into smaller virtual batches (or simulate larger batch by accumulating gradients). Pros: reduces instability while preserving BN benefits.5. Accumulate gradients to increase effective batch size (micro-batching) before BN updates or perform gradient accumulation across iterations with synchronized BN statistics. Pros: improves moment estimates without extra memory; Cons: changes optimization dynamics.6. Maintain separate running stats per domain/scale or use momentum tuning: lower BN momentum (slower EMA) so running stats change less from noisy steps; also initialize running stats from a short precompute pass over a few images.Recommendation: first try GroupNorm (algorithmic) for robustness; if preserving BN is required, use SyncBatchNorm + lower momentum or BatchRenorm; combine with small precompute to initialize running stats or freeze BN later in training.
Unlock Full Question Bank
Get access to hundreds of Convolutional Neural Networks interview questions and detailed answers.