Learn Before
Code

AnyNet Stem Code Implementation

The stem of the AnyNet model can be implemented as a sequential block containing a 3×33 \times 3 convolution with a stride of 22 and padding, followed by batch normalization and a ReLU activation function. This sequence halves the input resolution and generates the initial channels.

PyTorch Implementation:

class AnyNet(d2l.Classifier): def stem(self, num_channels): return nn.Sequential( nn.LazyConv2d(num_channels, kernel_size=3, stride=2, padding=1), nn.LazyBatchNorm2d(), nn.ReLU())

MXNet Implementation:

class AnyNet(d2l.Classifier): def stem(self, num_channels): net = nn.Sequential() net.add(nn.Conv2D(num_channels, kernel_size=3, padding=1, strides=2), nn.BatchNorm(), nn.Activation('relu')) return net

JAX Implementation:

class AnyNet(d2l.Classifier): arch: tuple stem_channels: int lr: float = 0.1 num_classes: int = 10 training: bool = True def setup(self): self.net = self.create_net() def stem(self, num_channels): return nn.Sequential([ nn.Conv(num_channels, kernel_size=(3, 3), strides=(2, 2), padding=(1, 1)), nn.BatchNorm(not self.training), nn.relu ])

TensorFlow Implementation:

class AnyNet(d2l.Classifier): def stem(self, num_channels): return tf.keras.models.Sequential([ tf.keras.layers.Conv2D(num_channels, kernel_size=3, strides=2, padding='same'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Activation('relu')])

0

1

Updated 2026-05-13

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L