Learn Before
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., ) and processed in batches (e.g., ). The model parameters are optimized using a specific learning rate (e.g., ) over multiple epochs (e.g., ). 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)
0
1
Updated 2026-05-13
Tags
D2L
Dive into Deep Learning @ D2L