While fine-tuning a pretrained Keras model, an engineer wants to keep the weights of the early convolutional layers fixed so only the new top layers learn. Which property accomplishes this on a per-layer basis?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal: in Keras, every layer has a trainable attribute, and setting layer.trainable = False tells the framework 'don't touch these weights during backprop.' That's exactly what you want when fine-tuning — you freeze the early layers that already learned good general features, and let only the new top layers adapt to your specific task. That's your answer. layer.frozen isn't a real Keras attribute, it's a made-up name that sounds plausible but doesn't exist. model.compile(freeze=True) is also fabricated — compile() configures the optimizer, loss, and metrics, not per-layer freezing. And requires_grad = False is the PyTorch way of freezing a parameter, not Keras — mixing frameworks like that is a common slip-up on exams, so keep your Keras and PyTorch vocabulary separate in your head.
Full explanation below image
Full Explanation
In Keras (and TensorFlow's tf.keras), every layer object exposes a boolean trainable attribute. Setting layer.trainable = False excludes that layer's weights from being updated during training: its parameters are still used in the forward pass, but no gradients are applied to them during backpropagation, and they are omitted from the list of trainable variables the optimizer touches. This is the standard mechanism for freezing layers in transfer learning and fine-tuning workflows — commonly, you load a pretrained base model, set trainable = False on its layers (or on the whole base model object), add new task-specific layers on top, and train only those new layers before optionally unfreezing some base layers for a later fine-tuning pass at a lower learning rate.
layer.frozen = True is not a real Keras API; there is no 'frozen' attribute on Keras layers. This distractor could mislead someone reasoning from the English word 'freeze' rather than the actual framework API.
model.compile(freeze=True) is also fabricated. The compile() method configures the optimizer, loss function, and metrics for the model as a whole — it has no freeze parameter and does not operate at the individual layer level at all.
layer.requires_grad = False describes PyTorch's mechanism for freezing a parameter or tensor (setting requires_grad to False on a parameter excludes it from gradient computation), but this attribute does not exist in Keras/TensorFlow. Confusing the two frameworks' APIs is a common but avoidable mistake.
As a memory aid: Keras uses trainable (a layer- or model-level boolean), while PyTorch uses requires_grad (a tensor/parameter-level boolean) for the same conceptual purpose — controlling whether gradients update given weights during training.