ImageNet Training in PyTorch#

This implements training of popular model architectures, such as ResNet, AlexNet, and VGG on the ImageNet dataset.

This version has been modified to use DALI. It assumes that the dataset is raw JPEGs from the ImageNet dataset. If offers CPU and GPU based pipeline for DALI - use dali_cpu switch to enable CPU one. For heavy GPU networks (like RN50) CPU based one is faster, for some lighter where CPU is the bottleneck like RN18 GPU is. This version has been modified to use the DistributedDataParallel module in APEx instead of the one in upstream PyTorch. Please install APEx from here.

To run use the following commands

ln -s /path/to/train/jpeg/ train
ln -s /path/to/validation/jpeg/ val
torchrun --nproc_per_node=NUM_GPUS main.py -a resnet50 --dali_cpu --b 128 \
         --loss-scale 128.0 --workers 4 --lr=0.4 --fp16-mode ./

Requirements#

  • APEx - optional (form PyTorch 1.6 it is part of the upstream so there is no need to install it separately), required for fp16 mode or distributed (multi-GPU) operation

  • Install PyTorch from source, main branch of PyTorch on github

  • pip install -r requirements.txt

  • Download the ImageNet dataset and move validation images to labeled subfolders

    • To do this, you can use the following script

Training#

To train a model, run docs/examples/use_cases/pytorch/resnet50/main.py with the desired model architecture and the path to the ImageNet dataset:

python main.py -a resnet18 [imagenet-folder with train and val folders]

The default learning rate schedule starts at 0.1 and decays by a factor of 10 every 30 epochs. This is appropriate for ResNet and models with batch normalization, but too high for AlexNet and VGG. Use 0.01 as the initial learning rate for AlexNet or VGG:

python main.py -a alexnet --lr 0.01 [imagenet-folder with train and val folders]

Data loaders#

  • dali: Leverages a DALI pipeline along with DALI’s PyTorch iterator for data loading, preprocessing, and augmentation.

  • dali_proxy: Uses a DALI pipeline for preprocessing and augmentation while relying on PyTorch’s data loader. DALI Proxy facilitates the transfer of data to DALI for processing. See PyTorch DALI Proxy.

  • pytorch: Employs the native PyTorch data loader for data preprocessing and augmentation.

Usage#