使用 timm
在 imagenet 上进行模型训练真的非常容易!
例如,让我们在 imagenette 上训练一个 resnet34
模型。我们将要进行以下步骤:
- 获取
imagenette
数据 - 使用
timm
开始训练
注意:在 CPU 上运行训练会非常慢!建议使用 GPU(s) - 越多越好 :)
!wget https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-320.tgz
!gunzip imagenette2-320.tgz
!tar -xvf imagenette2-320.tar
要触发训练,
python train.py /imagenette2-320 --model resnet34
以下是 Ross 用于获得具有竞争力的结果的训练脚本列表!
带 RandAugment 的 EfficientNet-B2 - 80.4 top-1, 95.1 top-5
这些参数适用于安装了 NVIDIA Apex 的双路 Titan RTX 显卡
./distributed_train.sh 2 /imagenet/ --model efficientnet_b2 -b 128 --sched step --epochs 450 --decay-epochs 2.4 --decay-rate .97 --opt rmsproptf --opt-eps .001 -j 8 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.3 --drop-connect 0.2 --model-ema --model-ema-decay 0.9999 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.2 --amp --lr .016
带 RandAugment 的 MixNet-XL - 80.5 top-1, 94.9 top-5
这些参数适用于安装了 NVIDIA Apex 的双路 Titan RTX 显卡
./distributed_train.sh 2 /imagenet/ --model mixnet_xl -b 128 --sched step --epochs 450 --decay-epochs 2.4 --decay-rate .969 --opt rmsproptf --opt-eps .001 -j 8 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.3 --drop-connect 0.2 --model-ema --model-ema-decay 0.9999 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.3 --amp --lr .016 --dist-bn reduce
SE-ResNeXt-26-D 和 SE-ResNeXt-26-T
这些超参数(或类似的)适用于各种 ResNet 架构,通常随着模型尺寸的增加,增加 epoch 数量是个好主意... 例如 ResNe(X)t50 大约 180-200 个 epoch,更大的模型则需要 220+ 个 epoch。对于更好的 GPU 或启用 AMP 的情况,按比例增加批量大小和学习率。这些参数是针对 2 块 1080Ti 显卡的。
./distributed_train.sh 2 /imagenet/ --model seresnext26t_32x4d --lr 0.1 --warmup-epochs 5 --epochs 160 --weight-decay 1e-4 --sched cosine --reprob 0.4 --remode pixel -b 112
带 RandAugment 的 EfficientNet-B0 - 77.7 top-1, 95.3 top-5
Michael Klachko 通过修改 B2 的命令行以适应更大的批量大小,并使用推荐的 B0 dropout 率 0.2,获得了这些结果。
./distributed_train.sh 2 /imagenet/ --model efficientnet_b0 -b 384 --sched step --epochs 450 --decay-epochs 2.4 --decay-rate .97 --opt rmsproptf --opt-eps .001 -j 8 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.2 --drop-connect 0.2 --model-ema --model-ema-decay 0.9999 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.2 --amp --lr .048
带 JSD loss 和 RandAugment(干净 + 2x RA augs)的 ResNet50 - 79.04 top-1, 94.39 top-5
在两块较旧的 1080Ti 显卡上训练,花了不少时间。ImageNet 验证结果仅比我第一次进行 AugMix 良好训练时的 78.99 略好,没有统计学上的显著差异。然而,这些权重在 ImageNetV2、ImageNet-Sketch 等测试上更具鲁棒性。与我第一次运行 AugMix 不同,我启用了 SplitBatchNorm,在干净分支上禁用了随机擦除,并在两个增强分支上提高了随机擦除的概率。
./distributed_train.sh 2 /imagenet -b 64 --model resnet50 --sched cosine --epochs 200 --lr 0.05 --amp --remode pixel --reprob 0.6 --aug-splits 3 --aa rand-m9-mstd0.5-inc1 --resplit --split-bn --jsd --dist-bn reduce
带 RandAugment 的 EfficientNet-ES (EdgeTPU-Small) - 78.066 top-1, 93.926 top-5
由 Andrew Lavin 使用 8 块 V100 显卡训练。未使用模型 EMA,最终检查点是训练期间 8 个最佳检查点的平均值。
./distributed_train.sh 8 /imagenet --model efficientnet_es -b 128 --sched step --epochs 450 --decay-epochs 2.4 --decay-rate .97 --opt rmsproptf --opt-eps .001 -j 8 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.2 --drop-connect 0.2 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.2 --amp --lr .064
MobileNetV3-Large-100 - 75.766 top-1, 92,542 top-5
./distributed_train.sh 2 /imagenet/ --model mobilenetv3_large_100 -b 512 --sched step --epochs 600 --decay-epochs 2.4 --decay-rate .973 --opt rmsproptf --opt-eps .001 -j 7 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.2 --drop-connect 0.2 --model-ema --model-ema-decay 0.9999 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.2 --amp --lr .064 --lr-noise 0.42 0.9
带 RandAugment 的 ResNeXt-50 32x4d - 79.762 top-1, 94.60 top-5
这些参数也适用于 SE-ResNeXt-50 和 SK-ResNeXt-50,可能也适用于 101。我用它们训练了 SK-ResNeXt-50 32x4d,使用了 2 块 GPU,并对每个有效批量大小使用了稍高的学习率 (lr=0.18, b=192 per GPU)。下面的命令行是为 8 块 GPU 训练调优的。
./distributed_train.sh 8 /imagenet --model resnext50_32x4d --lr 0.6 --warmup-epochs 5 --epochs 240 --weight-decay 1e-4 --sched cosine --reprob 0.4 --recount 3 --remode pixel --aa rand-m7-mstd0.5-inc1 -b 192 -j 6 --amp --dist-bn reduce
带 JSD loss 和 RandAugment(干净 + 2x RA augs)的 ResNet50 - 79.04 top-1, 94.39 top-5
在两块较旧的 1080Ti 显卡上训练,花了不少时间。ImageNet 验证结果仅比我第一次进行 AugMix 良好训练时的 78.99 略好,没有统计学上的显著差异。然而,这些权重在 ImageNetV2、ImageNet-Sketch 等测试上更具鲁棒性。与我第一次运行 AugMix 不同,我启用了 SplitBatchNorm,在干净分支上禁用了随机擦除,并在两个增强分支上提高了随机擦除的概率。
./distributed_train.sh 2 /imagenet -b 64 --model resnet50 --sched cosine --epochs 200 --lr 0.05 --amp --remode pixel --reprob 0.6 --aug-splits 3 --aa rand-m9-mstd0.5-inc1 --resplit --split-bn --jsd --dist-bn reduce