Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

applications.ResNet50

ResNet50 builds the 50-layer ResNet image model as a Keras model. It supports ImageNet or custom weights, optional classification layers, global pooling, and configurable input settings.

How it works

ResNet50 constructs the 50-layer ResNet architecture as a Keras model. It can load ImageNet weights, optionally remove the classification head, apply global pooling to convolutional features, and use a custom input tensor or shape.

Syntax

keras.applications.ResNet50(include_top=True, weights="imagenet", input_tensor=None, input_shape=None, pooling=None, classes=1000, classifier_activation="softmax", name="resnet50")

Parameters

NameTypeDescription
include_topbooleanWhether to include the fully connected classification layer.
weightsstring or NoneWeight initialization: None, "imagenet", or a compatible weights-file path.
input_tensortensor or NoneOptional tensor to use as the model input.
input_shapetuple or NoneOptional input shape for the model.
poolingstring or NoneOptional global pooling mode when the top is omitted; typically "avg" or "max".
classesintegerNumber of output classes when the top is included.
classifier_activationstring, callable, or NoneActivation for the top classifier, such as "softmax"; None returns logits.
namestringModel name.

Returns

A Keras model instance.

Key points

  • Calling ResNet50 returns a Keras model implementing the 50-layer residual network.
  • include_top controls whether the ImageNet classification head is attached.
  • weights can select ImageNet initialization, random initialization with None, or a local weights file.
  • The ResNet preprocessing helper converts channel order and centers channels for the expected input representation.
  • Selecting pretrained weights may trigger an automatic download during model construction.
  • The applications catalog reports ResNet50 at 98 MB, 25.6 million parameters, and 107 layers, with ImageNet top-1 and top-5 accuracy of 74.9% and 92.1%.

Common mistakes

  • Preprocess inputs with the ResNet-specific helper before inference or feature extraction.
  • Set classifier_activation to None when the unnormalized classifier logits are required.

Example: Extract ResNet50 features

import keras
import numpy as np

model = keras.applications.ResNet50(
    weights="imagenet",
    include_top=False,
    pooling="avg",
)
images = np.random.random((2, 224, 224, 3)).astype("float32")
images = keras.applications.resnet.preprocess_input(images)
features = model.predict(images, verbose=0)
print(features.shape)

Builds an ImageNet-initialized ResNet50 without its classifier and produces one pooled feature vector per image.

When to use it

Classify images with the pretrained ImageNet head.

Image classification

Remove the original classifier and attach a task-specific head.

Transfer learning

Use pooled convolutional representations as input to another model.

Feature extraction

Interview questions

QWhat does ResNet50 create by default?

ResNet50 instantiates the ResNet50 architecture and returns a Keras model. By default it includes the top classifier, uses ImageNet weights, and produces 1,000-class predictions.

Follow-up: How would you adapt it for transfer learning? Use include_top=False, choose an appropriate input shape, and add a task-specific head.

QHow do you use ResNet50 as a feature extractor?

Set include_top=False to omit the fully connected classifier. The resulting convolutional network can be used for feature extraction or as a backbone.

Follow-up: How can spatial features become a fixed-size vector? Set pooling to "avg" or "max" after removing the top.

QHow are weights selected and inputs prepared?

The weights argument accepts None for random initialization, "imagenet" for pretrained ImageNet weights, or a path to compatible weights. When using pretrained ResNet weights, preprocess inputs with keras.applications.resnet.preprocess_input.

Follow-up: What must be true when supplying custom weights? The weights must be compatible with the selected architecture and model configuration.

  • keras.applications.resnet.preprocess_input
  • keras.applications.resnet.decode_predictions
  • keras.applications.ResNet101
  • keras.applications.ResNet152

Source: Keras documentation: ResNet models. Checked 2026-10-15.