Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:NVIDIA DALI Paddle ResNet Model

From Leeroopedia


Knowledge Sources
Domains Vision, Training
Last Updated 2026-02-08 16:00 GMT

Overview

Implements a ResNet-50 v1.5 model architecture using the PaddlePaddle deep learning framework.

Description

This module defines the ResNet-50 model for image classification using PaddlePaddle's nn.Layer API. The implementation follows the standard bottleneck architecture with three core building blocks: ConvBNLayer (convolution + batch normalization + optional ReLU activation), BottleneckBlock (the classic 1x1 -> 3x3 -> 1x1 bottleneck with residual shortcut), and the top-level ResNet class that stacks these blocks into four stages with depths [3, 4, 6, 3].

The model supports configurable data formats (NCHW or NHWC), optional pure FP16 training via PaddlePaddle's AMP guard, and configurable batch normalization weight decay. The stem uses a single 7x7 convolution with stride 2 followed by max pooling, and the classifier head uses adaptive average pooling followed by a fully connected layer. Weights are initialized using Kaiming Normal for convolutional layers and Uniform initialization for the final FC layer.

A convenience factory function ResNet50(**kwargs) is provided to instantiate the model with the default configuration targeting 1000-class ImageNet classification.

Usage

Use this module as the model component in the PaddlePaddle ResNet-50 training pipeline that integrates with NVIDIA DALI for accelerated data loading. It is instantiated by the program.py build function and should be used together with the DALI PaddlePaddle plugin for high-throughput training.

Code Reference

Source Location

Signature

class ConvBNLayer(nn.Layer):
    def __init__(self, num_channels, num_filters, filter_size, stride=1,
                 groups=1, act=None, lr_mult=1.0, data_format="NCHW",
                 bn_weight_decay=True): ...

class BottleneckBlock(nn.Layer):
    def __init__(self, num_channels, num_filters, stride, shortcut=True,
                 lr_mult=1.0, data_format="NCHW", bn_weight_decay=True): ...

class ResNet(nn.Layer):
    def __init__(self, class_num=1000, data_format="NCHW",
                 input_image_channel=3, use_pure_fp16=False,
                 bn_weight_decay=True): ...

def ResNet50(**kwargs): ...

Import

from models.resnet import ResNet50

I/O Contract

Inputs

Name Type Required Description
x paddle.Tensor Yes Input image tensor of shape [N, C, H, W] (NCHW) or [N, H, W, C] (NHWC), typically [N, 3, 224, 224].
class_num int No Number of output classes. Default: 1000.
data_format str No Data layout, either "NCHW" or "NHWC". Default: "NCHW".
input_image_channel int No Number of input image channels. Default: 3.
use_pure_fp16 bool No Whether to use pure FP16 training with AMP guard. Default: False.
bn_weight_decay bool No Whether to apply weight decay to batch normalization parameters. Default: True.

Outputs

Name Type Description
logits paddle.Tensor Classification logits of shape [N, class_num]. Not softmaxed.

Usage Examples

Creating a ResNet-50 model

from models.resnet import ResNet50

# Create model for 1000-class ImageNet classification
model = ResNet50(class_num=1000, data_format="NCHW")

# Forward pass
import paddle
x = paddle.randn([8, 3, 224, 224])
logits = model(x)
print(logits.shape)  # [8, 1000]

Using with FP16 training

from models.resnet import ResNet50

model = ResNet50(
    class_num=1000,
    data_format="NHWC",
    use_pure_fp16=True,
    bn_weight_decay=False
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment