Computer Vision Interview
60 Q&A
Chapter 19
CV Libraries & Frameworks — Interview Q&A
OpenCV, PyTorch torchvision, and TensorFlow/Keras vision APIs for production workflows.
60 questions
Chapter 19
OpenCV: 20 Essential Q&A
1
What is OpenCV?
⚡ easy
Answer: Open-source computer vision library with C++ core and Python/Java bindings—image I/O, filters, geometry, features, ML/DNN hooks.
2
What is a Mat?
📊 medium
Answer: Dense n-dimensional array—stores pixels with type (8UC3, etc.), refcounted; ROI shares data unless
copy() used.
3
imread flags?
⚡ easy
Answer: IMREAD_COLOR, GRAYSCALE, UNCHANGED—default BGR color; watch alpha and 16-bit paths for medical/raw imagery.
4
Why BGR?
📊 medium
Answer: Historical—matplotlib expects RGB; convert with
cvtColor before display in Python notebooks.
img = cv2.imread("x.jpg"); gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
5
resize interpolation?
📊 medium
Answer: INTER_LINEAR default; INTER_AREA for downscale; INTER_CUBIC/LANCZOS4 for quality upsampling—trade speed vs sharpness.
6
Drawing functions?
⚡ easy
Answer: line, rectangle, circle, putText—modify image in-place; anti-aliased variants available.
7
GaussianBlur?
📊 medium
Answer: Separable kernel smoothing—reduce noise before edge detect; kernel size should be odd.
8
Canny steps?
📊 medium
Answer: Gradient + hysteresis thresholds—good thin edges; sensitive to blur and threshold tuning.
9
findContours?
📊 medium
Answer: Expects binary mask; returns boundary curves—CHAIN_APPROX_SIMPLE compresses polygons; use for shape analysis.
10
Morphology?
⚡ easy
Answer: erode/dilate/open/close with structuring element—clean masks, separate blobs, fill holes.
11
VideoCapture?
📊 medium
Answer: Read camera or file; check
isOpened(); codec fourcc for VideoWriter—platform quirks on macOS/Windows.
12
Python vs C++?
📊 medium
Answer: Same algorithms; Python faster to prototype; C++ for embedded latency—NumPy array can wrap Mat zero-copy in some flows.
13
dnn module?
📊 medium
Answer: Read ONNX/Caffe/TF frozen graphs—
blobFromImage, setInput, forward—good for deployment without full DL framework.
14
calib3d snapshot?
🔥 hard
Answer: calibrateCamera, undistort, stereoRectify—pinhole + distortion model for AR and measurement.
15
ROI pitfalls?
📊 medium
Answer: Slicing shares memory—mutations affect parent Mat; clone for independent crop.
16
Performance?
📊 medium
Answer: Avoid Python loops on pixels; use vectorized OpenCV; optional IPP/TBB builds; profile hot paths.
17
UMat / OpenCL?
🔥 hard
Answer: Transparent OpenCL offload when T-API enabled—mixed pipelines need careful sync with Mat.
18
Why build from source?
⚡ easy
Answer: Enable nonfree (SIFT/SURF in older builds), CUDA, custom flags—wheels on PyPI are convenient but fixed options.
19
License?
⚡ easy
Answer: Apache 2.0 (4.5+)—older versions mixed; check contrib modules and patent notes for algorithms.
20
Alternatives?
📊 medium
Answer: scikit-image, Pillow (limited CV), VTK, vendor SDKs—OpenCV remains default for classical CV education and tooling.
PyTorch Vision (torchvision): 20 Essential Q&A
21
What is torchvision?
⚡ easy
Answer: PyTorch domain library for vision—datasets, transforms, model architectures, and utilities (ops, io).
22
Transforms v2?
📊 medium
Answer: Tensor-based, torchscript-friendly transforms with consistent API for image/video/bbox/mask—prefer over legacy PIL transforms.
23
Compose?
⚡ easy
Answer: Chain transforms in order—typically Resize → ToImage → ToDtype(scale) → Normalize before batching.
24
ImageFolder?
📊 medium
Answer: Folder-per-class dataset returning image, label—pairs with DataLoader for supervised classification finetuning.
25
Common augmentations?
📊 medium
Answer: RandomResizedCrop, hflip, ColorJitter, RandAugment—match train vs eval (no randomness at test).
26
Normalize mean/std?
📊 medium
Answer: Per-channel (x-mean)/std—use weights’ documented stats (ImageNet) when loading pretrained backbones.
27
models.resnet50 pattern?
⚡ easy
Answer: Factory functions return architecture; pass
weights=ResNet50_Weights.IMAGENET1K_V2 for pretrained kernels.
from torchvision import models; m = models.resnet50(weights="DEFAULT")
28
Weights enums?
📊 medium
Answer: Typed enums carry meta (categories, metrics)—
get_weight() or auto-download on first use; reproducible defaults.
29
Finetune classifier?
🔥 hard
Answer: Replace final FC layer to num_classes; freeze backbone optionally; differential LR for head vs body.
30
DataLoader notes?
📊 medium
Answer: num_workers, pin_memory=True on GPU, persistent_workers—collate_fn for variable-size detection batches.
31
Detection helpers?
🔥 hard
Answer: coco_eval, NMS in torchvision.ops—RCNN/Mask R-CNN reference implementations live in torchvision.detection.
32
ONNX export?
📊 medium
Answer: torch.onnx.export on wrapped model—watch dynamic axes and op support; verify in onnxruntime.
33
torchvision vs timm?
📊 medium
Answer: timm: huge model zoo; torchvision: tightly coupled PyTorch references—often mix timm backbone + custom head.
34
AMP?
⚡ easy
Answer: autocast + GradScaler—most torchvision ops support fp16 on CUDA; watch BatchNorm numerics.
35
torchvision.ops?
📊 medium
Answer: ROIAlign, NMS, box_iou—building blocks for detectors; CUDA kernels behind the scenes.
36
Video datasets?
📊 medium
Answer: Kinetics-style readers + temporal transforms—memory heavy; clip sampling strategies matter.
37
Extract features?
🔥 hard
Answer: Forward hooks or intermediate layers API—FPN-style multi-scale features for segmentation/detection heads.
38
torch.jit?
🔥 hard
Answer: Trace or script model+transforms carefully—some dynamic Python in transforms blocks scripting.
39
Version coupling?
⚡ easy
Answer: torchvision releases track specific torch versions—install matched pairs to avoid binary incompatibility.
40
Debug pipeline?
⚡ easy
Answer: Visualize tensors after transforms; assert value ranges [0,1] or normalized; check label mapping in ImageFolder.
TensorFlow Vision: 20 Essential Q&A
41
TensorFlow vision stack?
⚡ easy
Answer: Keras high-level API + tf.data for input pipelines + optional KerasCV for detection/segmentation blocks.
42
Why tf.data?
📊 medium
Answer: Declarative, parallel map/prefetch/batch—keeps GPU fed;
cache() and prefetch(AUTOTUNE) are standard patterns.
ds = tf.data.Dataset.list_files("*.jpg").map(decode_fn).batch(32).prefetch(tf.data.AUTOTUNE)
43
Preprocessing layers?
📊 medium
Answer: Augment inside model (RandomFlip, RandomRotation) for exportable training graph—same code path in TFLite if supported.
44
keras.applications?
⚡ easy
Answer: Pretrained ResNet, EfficientNet, etc.—set
include_top false for feature extraction; load imagenet weights.
45
Finetuning recipe?
🔥 hard
Answer: Freeze base, train head; unfreeze top layers with small LR; use early stopping—watch catastrophic forgetting on tiny data.
46
TPU strategy?
🔥 hard
Answer: TPUStrategy scope + dataset stored in GCS—batch size and image size constraints differ from GPU pipelines.
47
MirroredStrategy?
📊 medium
Answer: Data-parallel multi-GPU on one host—simple path to scale batch without manual gradient sync code.
48
SavedModel?
📊 medium
Answer: Directory with graph + variables + signatures—TF Serving and TFLite consume this interchange format.
49
TFLite conversion?
📊 medium
Answer: TFLiteConverter.from_keras_model—select ops, FP16/INT8 quantization for mobile/NPU deployment.
50
Quantization-aware training?
🔥 hard
Answer: Simulate low precision during training—better INT8 accuracy than post-training quant on hard models.
51
TensorFlow Serving?
📊 medium
Answer: Model server with REST/gRPC—batching scheduler for production latency/throughput tradeoffs.
52
What is KerasCV?
📊 medium
Answer: Modular OD/seg components (YOLO, RetinaNet building blocks), augmentations—accelerates TF-native vision research.
53
TF vs PyTorch (interview angle)?
📊 medium
Answer: TF: deployment/serving story, TPU; PyTorch: research ergonomics—both mature for vision; know your team stack.
54
TFRecord?
⚡ easy
Answer: Serialized Example protos for large datasets—efficient sequential read on GCS; not mandatory for small local image folders.
55
@tf.function?
📊 medium
Answer: Trace graph for performance—avoid Python side effects; use Tensor ops inside for autograph success.
56
tf.io.decode_image?
⚡ easy
Answer: Decode JPEG/PNG to uint8 tensor—pair with convert_image_dtype for float pipeline.
57
Losses for segmentation?
📊 medium
Answer: SparseCategoricalCrossentropy with logits, Dice/Focal in add-ons—match activation (sigmoid vs softmax) and mask handling.
58
Profiler?
⚡ easy
Answer: TensorBoard profiler traces input bottleneck vs GPU kernel gaps—optimize prefetch and augmentation placement.
59
TF Hub?
📊 medium
Answer: Reusable SavedModel modules (image feature vectors)—quick baseline without training from scratch.
60
Debugging?
⚡ easy
Answer: tf.data.take(1), eager execution default in TF2, assert shapes—Static vs dynamic shapes affect XLA.
Full tutorial chapter
Pair these interview notes with the matching CV tutorial chapter.