1. Home
  2. Explore
  3. Computer Science
  4. Deep Learning with Keras

Study methods

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

Deep Learning with Keras

  • 97Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Keras Foundations
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is Keras, and how is it related to TensorFlow?

Tap to flipClick to flipspace

Keras is a high-level neural network API integrated with TensorFlow.

Or swipe the card

97 cards

  1. What is Keras, and how is it related to TensorFlow?

    Keras is a high-level neural network API integrated with TensorFlow.

  2. What did Keras use as backends historically, and how is its relationship with TensorFlow different now?

    Historically, Keras could run on TensorFlow, Theano, or CNTK. It is now integrated with TensorFlow rather than being a separate library configured to use one of those backends.

  3. What design goal does Keras emphasize?

    Fast user experimentation: moving from an idea to an implementation in few steps.

  4. Why is it useful to learn more than one neural network API?

    Once you understand the underlying concepts, syntax differences are easier to learn. Knowing multiple APIs also helps you compare their strengths and explain which may suit different problems.

  5. How can TensorFlow and its integrated Keras API be installed using pip?

    Run pip install tensorflow from the command line, after checking that the system meets TensorFlow’s requirements.

  6. Is a GPU required to use the models and code described in the content?

    No. The code can run on a CPU; a GPU is optional and can be set up for TensorFlow separately.

  7. What is the role of GPU memory growth when configuring TensorFlow?

    It is an optional GPU setting used when configuring TensorFlow’s GPU use; the content recommends it in the GPU setup code but does not require a GPU for the work.

  8. What basic coding background is sufficient to follow the Keras examples?

    Basic programming skills and some experience with Python.

  9. In supervised learning, what are samples and labels?

    Samples are the individual data points used as inputs; labels are the corresponding target answers for those data points.

  10. What alternative terms may be used for samples and labels in deep learning?

    Samples may be called inputs or input data; labels may be called targets or target data.

  11. What labels could correspond to headlines used for sentiment analysis?

    Labels could indicate positive or negative sentiment.

  12. What labels could correspond to images in a cat-versus-dog classifier?

    Each image could have a cat or dog label.

  13. What formats can Keras fit accept for its input data, according to the content?

    A NumPy array, TensorFlow tensor, dictionary or mapping, tf.data.Dataset, or Keras generator.

  14. What formats can Keras fit accept for target data, and how must its format relate to the input format?

    The target data can use the same listed formats, but its format must match the input data’s format.

  15. Why might data be normalized or standardized before training?

    Changing the data’s scale or representation can make it easier or more efficient for a model to learn.

  16. What was the age range in the imagined clinical-trial data example?

    Participants ranged from 13 to 100 years old, with the groups divided into under 65 and 65 or older.

  17. What relationship between age group and side effects was assumed in the trial example?

    About 95% of participants aged 65 or older experienced side effects, while about 95% of those under 65 experienced no side effects.

  18. How were side-effect outcomes encoded in the numerical example?

    A label of 1 represented experiencing side effects; a label of 0 represented experiencing no side effects.

  19. What did the samples and labels lists contain in the numerical example?

    The samples list contained participant ages; the corresponding labels list contained 0s and 1s for no side effects or side effects.

  20. Why were the sample and label lists shuffled together after being converted to NumPy arrays?

    To remove any order introduced during data generation while keeping each sample matched with its correct label.

  21. What did min-max scaling do to the age data in the example?

    It rescaled ages from their original range of 13–100 to a range between 0 and 1.

  22. Why did the example reshape the one-dimensional age data before applying the scaler?

    The fit_transform function did not accept one-dimensional data by default, so the data was reshaped to a compatible form.

  23. What is a Keras Sequential model?

    A model that represents a linear stack of layers.

  24. How does a Sequential model learn the expected input shape in the example?

    The input data provides the input layer, and the first hidden layer’s input_shape parameter tells the model what input shape to expect.

  25. What architecture was used for the numerical-data Sequential model?

    Two hidden dense layers with 16 and 32 units, followed by a two-unit output layer; the hidden layers used ReLU and the output used softmax.

  26. What does a dense layer mean in the neural-network examples?

    A densely connected, or fully connected, layer.

  27. What does model.compile do before training?

    It prepares the model for training by configuring items such as the optimizer, loss function, and metrics.

  28. Which optimizer and learning rate were used in the numerical-data training example?

    Adam with a learning rate of 0.00010.00010.0001.

  29. Which loss and metric were used to train the numerical-data classifier?

    Sparse categorical cross-entropy was the loss, and accuracy was the metric.

  30. What does the batch-size parameter control during training?

    It specifies how many samples are processed by the network at one time in a batch.

  31. What does an epoch represent during model training?

    One pass of training over all the data in the dataset.

  32. What did the numerical-data example’s settings of batch size 10 and 30 epochs mean?

    The model processed 10 samples per batch and trained over the full dataset 30 times.

  33. Why is shuffling training data useful?

    It removes ordering in the dataset that the model should not learn as a meaningful pattern.

  34. What does the verbose setting control during fitting?

    How much output the fitting process displays; the example notes that 2 is the most verbose of the shown settings.

  35. What is a validation set used for during training?

    It measures how well the model predicts on held-out data, providing evidence about how well it generalizes beyond the training data.

  36. Does a model train on the validation set when validation is used?

    No. The model trains on the training data and evaluates on the validation data after each epoch; validation data does not update the model during training.

  37. What is overfitting, and what pattern in training and validation results can indicate it?

    Overfitting occurs when a model learns the training data’s features well but does not generalize to unseen data. Strong training results alongside substantially worse validation results can indicate it.

  38. What does Keras’s validation_split parameter do, and what ordering caveat applies?

    It holds out a chosen fraction of the training data as validation data. The split is made before fit shuffles the remaining training data, so ordered data should be shuffled beforehand to avoid a biased validation subset.

  39. How can validation data be supplied without using validation_split?

    Create a separate validation set and pass it to fit using the validation_data parameter.

  40. What is inference in the context of a trained neural network?

    Using what the model learned during training to make predictions on data it has not seen before.

  41. Why might a test set be used after training and validation?

    To assess the trained model’s predictions on held-out data as an additional check of generalization before deployment.

  42. How does a confusion matrix help evaluate predictions when test labels are available?

    It compares predicted labels with true labels; correct predictions lie on the main diagonal, and off-diagonal values show errors between classes.

  43. In the confusion-matrix plots described, which axis shows predicted labels and which shows true labels?

    Predicted labels are on the x-axis and true labels are on the y-axis.

  44. What was the numerical model’s approximate accuracy after 30 epochs?

    About 94% accuracy, with loss decreasing during training.

  45. What did similar training and validation results suggest about the numerical model?

    They suggested that the model was generalizing well rather than substantially overfitting.

  46. What does Keras model saving with model.save preserve?

    The model architecture, weights, training configuration such as loss and optimizer, and optimizer state.

  47. Why can saving the optimizer state be useful when a model is saved during training?

    After loading the saved model, training can continue from where it left off because the optimizer state was preserved.

  48. How is a model previously saved with model.save loaded?

    Use Keras’s load_model function and provide the path to the saved model.

  49. What does saving a model with model.to_json preserve?

    The model architecture, but not its weights or training configuration.

  50. What must be done before training a model reconstructed from a saved architecture alone?

    Compile it and train it, since the architecture alone does not include learned weights or the training configuration.

  51. How can model architecture be saved and loaded using YAML rather than JSON?

    Use model.to_yaml to produce a YAML string and model_from_yaml to reconstruct the model.

  52. What is the key requirement when loading saved weights into another model?

    The new model must have a compatible architecture so the saved weights can map to its layers.

  53. What does save_weights preserve, and what is needed to use those weights later?

    It saves only the model’s weights. To load them later, first create a model with a compatible architecture, then load the weights into it.

  54. How many images were used from the cat-and-dog dataset in the described subset, and how were they divided?

    There were 1,000 training images, 200 validation images, and 100 test images, with each set split evenly between cats and dogs.

  55. How were the cat-and-dog images organized for training?

    Into train, validation, and test directories, each containing separate cat and dog directories.

  56. What did an image data generator’s flow_from_directory provide for the image-model workflow?

    Batches of images and their labels from organized directories, ready to be passed to a Sequential model’s fit function.

  57. What image dimensions and batch size were used for the cat-and-dog directory iterators?

    Images were resized to 224×224224 \times 224224×224 pixels, and the batch size was 10.

  58. Why was shuffling disabled for the test image iterator?

    To preserve the correspondence between test images and their labels so predictions could be compared with the correct labels in a confusion matrix.

  59. What label format did the cat-and-dog image generator produce?

    One-hot vectors: [1,0][1, 0][1,0] for cat and [0,1][0, 1][0,1] for dog.

  60. Why did the image-model training call not need a separate y argument when using a generator?

    The generator already contained the labels corresponding to its images.

  61. What layers made up the from-scratch convolutional model described?

    A convolutional layer with 32 filters, a max-pooling layer, a convolutional layer with 64 filters, another max-pooling layer, a flattening step, and a two-unit dense output layer.

  62. What kernel size and activation function were used for the described convolutional layers?

    A 3×33 \times 33×3 kernel and ReLU activation.

  63. What did padding="same" accomplish in the described convolutional layers?

    It used zero padding so convolution operations did not reduce the image dimensions.

  64. What effect did the described 2×22 \times 22×2 max-pooling layers with stride 2 have on image dimensions?

    They reduced the image dimensions by half.

  65. Why was the CNN’s final layer followed by softmax?

    To produce a probability for each of the two output classes, cat and dog.

  66. How could the two-class CNN instead be configured with binary cross-entropy?

    Use one output unit with a sigmoid activation and binary cross-entropy loss; this is an alternative to two outputs with softmax and categorical cross-entropy.

  67. How did the from-scratch CNN’s training and validation results compare?

    It reached 100% training accuracy but only about 69–70% validation accuracy, indicating overfitting.

  68. What image preprocessing was used for images passed to VGG16?

    The mean RGB value computed over the training set was subtracted from each corresponding pixel channel.

  69. Why must new images be processed in the same way as a pretrained model’s original training images?

    The model expects input data to be represented consistently with the preprocessing used during its original training.

  70. What was VGG16 originally trained to classify, and what change was made for the cat-and-dog task?

    It was trained on 1,000 ImageNet classes. Its original output layer was replaced with a two-class output for cats and dogs.

  71. What does fine-tuning mean in the described VGG16 example?

    Adapting the pretrained model for a new classification setup by changing its output layer and training the new output for the target classes.

  72. Why could VGG16 be adapted to cats and dogs with relatively little fine-tuning in the example?

    Cats and dogs were already included in the ImageNet data on which VGG16 was trained.

  73. What was done to VGG16’s existing layers during the described fine-tuning setup?

    Their weights were frozen so they would not be retrained; the new output layer was trainable.

  74. Approximately how large was VGG16, and how many total parameters did it have in the example?

    About 553 MB on disk and approximately 138 million parameters.

  75. How many parameters were trainable in the modified VGG16 model described?

    About 8,000, all in its new output layer.

  76. What results did the fine-tuned VGG16 model achieve on the cat-and-dog data?

    About 99% training accuracy, 98% validation accuracy after five epochs, and 96% test accuracy.

  77. What are MobileNets designed to offer compared with larger CNN models?

    Small, low-power, low-latency models suited to tasks such as classification and detection, including use on mobile devices.

  78. What size and parameter-count comparison was given between a large MobileNet and VGG16?

    The compared MobileNet was about 17 MB with 4.2 million parameters, versus VGG16 at about 553 MB with 138 million parameters.

  79. What trade-off may come with using a smaller MobileNet instead of a larger model such as VGG16?

    MobileNets can be faster and use less memory, but may have somewhat lower accuracy.

  80. How does the MobileNet preprocessing described scale RGB pixel values?

    It scales them from the range 0–255 to the range −1-1−1 to 111.

  81. What did MobileNet’s decode_predictions output for an ImageNet prediction?

    The top five predicted ImageNet classes and their probabilities, ordered by probability.

  82. What was the custom sign-language dataset, and how many classes did it contain?

    An RGB image dataset of hand signs for digits 0 through 9, giving 10 classes.

  83. How were the sign-language images organized on disk for the model workflow?

    Into train, validation, and test directories, with a separate class directory for each digit from 0 to 9.

  84. How many sign-language samples were placed in validation and test for each class?

    Thirty images per class in validation and five per class in the test set.

  85. Approximately how many training images were used for the sign-language dataset?

    About 1,712 images across the 10 classes; the class directories originally contained roughly 204–208 images each, before validation and test samples were moved out.

  86. How was the output layer of MobileNet adapted to the 10 sign-language classes?

    A dense layer with 10 units and a softmax activation was added as the output.

  87. Which MobileNet layers were retained in the described custom fine-tuning model?

    The layers from the original model up to and including the sixth-to-last layer; the last five layers were excluded.

  88. How many of the custom fine-tuning model’s 88 layers were left trainable in the described setup?

    The last 23 layers were left trainable; the choice was based on experimentation rather than a universal rule.

  89. What sign-language model configuration was used for training?

    Adam with a learning rate of 0.00010.00010.0001, categorical cross-entropy loss, accuracy as the metric, training batches and validation batches, and 30 epochs.

  90. What results did the fine-tuned MobileNet achieve on the sign-language dataset?

    About 100% training accuracy, 92% validation accuracy, and 90% test accuracy.

  91. What do the sign-language model’s training and validation results suggest?

    The model learned the training data very well, while the lower validation accuracy indicates some overfitting.

  92. What is image data augmentation?

    Creating modified versions of existing image data, such as rotated, shifted, zoomed, recolored, or flipped images.

  93. Why might data augmentation help when training an image model?

    It can increase the variety and amount of training data, which may help reduce overfitting when the original dataset is small.

  94. What kinds of image modifications were available in the described Keras image data generator?

    Rotation, width and height shifts, shearing, zooming, channel shifts, and horizontal flips.

  95. How can augmented versions of an image be generated from one source image?

    Configure an image data generator with augmentation settings, pass the image through its flow function, and retrieve generated image batches.

  96. How can horizontal-flip augmentation make a dog-image dataset more varied?

    It can add images with dogs facing the opposite direction, helping the dataset cover both left- and right-facing examples.

  97. Do all augmentation parameters necessarily use the same units?

    No. Their units differ; for example, rotation range and image-shift ranges are expressed differently, so the generator documentation should be checked for each parameter.

Card 1 of 97
Card 1 of 97

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent