1. Home
  2. Explore
  3. Computer Science
  4. Deep Learning for Computer Vision

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Deep Learning for Computer Vision

  • 40Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Tensor Essentials

What is a tensor in TensorFlow?

40 questions

  1. 1

    What is a tensor in TensorFlow?

    Model answer

    A tensor is a multi-dimensional array, the core data structure in TensorFlow, with dimensions from 0D (scalar) to 4D or higher.

    Explanation

    Tensors generalize scalars, vectors, and matrices to arbitrary dimensions, and all operations in TensorFlow work on tensors.

  2. 2

    How can you create a tensor with all ones?

    Model answer

    Use tf.ones(shape) to create a tensor filled with ones.

    Explanation

    tf.ones is a utility function that returns a tensor of the given shape with all elements set to 1.

  3. 3

    What does the tf.Variable class provide that tf.Tensor does not?

    Model answer

    tf.Variable can be updated during training using methods like assign, assign_add, and assign_sub, whereas tf.Tensor is immutable.

    Explanation

    Variables hold mutable state, which is essential for model weights that need to be changed through gradient descent.

  4. 4

    Explain how broadcasting works in TensorFlow.

    Model answer

    Broadcasting automatically expands the dimensions of smaller tensors to match larger ones during element-wise operations, similar to NumPy broadcasting rules.

    Explanation

    For example, adding a scalar or a vector to a matrix works because the scalar is broadcast across all elements.

  5. 5

    What is the purpose of the Normalization layer in the car price prediction model?

    Model answer

    It normalizes input features by subtracting the mean and dividing by the standard deviation, which helps the model converge faster.

    Explanation

    Normalization can either use pre-specified statistics or learn them from data via adapt().

  6. 6

    List three common loss functions for regression and their characteristics.

    Model answer

    Mean Squared Error (MSE) heavily penalizes outliers; Mean Absolute Error (MAE) is robust to outliers; Huber Loss combines both with a tunable threshold.

    Explanation

    The choice of loss affects how the model treats large errors.

  7. 7

    How does the Stochastic Gradient Descent (SGD) update rule work?

    Model answer

    It updates weights as weight = weight - learning_rate * gradient_of_loss.

    Explanation

    The gradient points in the direction of steepest increase, so subtracting it reduces the loss.

  8. 8

    Why is the learning rate important in training a model?

    Model answer

    A learning rate that is too small leads to slow convergence, while one that is too large can cause divergence.

    Explanation

    The learning rate controls the step size during gradient descent; finding an appropriate value is crucial.

  9. 9

    What are the benefits of using tf.data.Dataset for data loading?

    Model answer

    It enables efficient data loading with built-in methods for shuffling, batching, and prefetching, which speeds up training.

    Explanation

    Prefetching allows the CPU to prepare the next batch while the GPU is training, reducing idle time.

  10. 10

    What is the shape of an image tensor in a CNN?

    Model answer

    An image tensor has shape (height, width, channels), typically (H, W, 3) for RGB images.

    Explanation

    Height and width are spatial dimensions, and channels represent color (R, G, B) or grayscale.

  11. 11

    What is the role of the convolution operation in a CNN?

    Model answer

    A convolutional layer applies filters (kernels) that slide over the input to produce feature maps, detecting patterns like edges and textures.

    Explanation

    Convolution preserves spatial relationships and is more efficient than fully connected layers for images.

  12. 12

    What is the difference between 'valid' and 'same' padding in a convolutional layer?

    Model answer

    'Valid' padding means no padding, so the output spatial size is reduced. 'Same' padding adds zeros so the output size equals the input size.

    Explanation

    Padding controls the spatial dimensions of the output feature maps.

  13. 13

    Why is binary cross-entropy used as the loss function for binary classification?

    Model answer

    Binary cross-entropy measures the difference between true labels and predicted probabilities, penalizing confident wrong predictions heavily.

    Explanation

    It is derived from maximum likelihood estimation for Bernoulli distributions.

  14. 14

    When would precision and recall be more important than accuracy?

    Model answer

    When there is class imbalance or when the costs of false positives and false negatives differ significantly.

    Explanation

    For example, in disease detection, false negatives are worse; in spam detection, false positives are worse.

  15. 15

    For a multi-class classification problem with 3 classes, what activation function should the output layer use?

    Model answer

    Softmax activation, which outputs a probability distribution over the classes summing to 1.

    Explanation

    Softmax ensures the outputs are positive and sum to 1, suitable for mutually exclusive classes.

  16. 16

    What is the purpose of TopKCategoricalAccuracy?

    Model answer

    It computes the accuracy where the correct class is among the top K predictions, useful when multiple correct classes exist or for more lenient evaluation.

    Explanation

    For example, Top-2 accuracy counts a prediction as correct if the true label is in the top 2 predicted probabilities.

  17. 17

    How does the Functional API differ from the Sequential API in Keras?

    Model answer

    The Functional API allows non-linear topologies, multiple inputs/outputs, and shared layers, whereas the Sequential API only supports linear stacks.

    Explanation

    The Functional API treats layers as callable functions, giving more flexibility for complex models.

  18. 18

    What is the purpose of tf.GradientTape in a custom training loop?

    Model answer

    It records operations for automatic differentiation, enabling computation of gradients of the loss with respect to trainable variables.

    Explanation

    The tape is used to watch tensors and then compute gradients via tape.gradient().

  19. 19

    What does the @tf.function decorator do?

    Model answer

    It converts a Python function into a callable TensorFlow graph, which can be faster and more portable.

    Explanation

    Graph mode allows optimizations like op fusion and can be exported for serving.

  20. 20

    Explain the EarlyStopping callback and its purpose.

    Model answer

    EarlyStopping monitors a metric (e.g., validation loss) and stops training when the metric stops improving, preventing overfitting.

    Explanation

    It uses a patience parameter to allow fluctuations before stopping.

  21. 21

    What is the Mixup data augmentation technique?

    Model answer

    Mixup creates new samples by taking a weighted linear combination of two input images and their one-hot labels.

    Explanation

    This encourages the model to have linear behavior between training examples, improving generalization.

  22. 22

    How does Weights & Biases (W&B) integrate with Keras?

    Model answer

    W&B integrates via a Keras callback that logs metrics, hyperparameters, and model artifacts during training.

    Explanation

    The callback automatically sends data to the W&B dashboard for experiment tracking.

  23. 23

    What is a TensorFlow Record?

    Model answer

    A TensorFlow Record is an efficient binary format for storing and serializing large datasets, with preprocessed data for faster training.

    Explanation

    Data is serialized into protobuf messages, allowing for high-throughput reading.

  24. 24

    What is overfitting and what causes it?

    Model answer

    Overfitting occurs when a model performs well on training data but poorly on unseen data, often due to a small dataset or an overly complex model.

    Explanation

    The model memorizes noise instead of learning generalizable patterns.

  25. 25

    List three strategies to combat overfitting.

    Model answer

    Data augmentation, dropout, and L2 regularization (weight decay).

    Explanation

    Other strategies include early stopping, reducing network complexity, and using batch normalization.

  26. 26

    What is the key architectural innovation of ResNet?

    Model answer

    ResNet introduces skip connections (residual blocks) that allow gradients to flow directly through the network, mitigating the vanishing gradient problem.

    Explanation

    These skip connections enable training of very deep networks like ResNet-152.

  27. 27

    How does MobileNet achieve computational efficiency?

    Model answer

    MobileNet uses depthwise separable convolutions, which factorize a standard convolution into a depthwise convolution and a pointwise convolution, reducing parameters and computation.

    Explanation

    This makes it suitable for mobile and edge devices.

  28. 28

    What is compound scaling in EfficientNet?

    Model answer

    Compound scaling uniformly scales network depth, width, and input resolution using a fixed scaling coefficient.

    Explanation

    This balances all dimensions for optimal performance under resource constraints.

  29. 29

    Explain the transfer learning process for image classification.

    Model answer

    Take a pre-trained model (e.g., EfficientNet), remove its final classification layers, add new layers for the target task, and train only the new layers (feature extraction). Optionally, fine-tune by unfreezing some or all layers with a low learning rate.

    Explanation

    Transfer learning leverages features learned on large datasets to improve performance on small datasets.

  30. 30

    How does a Vision Transformer (ViT) process an image?

    Model answer

    It splits the image into fixed-size patches, flattens and linearly projects them into patch embeddings, adds positional embeddings and a class token, and passes the sequence through a standard Transformer encoder.

    Explanation

    ViTs treat image patches like word tokens in NLP and rely on self-attention to capture global dependencies.

  31. 31

    What does Grad-CAM produce?

    Model answer

    Grad-CAM generates a heatmap over the input image indicating the regions most influential for a model's prediction, by computing the gradient of the class score with respect to the final convolutional feature maps.

    Explanation

    The heatmap highlights important areas, providing visual explanations for CNN decisions.

  32. 32

    What is the ONNX format used for?

    Model answer

    ONNX (Open Neural Network Exchange) allows models to be converted between different frameworks (e.g., TensorFlow to PyTorch) and run efficiently on various hardware using the ONNX Runtime.

    Explanation

    It provides interoperability and optimized inference across platforms.

  33. 33

    What is quantization and why is it used?

    Model answer

    Quantization reduces model size and speeds up inference by converting weights and activations from 32-bit floats to lower-bit formats (e.g., 8-bit integers).

    Explanation

    Techniques include post-training quantization (dynamic/static) and Quantization-Aware Training (QAT).

  34. 34

    How does YOLO frame object detection?

    Model answer

    YOLO frames object detection as a regression problem: it divides the image into an SimesSS imes SSimesS grid, and each cell predicts BBB bounding boxes, confidence scores, and class probabilities.

    Explanation

    The output tensor has shape SimesSimes(B∗5+C)S imes S imes (B * 5 + C)SimesSimes(B∗5+C), enabling single-pass prediction.

  35. 35

    What is Intersection over Union (IoU) used for in YOLO?

    Model answer

    IoU measures overlap between predicted and ground truth boxes; it is used to assign a predicted box to an object (the one with highest IoU) and also in loss computation.

    Explanation

    IoU is a standard metric for object detection evaluation.

  36. 36

    What is Non-Max Suppression (NMS) and why is it needed?

    Model answer

    NMS eliminates duplicate detections by discarding boxes with high IoU overlap with a higher-confidence box, keeping only the best one per object.

    Explanation

    Without NMS, the model would output multiple overlapping boxes for the same object.

  37. 37

    What is the reparameterization trick in Variational Autoencoders (VAEs)?

    Model answer

    It expresses the latent variable zzz as z=mu+sigmaodotepsilonz = mu + sigma odot epsilonz=mu+sigmaodotepsilon, where epsilonepsilonepsilon is random noise, allowing backpropagation through the sampling process.

    Explanation

    This makes the VAE trainable via gradient descent while maintaining stochasticity.

  38. 38

    What are the two components of the VAE loss?

    Model answer

    The VAE loss consists of a reconstruction loss (e.g., binary cross-entropy) and a KL divergence loss that regularizes the latent distribution to a standard normal.

    Explanation

    The KL divergence term encourages the learned distribution to be close to a prior (usually standard normal).

  39. 39

    In a Generative Adversarial Network (GAN), what do the generator and discriminator do?

    Model answer

    The generator creates fake samples to fool the discriminator, while the discriminator tries to distinguish real from fake samples. They compete in a min-max game.

    Explanation

    This adversarial training leads to the generator producing increasingly realistic data.

  40. 40

    List two tips for stable GAN training mentioned in the course.

    Model answer

    Use label smoothing (e.g., replace real labels 1 with 0.9) and flip generator labels from 0 to 1 to improve training dynamics.

    Explanation

    Other tips include using Adam optimizer and leaky ReLU activations.

1 of 40
Question 1 of 40

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent