With modified architecture and initialization this ResNet50 version gives ~0.5% better accuracy than original.
1. Clone the repository.
git clone https://github.com/NVIDIA/DeepLearningExamples.git
cd DeepLearningExamples/PaddlePaddle/Classification/RN50v1.5
2. Download and preprocess the dataset.
The ResNet50 script operates on ImageNet 1k, a widely popular image classification dataset from the ILSVRC challenge.
Paddle can work directly on JPEGs; therefore, preprocessing/augmentation is not needed.
To train your model using mixed or TF32 precision with Tensor Cores or using FP32, perform the following steps using the default parameters of the resnet50 model on the ImageNet dataset. For the specifics concerning training and inference, refer to the Advanced section.
-
Extract the training data:
cd <path to imagenet>
mkdir train && mv ILSVRC2012_img_train.tar train/ && cd train
tar -xvf ILSVRC2012_img_train.tar && rm -f ILSVRC2012_img_train.tar
find . -name "*.tar" | while read NAME ; do mkdir -p "${NAME%.tar}"; tar -xvf "${NAME}" -C "${NAME%.tar}"; rm -f "${NAME}"; done
cd ..
- Extract the validation data and move the images to subfolders:
mkdir val && mv ILSVRC2012_img_val.tar val/ && cd val && tar -xvf ILSVRC2012_img_val.tar
wget -qO- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh | bash
The directory in which the train/ and val/ directories are placed is referred to as <path to imagenet> in this document.
3. Build the ResNet50 PaddlePaddle NGC container.
docker build . -t nvidia_resnet50
4. Start an interactive session in the NGC container to run training/inference.
nvidia-docker run --rm -it -v <path to imagenet>:/imagenet --ipc=host nvidia_resnet50
5. Start training
To run training for a standard configuration (DGXA100, AMP/TF32),
use one of scripts in scripts/training to launch training. (Please ensure ImageNet is mounted in the /imagenet directory.)
Example:
# For TF32 and 8 GPUs training in 90 epochs
bash scripts/training/train_resnet50_TF32_90E_DGXA100.sh
# For AMP and 8 GPUs training in 90 epochs
bash scripts/training/train_resnet50_TF32_90E_DGXA100.sh
Or you can manually launch training by paddle.distributed.launch. paddle.distributed.launch is a built-in module in PaddlePaddle that spawns up multiple distributed training processes on each of the training nodes.
Example:
# For single GPU training with AMP
python -m paddle.distributed.launch --gpus=0 train.py \
--epochs 90 \
--amp \
--scale-loss 128.0 \
--use-dynamic-loss-scaling \
--data-layout NHWC
# For 8 GPUs training with AMP
python -m paddle.distributed.launch --gpus=0,1,2,3,4,5,6,7 train.py \
--epochs 90 \
--amp \
--scale-loss 128.0 \
--use-dynamic-loss-scaling \
--data-layout NHWC
Note that for initializing training with checkpoints or pretrained parameters, refer to Training process for more details.
6. Start validation/evaluation.
To evaluate the validation dataset located in /imagenet/val, you need to specify the pretrained weights by --from-pretrained-params and set eval_only to --run-scope.
You can download pretrained weights from NGC:
wget --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/dle/resnet_50_paddle_ckpt/versions/22.05.0_amp/zip -O resnet_50_paddle_ckpt_22.05.0_amp.zip
unzip -d <path_to_downloaded_ckpt> resnet_50_paddle_ckpt_22.05.0_amp.zip
This checkpoint is well pretrained on the ImageNet dataset with AMP mode. It achieves 77.11% top 1 accuracy on the test dataset.
Example:
- TF32
# For single GPU evaluation
python -m paddle.distributed.launch --gpus=0 train.py \
--from-pretrained-params <path_to_downloaded_ckpt> \
--run-scope eval_only
# For 8 GPUs evaluation
python -m paddle.distributed.launch --gpus=0,1,2,3,4,5,6,7 train.py \
--from-pretrained-params <path_to_downloaded_ckpt> \
--run-scope eval_only
- AMP
# For single GPU evaluation
python -m paddle.distributed.launch --gpus=0 train.py \
--from-pretrained-params <path_to_downloaded_ckpt> \
--run-scope eval_only \
--amp \
--data-layout NHWC
# For 8 GPUs evaluation
python -m paddle.distributed.launch --gpus=0,1,2,3,4,5,6,7 train.py \
--from-pretrained-params <path_to_downloaded_ckpt> \
--run-scope eval_only \
--amp \
--data-layout NHWC
We also provide scripts to inference with TensorRT that could reach better performance. Refer to Inference process in Advanced for more details.