A developer wants a quick printed overview of every layer in a Keras model, including each layer's output shape and how many trainable parameters it contributes. Which method provides this?
Select an answer to reveal the explanation.
Short Explanation and Infographic
When you just want a quick sanity check on your architecture — what layers exist, in what order, what shape comes out of each one, and how many parameters each layer is contributing — model.summary() is your tool. Call it after building the model and Keras prints a clean table: layer name, output shape, param count, plus totals for trainable and non-trainable parameters at the bottom. That's exactly what's being asked for, so 'model.summary()' is correct. compile() just configures the optimizer, loss, and metrics — it doesn't print anything about layers. predict() runs inference to get outputs on new data, nothing to do with inspecting architecture. And save() writes the model to disk; it doesn't display anything to you at all.
Full explanation below image
Full Explanation
model.summary() is the Keras method specifically designed to print a concise, structured overview of a model's architecture. When called on a built (and typically compiled or at least fully defined) model, it outputs a table listing each layer in order, that layer's type and name, its output shape, and the number of parameters (weights and biases) it contributes. At the bottom, it also reports totals for the overall number of parameters, broken down into trainable parameters (those updated during training via backpropagation) and non-trainable parameters (such as frozen layers or certain normalization statistics). This is extremely useful for sanity-checking that an architecture is wired together as intended — for example, verifying that output shapes flow correctly from one layer to the next, or confirming that freezing certain layers during fine-tuning actually reduced the trainable parameter count as expected.
model.compile() is used earlier in the workflow to configure the model for training by specifying the optimizer (such as Adam or SGD), the loss function, and any metrics to track. It does not print or return any information about layer shapes or parameter counts; it purely sets up the training configuration and must be called before fit() can be used.
model.predict() runs the model in inference mode on provided input data and returns the corresponding output predictions. It performs only forward passes, does not train the model, and has no role in summarizing or displaying the model's internal architecture.
model.save() persists the model — its architecture, weights, and optionally the optimizer state — to a file or directory on disk so it can be reloaded later. It does not print any summary information to the console; its purpose is storage and later retrieval of the model, not inspection of its structure during development.
In typical practice, developers call model.summary() right after defining a model's layers (and often again after compiling) as a quick, low-cost verification step before committing to a potentially long and expensive training run, catching shape mismatches or unexpectedly large parameter counts early.