27 interview questions on cnn architectures, each answered in full. Free to read, no account needed.
What made AlexNet (2012) a breakthrough?
easy- AlexNet: 8 layers, ReLU activations (huge speedup vs sigmoid), dropout (novel regularization), overlapping max pooling, local response normalization (LRN, now obsolete), heavy data augmentation, and GPU training split across 2 GTX 580s.
- Won ImageNet 2012 by 10+ percentage points — kicked off the deep-learning revolution and made GPUs mandatory for vision.
What is the design principle behind VGG?
easy- Stack 3x3 conv blocks repeatedly (2, 3, or 4 in a row) and downsample with max-pooling.
- Two stacked 3x3 convs have the same receptive field as one 5x5 but with fewer parameters and one extra nonlinearity — makes deeper nets with more nonlinearity cheap.
- VGG-16 / VGG-19 became the standard feature extractor for years.
- Downsides: enormous FC layers (140M params in VGG-16).
What is the Inception module?
medium- Multi-branch block that applies 1x1, 3x3, 5x5 convolutions and 3x3 max pool in parallel, concatenates the outputs along channels.
- Each branch captures features at a different scale. 1x1 bottlenecks reduce cost.
- Also introduces auxiliary classifiers at intermediate depths for training deep nets.
- GoogLeNet (Inception v1) won ImageNet 2014 with 22 layers and 6M params — 12x smaller than VGG-16.
What is the key insight of ResNet's identity mapping?
medium- A residual block computes y = F(x) + x, where F is a stack of convolutions.
- If the optimal function is close to identity, the block only needs to learn a small correction F(x) ≈ 0 — easier than learning the identity from scratch.
- Enabled training 152-layer nets on ImageNet in 2015.
- Skip connections also let gradients flow directly to earlier layers → no vanishing.
How is DenseNet different from ResNet?
medium- In a DenseNet block, each layer receives the concatenated feature maps of every preceding layer, not just the previous one.
- Massive feature reuse — each layer produces only 'growth rate' k channels (typically 12-32), so the whole network has surprisingly few parameters.
- Trade-offs: high memory usage (long concatenated feature maps), slower on GPU.
- Cool idea but ResNet-derived architectures dominate today.
What is MobileNet designed for?
medium- Efficient inference on mobile and embedded devices.
- Uses depthwise-separable convolutions everywhere and a 'width multiplier' α scaling all layer widths, plus a resolution multiplier ρ.
- MobileNet-v2 adds inverted residuals (expand → depthwise → project) and linear bottlenecks.
- MobileNet-v3 uses NAS + h-swish. 5-10x smaller and faster than ResNet at similar accuracy.
What is compound scaling in EfficientNet?
hard- Scale depth (d), width (w), and resolution (r) together by a single coefficient φ: d = α^φ, w = β^φ, r = γ^φ, with α⋅β2⋅γ2 ≈ 2 to keep FLOPs proportional to 2^φ.
- Better than scaling one dimension at a time.
- Combined with a NAS-found base (EfficientNet-B0) and MBConv blocks (mobile inverted bottleneck), EfficientNet-B7 hit 84% ImageNet top-1 in 2019 at 8.4x fewer params than the previous SOTA.
How does a Vision Transformer (ViT) treat images?
hard- Split image into fixed-size patches (e.g., 16×16), linearly embed each patch (like word embeddings), add positional embeddings, prepend a learnable [CLS] token, and feed to a standard transformer encoder.
- The CLS token's final representation is the image feature for classification.
- Requires huge pretraining data (JFT-300M) to match CNN accuracy — with less data, CNNs still win.
- DeiT (Touvron 2021) added distillation + augmentation to make ViT competitive at ImageNet-scale.
What does Swin Transformer do differently from ViT?
hard- Swin uses hierarchical (multi-scale) feature maps like CNNs, with attention computed inside local windows (e.g., 7×7 patches).
- Adjacent transformer blocks shift the windows so information flows across window boundaries — hence 'Swin' (Shifted Windows).
- O(N) complexity in image size vs ViT's O(N2), and produces multi-scale features suitable for detection / segmentation.
How does a two-stage detector (Faster R-CNN) work?
hard- Stage 1: a Region Proposal Network (RPN) sliding a small conv over the backbone's feature map generates ~1k-2k class-agnostic object proposals (anchor boxes + objectness).
- Stage 2: RoIAlign extracts fixed-size features from each proposal, then a small head classifies the region and refines the box.
- Slower but more accurate than one-stage detectors — still SOTA on many benchmarks.
- Feature Pyramid Networks (FPN) extend it to multi-scale features.
How does YOLO / SSD / RetinaNet differ from two-stage detection?
medium- One-stage detectors predict class and box in a single forward pass over dense anchor / grid locations — no proposal step.
- YOLO: divide image into an S×S grid, each cell predicts B boxes + class probs.
- SSD: multi-scale feature maps with different anchor scales.
- RetinaNet: adds Focal Loss to fix the extreme class imbalance (background vs objects).
- Much faster, real-time capable; historically less accurate but the gap narrowed with recent versions.
What is Non-Maximum Suppression (NMS) and its variants?
medium- Post-processing that removes duplicate detections: sort boxes by confidence, keep the top one, remove all others with IoU > threshold with it, repeat.
- Standard threshold: 0.5.
- Variants: Soft-NMS (lower the score of overlapping boxes instead of removing, better for occluded objects), matrix NMS (used in SOLOv2 segmentation), and class-aware vs class-agnostic.
- Recent detectors (DETR) avoid NMS entirely via set prediction.
What are anchor boxes and their downsides?
medium- Predefined reference boxes of various sizes and aspect ratios placed at every location of the feature map.
- The network predicts offsets and class scores relative to each anchor.
- Downsides: (1) requires careful anchor design (scales, ratios) per dataset; (2) massive class imbalance (foreground:background can be 1:1000); (3) many hyperparameters.
- Anchor-free methods (FCOS, CenterNet, DETR) predict box centers or points directly and skip anchors.
Why is U-Net so popular for segmentation?
medium- Encoder-decoder with skip connections between symmetric layers.
- Encoder downsamples via convs + pooling; decoder upsamples via transposed convs / bilinear + convs, and concatenates the same-resolution encoder features.
- Skips preserve fine spatial detail through the low-resolution bottleneck.
- Simple, data-efficient (works on small medical datasets), still the go-to baseline for biomedical / satellite / cell segmentation.
How does Mask R-CNN extend Faster R-CNN for instance segmentation?
hard- Add a parallel FCN mask-prediction head to each RoI, predicting a small binary mask (28×28 typically) per class.
- Replaces RoIPool with RoIAlign (bilinear interpolation instead of quantization) — critical for precise mask localization.
- Preserves the classification / box head.
- Standard instance-segmentation baseline; adopted broadly for pose estimation, keypoints, panoptic segmentation.
What is a Feature Pyramid Network (FPN)?
hard- A top-down architecture that fuses features from multiple backbone stages (different resolutions and semantic levels) into a pyramid where each level is high-resolution and semantically rich.
- Take the deep low-resolution feature, upsample, add to the mid-resolution feature, and so on.
- Powers most modern detectors (Faster R-CNN + FPN, RetinaNet, YOLOv3+, Mask R-CNN) by giving each RoI head or anchor set the right-scale features.
How does DETR reformulate object detection?
hard- DETR (Carion 2020) treats detection as a set-prediction problem: a transformer decoder outputs a fixed set of N (>>true count) predictions in parallel, matched to ground-truth objects via bipartite Hungarian matching during training.
- No anchors, no NMS.
- Simple, elegant, but slow to converge (500+ epochs) and struggles on small objects.
- Deformable-DETR fixes both by using deformable attention and multi-scale features.
Describe a single transformer encoder block in detail.
hard- Input x.
- Sublayer 1: y = x + Dropout(MultiHeadAttention(LayerNorm(x))).
- Sublayer 2: z = y + Dropout(MLP(LayerNorm(y))), where MLP = Linear → GELU → Linear with dffn=4d.
- Modern variants use RMSNorm instead of LN, GLU-family MLPs, and pre-norm placement.
- All ops are parallel across sequence positions — no recurrence.
How does a decoder block differ from an encoder block?
hard- Decoder has three sublayers: (1) masked self-attention (each token can only attend to earlier positions — causal mask); (2) cross-attention over encoder outputs (queries from decoder, keys/values from encoder); (3) MLP.
- Each still wrapped in pre-norm + residual + dropout.
- Decoder-only LLMs (GPT) skip cross-attention and use only masked self-attention + MLP.
Encoder-only vs decoder-only vs encoder-decoder — when do you pick each?
medium- Encoder-only (BERT, RoBERTa): bidirectional attention over the whole input → best for understanding tasks (classification, NER, retrieval embeddings).
- Decoder-only (GPT, LLaMA): causal attention → best for open-ended generation and general chat assistants.
- Encoder-decoder (T5, BART): full attention encoder + causal decoder + cross-attention → best for seq2seq (translation, summarization).
- Modern LLMs converged on decoder-only for scale simplicity and general-purpose behavior.
Explain focal loss and why it's used in dense detection.
hard- FL(pt) = -α⋅(1−pt)^γ⋅log(pt), where pt is the model's probability for the true class.
- The (1−pt)^γ term (γ ~ 2) down-weights well-classified examples, keeping the loss focused on hard examples.
- Fixes the extreme class imbalance in one-stage detectors (RetinaNet) where 100k background anchors dominate a few foreground ones.
- Also useful for imbalanced classification.
Write Dice loss and its role in segmentation.
medium- Dice = 1 - 2 * |P ∩ G| / (∣P∣+∣G∣) — one minus the Dice coefficient (F1 on binary masks).
- Directly optimizes overlap between predicted and ground-truth masks.
- Robust to foreground/background imbalance in medical images where the target is 1% of pixels.
- Often combined with BCE (Dice + BCE, or Dice + focal) for stability and calibration.
What is perceptual loss and why is it better than pixel-wise for image quality?
medium- Loss computed as MSE (or cosine similarity) between features from a pretrained network (e.g., VGG-19 conv layers) applied to prediction and target, rather than on raw pixels.
- Pretrained features capture perceptual similarity — small changes in features correspond to visually similar images.
- Pixel-MSE encourages blurry averages of possible outputs; perceptual loss produces sharper, more realistic reconstructions.
- Used in super-resolution, style transfer, image translation.
What are the main ideas of StyleGAN?
hard- (1) Map input latent z to an intermediate 'style' space W with an MLP — disentangles factors of variation.
- (2) Inject style at every layer of the generator via adaptive instance normalization (AdaIN) — controls features at multiple scales.
- (3) Noise injection at each layer adds fine-grained stochastic detail (hair, freckles).
- (4) Progressive growing (StyleGAN1) or top-down architecture (StyleGAN2/3) for high resolution.
- Produces photorealistic 1024×1024 faces and enables style mixing.
How does Latent Diffusion (Stable Diffusion) reduce compute?
hard- Train a VAE / autoencoder that maps 512×512 images to an 8-16x smaller latent space (e.g., 64×64×4).
- Run the diffusion process in that latent space instead of pixels.
- Compute drops ~50x, memory drops ~64x, quality is comparable to pixel-space diffusion after the VAE decoder up-samples the final latent.
- Foundation of Stable Diffusion (Rombach 2022) — democratized text-to-image generation on consumer hardware.
What are normalizing flows and their trade-off vs GANs / diffusion?
hard- Sequence of invertible transformations from a simple base (N(0, I)) to the data distribution, using the change-of-variables formula for exact log-likelihood.
- Advantages: exact density evaluation, invertible sampling.
- Disadvantages: constrained architectures (each layer must be invertible with a tractable Jacobian) → less expressive per-parameter than GAN / diffusion.
- Used in density estimation and RL where exact log p is needed.
- Modern generative modeling has mostly shifted to diffusion for quality.
What is Neural Architecture Search (NAS)?
hard- Automated search for the best architecture (layers, connections, widths) given a target task and constraints (FLOPs, latency, memory).
- Methods: reinforcement learning over architectures (NASNet, MnasNet), evolutionary search (AmoebaNet), gradient-based (DARTS — differentiable), or one-shot supernets (Once-For-All).
- Produced EfficientNet, MobileNetV3, MnasNet — SOTA vision architectures under mobile budgets.
- Now less used for LLMs (transformers are already close to optimal at scale); still active in edge vision and hardware-aware design.