Code

NiN Model Training Code Implementation

To train a Network in Network (NiN) model, practitioners typically apply the same optimization strategies and datasets used for architectures like AlexNet and VGG. For instance, when training on the Fashion-MNIST dataset, the input images are resized to the required resolution (e.g., 224×224224 \times 224) and processed in batches (e.g., 128128). The model parameters are optimized using a specific learning rate (e.g., 0.050.05) over multiple epochs (e.g., 1010). Modern deep learning frameworks provide high-level APIs to facilitate this training loop efficiently.

# PyTorch Implementation model = NiN(lr=0.05) trainer = d2l.Trainer(max_epochs=10, num_gpus=1) data = d2l.FashionMNIST(batch_size=128, resize=(224, 224)) model.apply_init([next(iter(data.get_dataloader(True)))[0]], d2l.init_cnn) trainer.fit(model, data)
# MXNet Implementation model = NiN(lr=0.05) trainer = d2l.Trainer(max_epochs=10, num_gpus=1) data = d2l.FashionMNIST(batch_size=128, resize=(224, 224)) trainer.fit(model, data)
# JAX Implementation model = NiN(lr=0.05) trainer = d2l.Trainer(max_epochs=10, num_gpus=1) data = d2l.FashionMNIST(batch_size=128, resize=(224, 224)) trainer.fit(model, data)
# TensorFlow Implementation trainer = d2l.Trainer(max_epochs=10) data = d2l.FashionMNIST(batch_size=128, resize=(224, 224)) with d2l.try_gpu(): model = NiN(lr=0.05) trainer.fit(model, data)
Image 0

0

1

Updated 2026-05-13

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L