diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/README.md b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/README.md index c96358198e1117e7218032573a99c8a922069ee1..9325faa55c420c307853b8d11100e2b6ff9a5155 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/README.md @@ -2,26 +2,20 @@ 单卡训练流程: -``` - 1.安装环境 - 2.修改run_1p.sh字段"data"为当前磁盘的数据集路径 - 3.修改字段device_id(单卡训练所使用的device id),为训练配置device_id,比如device_id=0 - 4.cd到run_1p.sh文件的目录,执行bash run_1p.sh单卡脚本, 进行单卡训练 -``` + 1.安装环境 + 2.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - + 多卡训练流程 -``` - 1.安装环境 - 2.修改多P脚本中字段"data"为当前磁盘的数据集路径 - 3.修改run_8p.sh字段"addr"为当前主机ip地址 - 4.cd到run_8p.sh文件的目录,执行bash run_8p.sh等多卡脚本, 进行多卡训练 -``` - + 1.安装环境 + 2.开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 - 二、Docker容器训练: 1.导入镜像二进制包docker import ubuntuarmpytorch.tar REPOSITORY:TAG, 比如: diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/env_npu.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/env_npu.sh deleted file mode 100644 index 1f3834e1cfa262d2bdfbac23a1a661135c04e558..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/env_npu.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash -export install_path=/usr/local/Ascend - -if [ -d ${install_path}/toolkit ]; then - export LD_LIBRARY_PATH=/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} - export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH - export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH - export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH - export ASCEND_OPP_PATH=${install_path}/opp -else - if [ -d ${install_path}/nnae/latest ];then - export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/nnae/latest - else - export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest - fi -fi - - -#将Host日志输出到串口,0-关闭/1-开启 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -#设置默认日志级别,0-debug/1-info/2-warning/3-error -export ASCEND_GLOBAL_LOG_LEVEL=3 -#设置Event日志开启标志,0-关闭/1-开启 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#设置是否开启taskque,0-关闭/1-开启 -export TASK_QUEUE_ENABLE=1 -#设置是否开启PTCopy,0-关闭/1-开启 -export PTCOPY_ENABLE=1 -#HCCL白名单开关,1-关闭/0-开启 -export HCCL_WHITELIST_DISABLE=1 - -#设置device侧日志登记为error -${install_path}/driver/tools/msnpureport -g error -d 0 -${install_path}/driver/tools/msnpureport -g error -d 1 -${install_path}/driver/tools/msnpureport -g error -d 2 -${install_path}/driver/tools/msnpureport -g error -d 3 -${install_path}/driver/tools/msnpureport -g error -d 4 -${install_path}/driver/tools/msnpureport -g error -d 5 -${install_path}/driver/tools/msnpureport -g error -d 6 -${install_path}/driver/tools/msnpureport -g error -d 7 -#关闭Device侧Event日志 -${install_path}/driver/tools/msnpureport -e disable - -path_lib=$(python3.7 -c """ -import sys -import re -result='' -for index in range(len(sys.path)): - match_sit = re.search('-packages', sys.path[index]) - if match_sit is not None: - match_lib = re.search('lib', sys.path[index]) - - if match_lib is not None: - end=match_lib.span()[1] - result += sys.path[index][0:end] + ':' - - result+=sys.path[index] + '/torch/lib:' -print(result)""" -) - -echo ${path_lib} - -export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_1p.sh deleted file mode 100644 index a7bec336168786b24f40fc44e91facf1ee8a81c1..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_1p.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -source env_npu.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_1p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -python3.7 ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=512 \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --npu=0 > ${train_log_dir}/train_1p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_8p.sh deleted file mode 100644 index 63e06c3410e42314e4899f5f62ff7e2361440993..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/run_8p.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -source env_npu.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error -/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_8p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -python3.7 ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=4096 \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --device_list '0,1,2,3,4,5,6,7' > ${train_log_dir}/train_8p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_1p.sh index f2f9691547844924118dd7c04a57a7a4c2896c91..74a94c1402edb8a4770975881f7b343fc4396695 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_1p.sh @@ -2,6 +2,14 @@ #当前路径,不需要修改 cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi #集合通信参数,不需要修改 @@ -85,11 +93,18 @@ if [[ $data_path == "" ]];then exit 1 fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + #训练开始时间,不需要修改 start_time=$(date +%s) - +ASCEND_DEVICE_ID=0 #进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. +cd $cur_path for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); do #设置环境变量,不需要修改 @@ -99,11 +114,11 @@ do #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt fi # 绑核,不需要的绑核的模型删除,需要的模型审视修改 #let a=RANK_ID*12 @@ -112,7 +127,7 @@ do #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - python3 ${cur_path}/../examples/imagenet/main.py \ + nohup python3.7 ${cur_path}/examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b4 \ --batch-size=${batch_size} \ @@ -124,7 +139,7 @@ do --pm=O1 \ --loss_scale=32 \ --val_feq=10 \ - --npu=$ASCEND_DEVICE_ID > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + --npu=$ASCEND_DEVICE_ID > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & done wait @@ -135,12 +150,12 @@ e2e_time=$(( $end_time - $start_time )) #结果打印,不需要修改 echo "------------------ Final result ------------------" #输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep -a 'FPS' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` #打印,不需要修改 echo "Final Performance images/sec : $FPS" #输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` #打印,不需要修改 echo "Final Train Accuracy : ${train_accuracy}" echo "E2E Training Duration sec : $e2e_time" @@ -158,18 +173,18 @@ ActualFPS=${FPS} TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` #从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep Epoch: $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt #最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` #关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_8p.sh index 6058a2132a8d499f6b5446a6a00775af6f7c8d4c..394afd7ec41ce4880fe0a7fb8857c039b84c5f42 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_full_8p.sh @@ -1,7 +1,4 @@ #!/bin/bash -#source env_npu.sh -#当前路径,不需要修改 -cur_path=`pwd` #集合通信参数,不需要修改 @@ -95,12 +92,19 @@ else mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + ##################启动训练脚本################## #训练开始时间,不需要修改 start_time=$(date +%s) # source 环境变量 #source ${test_path_dir}/env.sh -python3 ${test_path_dir}/../examples/imagenet/main.py \ +nohup python3.7 ${test_path_dir}/../examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b4 \ --batch-size=${batch_size} \ diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_1p.sh index f4c1e7e92cd7bafae43bca0760f41ccf2bd0b1ec..3e9586c3a59899388aff3735a26a6594650c3138 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_1p.sh @@ -1,7 +1,15 @@ #!/bin/bash -#source env_npu.sh + #当前路径,不需要修改 cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi #集合通信参数,不需要修改 @@ -85,25 +93,30 @@ if [[ $data_path == "" ]];then exit 1 fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +ASCEND_DEVICE_ID=0 #训练开始时间,不需要修改 start_time=$(date +%s) #进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. +cd $cur_path for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); do #设置环境变量,不需要修改 echo "Device ID: $ASCEND_DEVICE_ID" export RANK_ID=$RANK_ID - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt fi # 绑核,不需要的绑核的模型删除,需要的模型审视修改 #let a=RANK_ID*12 @@ -112,7 +125,7 @@ do #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - python3 ${cur_path}/../examples/imagenet/main.py \ + python3 ${cur_path}/examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b4 \ --batch-size=${batch_size} \ @@ -125,7 +138,7 @@ do --loss_scale=32 \ --val_feq=10 \ --stop-step-num=128 \ - --npu=$ASCEND_DEVICE_ID > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + --npu=$ASCEND_DEVICE_ID > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & done wait @@ -136,12 +149,12 @@ e2e_time=$(( $end_time - $start_time )) #结果打印,不需要修改 echo "------------------ Final result ------------------" #输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep -a 'FPS' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` #打印,不需要修改 echo "Final Performance images/sec : $FPS" #输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` #打印,不需要修改 echo "Final Train Accuracy : ${train_accuracy}" echo "E2E Training Duration sec : $e2e_time" @@ -159,18 +172,18 @@ ActualFPS=${FPS} TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` #从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep Epoch: $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt #最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` #关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_8p.sh index 23dd1394c3223869e26c1fc49d1756583a59a4ec..6134dd7a0685057575b021e99592952a152f10fb 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch/test/train_performance_8p.sh @@ -1,10 +1,5 @@ #!/bin/bash -#source env_npu.sh -#当前路径,不需要修改 -cur_path=`pwd` - #集合通信参数,不需要修改 - export RANK_SIZE=8 export JOB_ID=10087 RANK_ID_START=0 @@ -95,12 +90,17 @@ else mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + ##################启动训练脚本################## #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -#source ${test_path_dir}/env.sh -python3 ${test_path_dir}/../examples/imagenet/main.py \ +nohup python3.7 ${test_path_dir}/../examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b4 \ --batch-size=${batch_size} \ diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/README.md b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/README.md index c96358198e1117e7218032573a99c8a922069ee1..8cfabe7a9f6d8bfc49fc244a7e27d12e7fe21924 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/README.md @@ -1,24 +1,20 @@ 一、训练流程: + 单卡训练流程: -``` - 1.安装环境 - 2.修改run_1p.sh字段"data"为当前磁盘的数据集路径 - 3.修改字段device_id(单卡训练所使用的device id),为训练配置device_id,比如device_id=0 - 4.cd到run_1p.sh文件的目录,执行bash run_1p.sh单卡脚本, 进行单卡训练 -``` + 1.安装环境 + 2.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - + 多卡训练流程 -``` - 1.安装环境 - 2.修改多P脚本中字段"data"为当前磁盘的数据集路径 - 3.修改run_8p.sh字段"addr"为当前主机ip地址 - 4.cd到run_8p.sh文件的目录,执行bash run_8p.sh等多卡脚本, 进行多卡训练 -``` - + 1.安装环境 + 2.开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/env_npu.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/env_npu.sh deleted file mode 100644 index b10494a71a7e8edd749b32cff1c84f36bf4bc27b..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/env_npu.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -export install_path=/usr/local/Ascend - -if [ -d ${install_path}/toolkit ]; then - export LD_LIBRARY_PATH=/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} - export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH - export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH - export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH - export ASCEND_OPP_PATH=${install_path}/opp -else - if [ -d ${install_path}/nnae/latest ];then - export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/nnae/latest - else - export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest - fi -fi - - -#将Host日志输出到串口,0-关闭/1-开启 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -#设置默认日志级别,0-debug/1-info/2-warning/3-error -export ASCEND_GLOBAL_LOG_LEVEL=3 -#设置Event日志开启标志,0-关闭/1-开启 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#设置是否开启taskque,0-关闭/1-开启 -export TASK_QUEUE_ENABLE=1 -#设置是否开启PTCopy,0-关闭/1-开启 -export PTCOPY_ENABLE=1 -#HCCL白名单开关,1-关闭/0-开启 -export HCCL_WHITELIST_DISABLE=1 - - -#设置device侧日志登记为error -${install_path}/driver/tools/msnpureport -g error -d 0 -${install_path}/driver/tools/msnpureport -g error -d 1 -${install_path}/driver/tools/msnpureport -g error -d 2 -${install_path}/driver/tools/msnpureport -g error -d 3 -${install_path}/driver/tools/msnpureport -g error -d 4 -${install_path}/driver/tools/msnpureport -g error -d 5 -${install_path}/driver/tools/msnpureport -g error -d 6 -${install_path}/driver/tools/msnpureport -g error -d 7 -#关闭Device侧Event日志 -${install_path}/driver/tools/msnpureport -e disable - -path_lib=$(python3.7 -c """ -import sys -import re -result='' -for index in range(len(sys.path)): - match_sit = re.search('-packages', sys.path[index]) - if match_sit is not None: - match_lib = re.search('lib', sys.path[index]) - - if match_lib is not None: - end=match_lib.span()[1] - result += sys.path[index][0:end] + ':' - - result+=sys.path[index] + '/torch/lib:' -print(result)""" -) - -echo ${path_lib} - -export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_1p.sh deleted file mode 100644 index 33a92f58cd625023a3d4faf45e29e91227a56303..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_1p.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -source npu_set_env.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_1p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -python3.7 ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=512 \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --npu=0 > ${train_log_dir}/train_1p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_8p.sh deleted file mode 100644 index 389062c67150ab0f2e9b61742ecb84239fc77a80..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/run_8p.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -source npu_set_env.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error -/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_8p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -python3.7 ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=4096 \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --device_list '0,1,2,3,4,5,6,7' > ${train_log_dir}/train_8p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_1p.sh index b6a3b682b140a9138d734629d8c16bed3d9422aa..c5427725323d6cbd4bf704a5756a0e0657029d89 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_1p.sh @@ -2,6 +2,14 @@ #当前路径,不需要修改 cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi #集合通信参数,不需要修改 @@ -87,25 +95,30 @@ if [[ $data_path == "" ]];then exit 1 fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + #训练开始时间,不需要修改 start_time=$(date +%s) #进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. +cd $cur_path +ASCEND_DEVICE_ID=0 for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); do #设置环境变量,不需要修改 echo "Device ID: $ASCEND_DEVICE_ID" export RANK_ID=$RANK_ID - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt fi # 绑核,不需要的绑核的模型删除,需要的模型审视修改 #let a=RANK_ID*12 @@ -114,7 +127,7 @@ do #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - python3 ${cur_path}/../examples/imagenet/main.py \ + nohup python3.7 ${cur_path}/examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b5 \ --batch-size=${batch_size} \ @@ -126,7 +139,7 @@ do --pm=O1 \ --loss_scale=32 \ --val_feq=10 \ - --npu=$ASCEND_DEVICE_ID > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + --npu=$ASCEND_DEVICE_ID > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & done wait @@ -137,12 +150,12 @@ e2e_time=$(( $end_time - $start_time )) #结果打印,不需要修改 echo "------------------ Final result ------------------" #输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep -a 'FPS' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` #打印,不需要修改 echo "Final Performance images/sec : $FPS" #输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` #打印,不需要修改 echo "Final Train Accuracy : ${train_accuracy}" echo "E2E Training Duration sec : $e2e_time" @@ -160,18 +173,18 @@ ActualFPS=${FPS} TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` #从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep Epoch: $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt #最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` #关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_8p.sh index 9d6ee89ba26dc4668d154dd367b70c335e8db36b..c6c2a1339710e5e7d7c62f303f669fe33f595258 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_full_8p.sh @@ -1,7 +1,4 @@ #!/bin/bash -#source env_npu.sh -#当前路径,不需要修改 -cur_path=`pwd` #集合通信参数,不需要修改 @@ -86,6 +83,12 @@ else test_path_dir=${cur_path}/test fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi ##################创建日志输出目录,根据模型审视################## # 模型采用非循环方式启动多卡训练,创建日志输出目录如下;采用循环方式启动多卡训练的模型,在循环中创建日志输出目录,可参考CRNN模型 @@ -101,9 +104,8 @@ fi ##################启动训练脚本################## #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -#source ${test_path_dir}/env.sh -python3 ${test_path_dir}/../examples/imagenet/main.py \ + +nohup python3.7 ${test_path_dir}/../examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b5 \ --batch-size=${batch_size} \ diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_1p.sh index ac44bd886a911967dfd6c21c443c58932a01b95f..6eb1638724e581421b00d1137c7e5ce54e37e718 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_1p.sh @@ -1,7 +1,14 @@ #!/bin/bash -#source env_npu.sh #当前路径,不需要修改 cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi #集合通信参数,不需要修改 @@ -88,25 +95,30 @@ if [[ $data_path == "" ]];then exit 1 fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + #训练开始时间,不需要修改 start_time=$(date +%s) - +ASCEND_DEVICE_ID=0 #进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. +cd $cur_path for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); do #设置环境变量,不需要修改 echo "Device ID: $ASCEND_DEVICE_ID" export RANK_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt fi # 绑核,不需要的绑核的模型删除,需要的模型审视修改 #let a=RANK_ID*12 @@ -115,7 +127,7 @@ do #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - python3 ${cur_path}/../examples/imagenet/main.py \ + nohup python3.7 ${cur_path}/examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b5 \ --batch-size=${batch_size} \ @@ -128,7 +140,7 @@ do --loss_scale=32 \ --val_feq=10 \ --stop-step-num=128 \ - --npu=$ASCEND_DEVICE_ID > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + --npu=$ASCEND_DEVICE_ID > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & done wait @@ -139,12 +151,12 @@ e2e_time=$(( $end_time - $start_time )) #结果打印,不需要修改 echo "------------------ Final result ------------------" #输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep -a 'FPS' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` #打印,不需要修改 echo "Final Performance images/sec : $FPS" #输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' $test_path_dir/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` #打印,不需要修改 echo "Final Train Accuracy : ${train_accuracy}" echo "E2E Training Duration sec : $e2e_time" @@ -162,18 +174,18 @@ ActualFPS=${FPS} TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` #从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep Epoch: $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt #最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` #关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_8p.sh index fdf88cce5baefe283476f3b3f8dfd046574dcd40..a5e411f6a455d4e7d6ea6731a2d808d0bc2b1dec 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch/test/train_performance_8p.sh @@ -1,7 +1,4 @@ #!/bin/bash -#source env_npu.sh -#当前路径,不需要修改 -cur_path=`pwd` #集合通信参数,不需要修改 @@ -98,12 +95,18 @@ else mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID fi +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + ##################启动训练脚本################## #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -#source ${test_path_dir}/env.sh -python3 ${test_path_dir}/../examples/imagenet/main.py \ + +nohup python3.7 ${test_path_dir}/../examples/imagenet/main.py \ --data=${data_path} \ --arch=efficientnet-b5 \ --batch-size=${batch_size} \ diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/README.md b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/README.md index c96358198e1117e7218032573a99c8a922069ee1..8c8dbfb5be5c747e741ec4f08791ab1fd9309eb5 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/README.md @@ -2,22 +2,18 @@ 单卡训练流程: -``` - 1.安装环境 - 2.修改run_1p.sh字段"data"为当前磁盘的数据集路径 - 3.修改字段device_id(单卡训练所使用的device id),为训练配置device_id,比如device_id=0 - 4.cd到run_1p.sh文件的目录,执行bash run_1p.sh单卡脚本, 进行单卡训练 -``` + 1.安装环境 + 2.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - + 多卡训练流程 -``` - 1.安装环境 - 2.修改多P脚本中字段"data"为当前磁盘的数据集路径 - 3.修改run_8p.sh字段"addr"为当前主机ip地址 - 4.cd到run_8p.sh文件的目录,执行bash run_8p.sh等多卡脚本, 进行多卡训练 -``` + 1.安装环境 + 2.开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_1p.sh deleted file mode 100644 index ad12e922b677783d366fc8e4bf23f58a58a85e33..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_1p.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -source env_npu.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_1p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -if [ $(uname -m) = "aarch64" ] -then - taskset -c 0-95 python3.7 -u ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=512 \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --npu=0 > ${train_log_dir}/train_1p.log 2>&1 & -else - python3.7 -u ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=512 \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --npu=0 > ${train_log_dir}/train_1p.log 2>&1 & -fi \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_8p.sh deleted file mode 100644 index 2a1b9e2c311027cd07a239c0f4b15d3291b63215..0000000000000000000000000000000000000000 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_8p.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -source env_npu.sh - -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error -/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error - -currentDir=$(cd "$(dirname "$0")";pwd) -currtime=`date +%Y%m%d%H%M%S` -train_log_dir=${currentDir}/result/training_8p_job_${currtime} -mkdir -p ${train_log_dir} -cd ${train_log_dir} -echo "train log path is ${train_log_dir}" - -kernel_num=$(nproc) - -if [ ${kernel_num} -lt 95 ];then - cpu_number=${kernel_num} -else - cpu_number=95 -fi - -taskset -c 0-${cpu_number} python3.7 ${currentDir}/examples/imagenet/main.py \ - --data=/data/imagenet \ - --arch=efficientnet-b0 \ - --batch-size=4096 \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --device_list '0,1,2,3,4,5,6,7' > ${train_log_dir}/train_8p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/env_npu.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/env_npu.sh similarity index 100% rename from PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/env_npu.sh rename to PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/env_npu.sh diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh index 5a841a3b8809fc2e902831a11a0ea54099d4659a..804ed46b6e9b7d7d68a0a048cd1317f15be069c2 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh @@ -1,174 +1,190 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=100 -#训练batch_size -batch_size=4096 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#add ASCEND_DEVICE_ID -ASCEND_DEVICE_ID=0 - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` -let a=RANK_ID*${corenum}/${RANK_SIZE} -let b=RANK_ID+1 -let c=b*${corenum}/${RANK_SIZE}-1 - - -nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 --batch-size=$batch_size \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -train_accuracy=`grep -a '* Acc@1' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=100 +#训练batch_size +batch_size=4096 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#add ASCEND_DEVICE_ID +ASCEND_DEVICE_ID=0 + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` +let a=RANK_ID*${corenum}/${RANK_SIZE} +let b=RANK_ID+1 +let c=b*${corenum}/${RANK_SIZE}-1 + + +nohup taskset -c $a-$c python3.7 ${cur_path}/examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 --batch-size=$batch_size \ + --lr=1.6 \ + --momentum=0.9 \ + --epochs=$train_epochs \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --addr=$(hostname -I |awk '{print $1}') \ + --dist-backend=hccl \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 > $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh index 4a5a6d5b4cf8463f4a88bf73a49b085b8cf9b039..279206e7fa999131996e50aafbf764340ad22688 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh @@ -1,160 +1,175 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=512 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#训练 -nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 \ - --batch-size=$batch_size \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=$train_epochs \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --stop-step-num=1000 \ - --npu=$ASCEND_DEVICE_ID > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=512 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path +ASCEND_DEVICE_ID=0 +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $test_path_dir/output ];then + rm -rf $test_path_dir/output/* + mkdir -p $test_path_dir/output/$ASCEND_DEVICE_ID +else + mkdir -p $test_path_dir/output/$ASCEND_DEVICE_ID +fi +wait + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#训练 +nohup python3.7 ${cur_path}/examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 \ + --batch-size=$batch_size \ + --lr=0.2 \ + --momentum=0.9 \ + --epochs=$train_epochs \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --stop-step-num=1000 \ + --npu=$ASCEND_DEVICE_ID > $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh index 5128dfcbb28a5c33daf7484bc1d856e0868d5bf2..890b892c5894b6528fced0d21c42afe4d5b7e9b2 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh @@ -1,173 +1,189 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export SOC_VERSION=Ascend910 -export HCCL_CONNECT_TIMEOUT=600 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=4096 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -#corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` -#let a=RANK_ID*${corenum}/${RANK_SIZE} -#let b=RANK_ID+1 -#let c=b*${corenum}/${RANK_SIZE}-1 -export RANK_INDEX=0 -DEVICE_INDEX=$(( ASCEND_DEVICE_ID + RANK_INDEX * 8 )) -export DEVICE_INDEX=${DEVICE_INDEX} - -#nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py -nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 \ - --batch-size=$batch_size \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=1 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export SOC_VERSION=Ascend910 +export HCCL_CONNECT_TIMEOUT=600 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=4096 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +cd $cur_path +ASCEND_DEVICE_ID=0 +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $test_path_dir/output ];then + rm -rf $test_path_dir/output/* + mkdir -p $test_path_dir/output/$ASCEND_DEVICE_ID +else + mkdir -p $test_path_dir/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +#corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` +#let a=RANK_ID*${corenum}/${RANK_SIZE} +#let b=RANK_ID+1 +#let c=b*${corenum}/${RANK_SIZE}-1 +export RANK_INDEX=0 +DEVICE_INDEX=$(( ASCEND_DEVICE_ID + RANK_INDEX * 8 )) +export DEVICE_INDEX=${DEVICE_INDEX} + +#nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py +nohup python3.7 ${cur_path}/examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 \ + --batch-size=$batch_size \ + --lr=1.6 \ + --momentum=0.9 \ + --epochs=1 \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --addr=$(hostname -I |awk '{print $1}') \ + --dist-backend=hccl \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 > $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $test_path_dir/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $test_path_dir/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README.md b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README.md index 76261cccf2de722c023d94286b41ea3ec8e0d491..c3df4f61b972928c330b5aad3e0df824543b9e29 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README.md @@ -1,399 +1,37 @@ -# PyTorch Image Models -- [Sponsors](#sponsors) -- [What's New](#whats-new) -- [Introduction](#introduction) -- [Models](#models) -- [Features](#features) -- [Results](#results) -- [Getting Started (Documentation)](#getting-started-documentation) -- [Train, Validation, Inference Scripts](#train-validation-inference-scripts) -- [Awesome PyTorch Resources](#awesome-pytorch-resources) -- [Licenses](#licenses) -- [Citing](#citing) +一、训练流程: + -## Sponsors +单卡训练流程: -A big thank you to my [GitHub Sponsors](https://github.com/sponsors/rwightman) for their support! + 1.安装环境 + 2.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 -In addition to the sponsors at the link above, I've received hardware and/or cloud resources from -* Nvidia (https://www.nvidia.com/en-us/) -* TFRC (https://www.tensorflow.org/tfrc) + +多卡训练流程 -I'm fortunate to be able to dedicate significant time and money of my own supporting this and other open source projects. However, as the projects increase in scope, outside support is needed to continue with the current trajectory of hardware, infrastructure, and electricty costs. + 1.安装环境 + 2.开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 -## What's New -### June 20, 2021 -* Release Vision Transformer 'AugReg' weights from [How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers](https://arxiv.org/abs/2106.10270) - * .npz weight loading support added, can load any of the 50K+ weights from the [AugReg series](https://console.cloud.google.com/storage/browser/vit_models/augreg) - * See [example notebook](https://colab.research.google.com/github/google-research/vision_transformer/blob/master/vit_jax_augreg.ipynb) from official impl for navigating the augreg weights - * Replaced all default weights w/ best AugReg variant (if possible). All AugReg 21k classifiers work. - * Highlights: `vit_large_patch16_384` (87.1 top-1), `vit_large_r50_s32_384` (86.2 top-1), `vit_base_patch16_384` (86.0 top-1) - * `vit_deit_*` renamed to just `deit_*` - * Remove my old small model, replace with DeiT compatible small w/ AugReg weights -* Add 1st training of my `gmixer_24_224` MLP /w GLU, 78.1 top-1 w/ 25M params. -* Add weights from official ResMLP release (https://github.com/facebookresearch/deit) -* Add `eca_nfnet_l2` weights from my 'lightweight' series. 84.7 top-1 at 384x384. -* Add distilled BiT 50x1 student and 152x2 Teacher weights from [Knowledge distillation: A good teacher is patient and consistent](https://arxiv.org/abs/2106.05237) -* NFNets and ResNetV2-BiT models work w/ Pytorch XLA now - * weight standardization uses F.batch_norm instead of std_mean (std_mean wasn't lowered) - * eps values adjusted, will be slight differences but should be quite close -* Improve test coverage and classifier interface of non-conv (vision transformer and mlp) models -* Cleanup a few classifier / flatten details for models w/ conv classifiers or early global pool -* Please report any regressions, this PR touched quite a few models. + +二、Docker容器训练: + +1.导入镜像二进制包docker import ubuntuarmpytorch.tar REPOSITORY:TAG, 比如: -### June 8, 2021 -* Add first ResMLP weights, trained in PyTorch XLA on TPU-VM w/ my XLA branch. 24 block variant, 79.2 top-1. -* Add ResNet51-Q model w/ pretrained weights at 82.36 top-1. - * NFNet inspired block layout with quad layer stem and no maxpool - * Same param count (35.7M) and throughput as ResNetRS-50 but +1.5 top-1 @ 224x224 and +2.5 top-1 at 288x288 + docker import ubuntuarmpytorch.tar pytorch:b020 -### May 25, 2021 -* Add LeViT, Visformer, ConViT (PR by Aman Arora), Twins (PR by paper authors) transformer models -* Add ResMLP and gMLP MLP vision models to the existing MLP Mixer impl -* Fix a number of torchscript issues with various vision transformer models -* Cleanup input_size/img_size override handling and improve testing / test coverage for all vision transformer and MLP models -* More flexible pos embedding resize (non-square) for ViT and TnT. Thanks [Alexander Soare](https://github.com/alexander-soare) -* Add `efficientnetv2_rw_m` model and weights (started training before official code). 84.8 top-1, 53M params. +2.执行docker_start.sh后带三个参数:步骤1生成的REPOSITORY:TAG;数据集路径;模型执行路径;比如: -### May 14, 2021 -* Add EfficientNet-V2 official model defs w/ ported weights from official [Tensorflow/Keras](https://github.com/google/automl/tree/master/efficientnetv2) impl. - * 1k trained variants: `tf_efficientnetv2_s/m/l` - * 21k trained variants: `tf_efficientnetv2_s/m/l_in21k` - * 21k pretrained -> 1k fine-tuned: `tf_efficientnetv2_s/m/l_in21ft1k` - * v2 models w/ v1 scaling: `tf_efficientnetv2_b0` through `b3` - * Rename my prev V2 guess `efficientnet_v2s` -> `efficientnetv2_rw_s` - * Some blank `efficientnetv2_*` models in-place for future native PyTorch training + ./docker_start.sh pytorch:b020 /train/imagenet /home/Gluon_ResNet50_v1c_for_PyTorch -### May 5, 2021 -* Add MLP-Mixer models and port pretrained weights from [Google JAX impl](https://github.com/google-research/vision_transformer/tree/linen) -* Add CaiT models and pretrained weights from [FB](https://github.com/facebookresearch/deit) -* Add ResNet-RS models and weights from [TF](https://github.com/tensorflow/tpu/tree/master/models/official/resnet/resnet_rs). Thanks [Aman Arora](https://github.com/amaarora) -* Add CoaT models and weights. Thanks [Mohammed Rizin](https://github.com/morizin) -* Add new ImageNet-21k weights & finetuned weights for TResNet, MobileNet-V3, ViT models. Thanks [mrT](https://github.com/mrT23) -* Add GhostNet models and weights. Thanks [Kai Han](https://github.com/iamhankai) -* Update ByoaNet attention modules - * Improve SA module inits - * Hack together experimental stand-alone Swin based attn module and `swinnet` - * Consistent '26t' model defs for experiments. -* Add improved Efficientnet-V2S (prelim model def) weights. 83.8 top-1. -* WandB logging support +3.执行步骤一训练流程(环境安装除外) + +三、测试结果 + +训练日志路径:在训练脚本的同目录下result文件夹里,如: -### April 13, 2021 -* Add Swin Transformer models and weights from https://github.com/microsoft/Swin-Transformer - -### April 12, 2021 -* Add ECA-NFNet-L1 (slimmed down F1 w/ SiLU, 41M params) trained with this code. 84% top-1 @ 320x320. Trained at 256x256. -* Add EfficientNet-V2S model (unverified model definition) weights. 83.3 top-1 @ 288x288. Only trained single res 224. Working on progressive training. -* Add ByoaNet model definition (Bring-your-own-attention) w/ SelfAttention block and corresponding SA/SA-like modules and model defs - * Lambda Networks - https://arxiv.org/abs/2102.08602 - * Bottleneck Transformers - https://arxiv.org/abs/2101.11605 - * Halo Nets - https://arxiv.org/abs/2103.12731 -* Adabelief optimizer contributed by Juntang Zhuang - -### April 1, 2021 -* Add snazzy `benchmark.py` script for bulk `timm` model benchmarking of train and/or inference -* Add Pooling-based Vision Transformer (PiT) models (from https://github.com/naver-ai/pit) - * Merged distilled variant into main for torchscript compatibility - * Some `timm` cleanup/style tweaks and weights have hub download support -* Cleanup Vision Transformer (ViT) models - * Merge distilled (DeiT) model into main so that torchscript can work - * Support updated weight init (defaults to old still) that closer matches original JAX impl (possibly better training from scratch) - * Separate hybrid model defs into different file and add several new model defs to fiddle with, support patch_size != 1 for hybrids - * Fix fine-tuning num_class changes (PiT and ViT) and pos_embed resizing (Vit) with distilled variants - * nn.Sequential for block stack (does not break downstream compat) -* TnT (Transformer-in-Transformer) models contributed by author (from https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/cv/TNT) -* Add RegNetY-160 weights from DeiT teacher model -* Add new NFNet-L0 w/ SE attn (rename `nfnet_l0b`->`nfnet_l0`) weights 82.75 top-1 @ 288x288 -* Some fixes/improvements for TFDS dataset wrapper - -### March 17, 2021 -* Add new ECA-NFNet-L0 (rename `nfnet_l0c`->`eca_nfnet_l0`) weights trained by myself. - * 82.6 top-1 @ 288x288, 82.8 @ 320x320, trained at 224x224 - * Uses SiLU activation, approx 2x faster than `dm_nfnet_f0` and 50% faster than `nfnet_f0s` w/ 1/3 param count -* Integrate [Hugging Face model hub](https://huggingface.co/models) into timm create_model and default_cfg handling for pretrained weight and config sharing (more on this soon!) -* Merge HardCoRe NAS models contributed by https://github.com/yoniaflalo -* Merge PyTorch trained EfficientNet-EL and pruned ES/EL variants contributed by [DeGirum](https://github.com/DeGirum) - - -### March 7, 2021 -* First 0.4.x PyPi release w/ NFNets (& related), ByoB (GPU-Efficient, RepVGG, etc). -* Change feature extraction for pre-activation nets (NFNets, ResNetV2) to return features before activation. -* Tested with PyTorch 1.8 release. Updated CI to use 1.8. -* Benchmarked several arch on RTX 3090, Titan RTX, and V100 across 1.7.1, 1.8, NGC 20.12, and 21.02. Some interesting performance variations to take note of https://gist.github.com/rwightman/bb59f9e245162cee0e38bd66bd8cd77f - -### Feb 18, 2021 -* Add pretrained weights and model variants for NFNet-F* models from [DeepMind Haiku impl](https://github.com/deepmind/deepmind-research/tree/master/nfnets). - * Models are prefixed with `dm_`. They require SAME padding conv, skipinit enabled, and activation gains applied in act fn. - * These models are big, expect to run out of GPU memory. With the GELU activiation + other options, they are roughly 1/2 the inference speed of my SiLU PyTorch optimized `s` variants. - * Original model results are based on pre-processing that is not the same as all other models so you'll see different results in the results csv (once updated). - * Matching the original pre-processing as closely as possible I get these results: - * `dm_nfnet_f6` - 86.352 - * `dm_nfnet_f5` - 86.100 - * `dm_nfnet_f4` - 85.834 - * `dm_nfnet_f3` - 85.676 - * `dm_nfnet_f2` - 85.178 - * `dm_nfnet_f1` - 84.696 - * `dm_nfnet_f0` - 83.464 - -### Feb 16, 2021 -* Add Adaptive Gradient Clipping (AGC) as per https://arxiv.org/abs/2102.06171. Integrated w/ PyTorch gradient clipping via mode arg that defaults to prev 'norm' mode. For backward arg compat, clip-grad arg must be specified to enable when using train.py. - * AGC w/ default clipping factor `--clip-grad .01 --clip-mode agc` - * PyTorch global norm of 1.0 (old behaviour, always norm), `--clip-grad 1.0` - * PyTorch value clipping of 10, `--clip-grad 10. --clip-mode value` - * AGC performance is definitely sensitive to the clipping factor. More experimentation needed to determine good values for smaller batch sizes and optimizers besides those in paper. So far I've found .001-.005 is necessary for stable RMSProp training w/ NFNet/NF-ResNet. - -### Feb 12, 2021 -* Update Normalization-Free nets to include new NFNet-F (https://arxiv.org/abs/2102.06171) model defs - -### Feb 10, 2021 -* First Normalization-Free model training experiments done, - * nf_resnet50 - 80.68 top-1 @ 288x288, 80.31 @ 256x256 - * nf_regnet_b1 - 79.30 @ 288x288, 78.75 @ 256x256 -* More model archs, incl a flexible ByobNet backbone ('Bring-your-own-blocks') - * GPU-Efficient-Networks (https://github.com/idstcv/GPU-Efficient-Networks), impl in `byobnet.py` - * RepVGG (https://github.com/DingXiaoH/RepVGG), impl in `byobnet.py` - * classic VGG (from torchvision, impl in `vgg.py`) -* Refinements to normalizer layer arg handling and normalizer+act layer handling in some models -* Default AMP mode changed to native PyTorch AMP instead of APEX. Issues not being fixed with APEX. Native works with `--channels-last` and `--torchscript` model training, APEX does not. -* Fix a few bugs introduced since last pypi release - -### Feb 8, 2021 -* Add several ResNet weights with ECA attention. 26t & 50t trained @ 256, test @ 320. 269d train @ 256, fine-tune @320, test @ 352. - * `ecaresnet26t` - 79.88 top-1 @ 320x320, 79.08 @ 256x256 - * `ecaresnet50t` - 82.35 top-1 @ 320x320, 81.52 @ 256x256 - * `ecaresnet269d` - 84.93 top-1 @ 352x352, 84.87 @ 320x320 -* Remove separate tiered (`t`) vs tiered_narrow (`tn`) ResNet model defs, all `tn` changed to `t` and `t` models removed (`seresnext26t_32x4d` only model w/ weights that was removed). -* Support model default_cfgs with separate train vs test resolution `test_input_size` and remove extra `_320` suffix ResNet model defs that were just for test. - -### Jan 30, 2021 -* Add initial "Normalization Free" NF-RegNet-B* and NF-ResNet model definitions based on [paper](https://arxiv.org/abs/2101.08692) - -### Jan 25, 2021 -* Add ResNetV2 Big Transfer (BiT) models w/ ImageNet-1k and 21k weights from https://github.com/google-research/big_transfer -* Add official R50+ViT-B/16 hybrid models + weights from https://github.com/google-research/vision_transformer -* ImageNet-21k ViT weights are added w/ model defs and representation layer (pre logits) support - * NOTE: ImageNet-21k classifier heads were zero'd in original weights, they are only useful for transfer learning -* Add model defs and weights for DeiT Vision Transformer models from https://github.com/facebookresearch/deit -* Refactor dataset classes into ImageDataset/IterableImageDataset + dataset specific parser classes -* Add Tensorflow-Datasets (TFDS) wrapper to allow use of TFDS image classification sets with train script - * Ex: `train.py /data/tfds --dataset tfds/oxford_iiit_pet --val-split test --model resnet50 -b 256 --amp --num-classes 37 --opt adamw --lr 3e-4 --weight-decay .001 --pretrained -j 2` -* Add improved .tar dataset parser that reads images from .tar, folder of .tar files, or .tar within .tar - * Run validation on full ImageNet-21k directly from tar w/ BiT model: `validate.py /data/fall11_whole.tar --model resnetv2_50x1_bitm_in21k --amp` -* Models in this update should be stable w/ possible exception of ViT/BiT, possibility of some regressions with train/val scripts and dataset handling - -### Jan 3, 2021 -* Add SE-ResNet-152D weights - * 256x256 val, 0.94 crop top-1 - 83.75 - * 320x320 val, 1.0 crop - 84.36 -* Update [results files](results/) - - -## Introduction - -Py**T**orch **Im**age **M**odels (`timm`) is a collection of image models, layers, utilities, optimizers, schedulers, data-loaders / augmentations, and reference training / validation scripts that aim to pull together a wide variety of SOTA models with ability to reproduce ImageNet training results. - -The work of many others is present here. I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code docstrings. Please let me know if I missed anything. - -## Models - -All model architecture families include variants with pretrained weights. There are specific model variants without any weights, it is NOT a bug. Help training new or better weights is always appreciated. Here are some example [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) to get you started. - -A full version of the list below with source links can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/models/). - -* Big Transfer ResNetV2 (BiT) - https://arxiv.org/abs/1912.11370 -* Bottleneck Transformers - https://arxiv.org/abs/2101.11605 -* CaiT (Class-Attention in Image Transformers) - https://arxiv.org/abs/2103.17239 -* CoaT (Co-Scale Conv-Attentional Image Transformers) - https://arxiv.org/abs/2104.06399 -* ConViT (Soft Convolutional Inductive Biases Vision Transformers)- https://arxiv.org/abs/2103.10697 -* CspNet (Cross-Stage Partial Networks) - https://arxiv.org/abs/1911.11929 -* DeiT (Vision Transformer) - https://arxiv.org/abs/2012.12877 -* DenseNet - https://arxiv.org/abs/1608.06993 -* DLA - https://arxiv.org/abs/1707.06484 -* DPN (Dual-Path Network) - https://arxiv.org/abs/1707.01629 -* EfficientNet (MBConvNet Family) - * EfficientNet NoisyStudent (B0-B7, L2) - https://arxiv.org/abs/1911.04252 - * EfficientNet AdvProp (B0-B8) - https://arxiv.org/abs/1911.09665 - * EfficientNet (B0-B7) - https://arxiv.org/abs/1905.11946 - * EfficientNet-EdgeTPU (S, M, L) - https://ai.googleblog.com/2019/08/efficientnet-edgetpu-creating.html - * EfficientNet V2 - https://arxiv.org/abs/2104.00298 - * FBNet-C - https://arxiv.org/abs/1812.03443 - * MixNet - https://arxiv.org/abs/1907.09595 - * MNASNet B1, A1 (Squeeze-Excite), and Small - https://arxiv.org/abs/1807.11626 - * MobileNet-V2 - https://arxiv.org/abs/1801.04381 - * Single-Path NAS - https://arxiv.org/abs/1904.02877 -* GhostNet - https://arxiv.org/abs/1911.11907 -* gMLP - https://arxiv.org/abs/2105.08050 -* GPU-Efficient Networks - https://arxiv.org/abs/2006.14090 -* Halo Nets - https://arxiv.org/abs/2103.12731 -* HardCoRe-NAS - https://arxiv.org/abs/2102.11646 -* HRNet - https://arxiv.org/abs/1908.07919 -* Inception-V3 - https://arxiv.org/abs/1512.00567 -* Inception-ResNet-V2 and Inception-V4 - https://arxiv.org/abs/1602.07261 -* Lambda Networks - https://arxiv.org/abs/2102.08602 -* LeViT (Vision Transformer in ConvNet's Clothing) - https://arxiv.org/abs/2104.01136 -* MLP-Mixer - https://arxiv.org/abs/2105.01601 -* MobileNet-V3 (MBConvNet w/ Efficient Head) - https://arxiv.org/abs/1905.02244 -* NASNet-A - https://arxiv.org/abs/1707.07012 -* NFNet-F - https://arxiv.org/abs/2102.06171 -* NF-RegNet / NF-ResNet - https://arxiv.org/abs/2101.08692 -* PNasNet - https://arxiv.org/abs/1712.00559 -* Pooling-based Vision Transformer (PiT) - https://arxiv.org/abs/2103.16302 -* RegNet - https://arxiv.org/abs/2003.13678 -* RepVGG - https://arxiv.org/abs/2101.03697 -* ResMLP - https://arxiv.org/abs/2105.03404 -* ResNet/ResNeXt - * ResNet (v1b/v1.5) - https://arxiv.org/abs/1512.03385 - * ResNeXt - https://arxiv.org/abs/1611.05431 - * 'Bag of Tricks' / Gluon C, D, E, S variations - https://arxiv.org/abs/1812.01187 - * Weakly-supervised (WSL) Instagram pretrained / ImageNet tuned ResNeXt101 - https://arxiv.org/abs/1805.00932 - * Semi-supervised (SSL) / Semi-weakly Supervised (SWSL) ResNet/ResNeXts - https://arxiv.org/abs/1905.00546 - * ECA-Net (ECAResNet) - https://arxiv.org/abs/1910.03151v4 - * Squeeze-and-Excitation Networks (SEResNet) - https://arxiv.org/abs/1709.01507 - * ResNet-RS - https://arxiv.org/abs/2103.07579 -* Res2Net - https://arxiv.org/abs/1904.01169 -* ResNeSt - https://arxiv.org/abs/2004.08955 -* ReXNet - https://arxiv.org/abs/2007.00992 -* SelecSLS - https://arxiv.org/abs/1907.00837 -* Selective Kernel Networks - https://arxiv.org/abs/1903.06586 -* Swin Transformer - https://arxiv.org/abs/2103.14030 -* Transformer-iN-Transformer (TNT) - https://arxiv.org/abs/2103.00112 -* TResNet - https://arxiv.org/abs/2003.13630 -* Twins (Spatial Attention in Vision Transformers) - https://arxiv.org/pdf/2104.13840.pdf -* Vision Transformer - https://arxiv.org/abs/2010.11929 -* VovNet V2 and V1 - https://arxiv.org/abs/1911.06667 -* Xception - https://arxiv.org/abs/1610.02357 -* Xception (Modified Aligned, Gluon) - https://arxiv.org/abs/1802.02611 -* Xception (Modified Aligned, TF) - https://arxiv.org/abs/1802.02611 - -## Features - -Several (less common) features that I often utilize in my projects are included. Many of their additions are the reason why I maintain my own set of models, instead of using others' via PIP: - -* All models have a common default configuration interface and API for - * accessing/changing the classifier - `get_classifier` and `reset_classifier` - * doing a forward pass on just the features - `forward_features` (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) - * these makes it easy to write consistent network wrappers that work with any of the models -* All models support multi-scale feature map extraction (feature pyramids) via create_model (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) - * `create_model(name, features_only=True, out_indices=..., output_stride=...)` - * `out_indices` creation arg specifies which feature maps to return, these indices are 0 based and generally correspond to the `C(i + 1)` feature level. - * `output_stride` creation arg controls output stride of the network by using dilated convolutions. Most networks are stride 32 by default. Not all networks support this. - * feature map channel counts, reduction level (stride) can be queried AFTER model creation via the `.feature_info` member -* All models have a consistent pretrained weight loader that adapts last linear if necessary, and from 3 to 1 channel input if desired -* High performance [reference training, validation, and inference scripts](https://rwightman.github.io/pytorch-image-models/scripts/) that work in several process/GPU modes: - * NVIDIA DDP w/ a single GPU per process, multiple processes with APEX present (AMP mixed-precision optional) - * PyTorch DistributedDataParallel w/ multi-gpu, single process (AMP disabled as it crashes when enabled) - * PyTorch w/ single GPU single process (AMP optional) -* A dynamic global pool implementation that allows selecting from average pooling, max pooling, average + max, or concat([average, max]) at model creation. All global pooling is adaptive average by default and compatible with pretrained weights. -* A 'Test Time Pool' wrapper that can wrap any of the included models and usually provides improved performance doing inference with input images larger than the training size. Idea adapted from original DPN implementation when I ported (https://github.com/cypw/DPNs) -* Learning rate schedulers - * Ideas adopted from - * [AllenNLP schedulers](https://github.com/allenai/allennlp/tree/master/allennlp/training/learning_rate_schedulers) - * [FAIRseq lr_scheduler](https://github.com/pytorch/fairseq/tree/master/fairseq/optim/lr_scheduler) - * SGDR: Stochastic Gradient Descent with Warm Restarts (https://arxiv.org/abs/1608.03983) - * Schedulers include `step`, `cosine` w/ restarts, `tanh` w/ restarts, `plateau` -* Optimizers: - * `rmsprop_tf` adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behaviour. - * `radam` by [Liyuan Liu](https://github.com/LiyuanLucasLiu/RAdam) (https://arxiv.org/abs/1908.03265) - * `novograd` by [Masashi Kimura](https://github.com/convergence-lab/novograd) (https://arxiv.org/abs/1905.11286) - * `lookahead` adapted from impl by [Liam](https://github.com/alphadl/lookahead.pytorch) (https://arxiv.org/abs/1907.08610) - * `fused` optimizers by name with [NVIDIA Apex](https://github.com/NVIDIA/apex/tree/master/apex/optimizers) installed - * `adamp` and `sgdp` by [Naver ClovAI](https://github.com/clovaai) (https://arxiv.org/abs/2006.08217) - * `adafactor` adapted from [FAIRSeq impl](https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py) (https://arxiv.org/abs/1804.04235) - * `adahessian` by [David Samuel](https://github.com/davda54/ada-hessian) (https://arxiv.org/abs/2006.00719) -* Random Erasing from [Zhun Zhong](https://github.com/zhunzhong07/Random-Erasing/blob/master/transforms.py) (https://arxiv.org/abs/1708.04896) -* Mixup (https://arxiv.org/abs/1710.09412) -* CutMix (https://arxiv.org/abs/1905.04899) -* AutoAugment (https://arxiv.org/abs/1805.09501) and RandAugment (https://arxiv.org/abs/1909.13719) ImageNet configurations modeled after impl for EfficientNet training (https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py) -* AugMix w/ JSD loss (https://arxiv.org/abs/1912.02781), JSD w/ clean + augmented mixing support works with AutoAugment and RandAugment as well -* SplitBachNorm - allows splitting batch norm layers between clean and augmented (auxiliary batch norm) data -* DropPath aka "Stochastic Depth" (https://arxiv.org/abs/1603.09382) -* DropBlock (https://arxiv.org/abs/1810.12890) -* Blur Pooling (https://arxiv.org/abs/1904.11486) -* Space-to-Depth by [mrT23](https://github.com/mrT23/TResNet/blob/master/src/models/tresnet/layers/space_to_depth.py) (https://arxiv.org/abs/1801.04590) -- original paper? -* Adaptive Gradient Clipping (https://arxiv.org/abs/2102.06171, https://github.com/deepmind/deepmind-research/tree/master/nfnets) -* An extensive selection of channel and/or spatial attention modules: - * Bottleneck Transformer - https://arxiv.org/abs/2101.11605 - * CBAM - https://arxiv.org/abs/1807.06521 - * Effective Squeeze-Excitation (ESE) - https://arxiv.org/abs/1911.06667 - * Efficient Channel Attention (ECA) - https://arxiv.org/abs/1910.03151 - * Gather-Excite (GE) - https://arxiv.org/abs/1810.12348 - * Global Context (GC) - https://arxiv.org/abs/1904.11492 - * Halo - https://arxiv.org/abs/2103.12731 - * Involution - https://arxiv.org/abs/2103.06255 - * Lambda Layer - https://arxiv.org/abs/2102.08602 - * Non-Local (NL) - https://arxiv.org/abs/1711.07971 - * Squeeze-and-Excitation (SE) - https://arxiv.org/abs/1709.01507 - * Selective Kernel (SK) - (https://arxiv.org/abs/1903.06586 - * Split (SPLAT) - https://arxiv.org/abs/2004.08955 - * Shifted Window (SWIN) - https://arxiv.org/abs/2103.14030 - -## Results - -Model validation results can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/results/) and in the [results tables](results/README.md) - -## Getting Started (Documentation) - -My current [documentation](https://rwightman.github.io/pytorch-image-models/) for `timm` covers the basics. - -[timmdocs](https://fastai.github.io/timmdocs/) is quickly becoming a much more comprehensive set of documentation for `timm`. A big thanks to [Aman Arora](https://github.com/amaarora) for his efforts creating timmdocs. - -[paperswithcode](https://paperswithcode.com/lib/timm) is a good resource for browsing the models within `timm`. - -## Train, Validation, Inference Scripts - -The root folder of the repository contains reference train, validation, and inference scripts that work with the included models and other features of this repository. They are adaptable for other datasets and use cases with a little hacking. See [documentation](https://rwightman.github.io/pytorch-image-models/scripts/) for some basics and [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) for some train examples that produce SOTA ImageNet results. - -## Awesome PyTorch Resources - -One of the greatest assets of PyTorch is the community and their contributions. A few of my favourite resources that pair well with the models and components here are listed below. - -### Object Detection, Instance and Semantic Segmentation -* Detectron2 - https://github.com/facebookresearch/detectron2 -* Segmentation Models (Semantic) - https://github.com/qubvel/segmentation_models.pytorch -* EfficientDet (Obj Det, Semantic soon) - https://github.com/rwightman/efficientdet-pytorch - -### Computer Vision / Image Augmentation -* Albumentations - https://github.com/albumentations-team/albumentations -* Kornia - https://github.com/kornia/kornia - -### Knowledge Distillation -* RepDistiller - https://github.com/HobbitLong/RepDistiller -* torchdistill - https://github.com/yoshitomo-matsubara/torchdistill - -### Metric Learning -* PyTorch Metric Learning - https://github.com/KevinMusgrave/pytorch-metric-learning - -### Training / Frameworks -* fastai - https://github.com/fastai/fastai - -## Licenses - -### Code -The code here is licensed Apache 2.0. I've taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc. I've made an effort to avoid any GPL / LGPL conflicts. That said, it is your responsibility to ensure you comply with licenses here and conditions of any dependent licenses. Where applicable, I've linked the sources/references for various components in docstrings. If you think I've missed anything please create an issue. - -### Pretrained Weights -So far all of the pretrained weights available here are pretrained on ImageNet with a select few that have some additional pretraining (see extra note below). ImageNet was released for non-commercial research purposes only (http://www.image-net.org/download-faq). It's not clear what the implications of that are for the use of pretrained weights from that dataset. Any models I have trained with ImageNet are done for research purposes and one should assume that the original dataset license applies to the weights. It's best to seek legal advice if you intend to use the pretrained weights in a commercial product. - -#### Pretrained on more than ImageNet -Several weights included or references here were pretrained with proprietary datasets that I do not have access to. These include the Facebook WSL, SSL, SWSL ResNe(Xt) and the Google Noisy Student EfficientNet models. The Facebook models have an explicit non-commercial license (CC-BY-NC 4.0, https://github.com/facebookresearch/semi-supervised-ImageNet1K-models, https://github.com/facebookresearch/WSL-Images). The Google models do not appear to have any restriction beyond the Apache 2.0 license (and ImageNet concerns). In either case, you should contact Facebook or Google with any questions. - -## Citing - -### BibTeX - -``` -@misc{rw2019timm, - author = {Ross Wightman}, - title = {PyTorch Image Models}, - year = {2019}, - publisher = {GitHub}, - journal = {GitHub repository}, - doi = {10.5281/zenodo.4414861}, - howpublished = {\url{https://github.com/rwightman/pytorch-image-models}} -} -``` - -### Latest DOI - -[![DOI](https://zenodo.org/badge/168799526.svg)](https://zenodo.org/badge/latestdoi/168799526) + /home/Gluon_ResNet50_v1c_for_PyTorch/test/output/0 \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README_raw.md b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README_raw.md new file mode 100644 index 0000000000000000000000000000000000000000..76261cccf2de722c023d94286b41ea3ec8e0d491 --- /dev/null +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/README_raw.md @@ -0,0 +1,399 @@ +# PyTorch Image Models +- [Sponsors](#sponsors) +- [What's New](#whats-new) +- [Introduction](#introduction) +- [Models](#models) +- [Features](#features) +- [Results](#results) +- [Getting Started (Documentation)](#getting-started-documentation) +- [Train, Validation, Inference Scripts](#train-validation-inference-scripts) +- [Awesome PyTorch Resources](#awesome-pytorch-resources) +- [Licenses](#licenses) +- [Citing](#citing) + +## Sponsors + +A big thank you to my [GitHub Sponsors](https://github.com/sponsors/rwightman) for their support! + +In addition to the sponsors at the link above, I've received hardware and/or cloud resources from +* Nvidia (https://www.nvidia.com/en-us/) +* TFRC (https://www.tensorflow.org/tfrc) + +I'm fortunate to be able to dedicate significant time and money of my own supporting this and other open source projects. However, as the projects increase in scope, outside support is needed to continue with the current trajectory of hardware, infrastructure, and electricty costs. + +## What's New + +### June 20, 2021 +* Release Vision Transformer 'AugReg' weights from [How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers](https://arxiv.org/abs/2106.10270) + * .npz weight loading support added, can load any of the 50K+ weights from the [AugReg series](https://console.cloud.google.com/storage/browser/vit_models/augreg) + * See [example notebook](https://colab.research.google.com/github/google-research/vision_transformer/blob/master/vit_jax_augreg.ipynb) from official impl for navigating the augreg weights + * Replaced all default weights w/ best AugReg variant (if possible). All AugReg 21k classifiers work. + * Highlights: `vit_large_patch16_384` (87.1 top-1), `vit_large_r50_s32_384` (86.2 top-1), `vit_base_patch16_384` (86.0 top-1) + * `vit_deit_*` renamed to just `deit_*` + * Remove my old small model, replace with DeiT compatible small w/ AugReg weights +* Add 1st training of my `gmixer_24_224` MLP /w GLU, 78.1 top-1 w/ 25M params. +* Add weights from official ResMLP release (https://github.com/facebookresearch/deit) +* Add `eca_nfnet_l2` weights from my 'lightweight' series. 84.7 top-1 at 384x384. +* Add distilled BiT 50x1 student and 152x2 Teacher weights from [Knowledge distillation: A good teacher is patient and consistent](https://arxiv.org/abs/2106.05237) +* NFNets and ResNetV2-BiT models work w/ Pytorch XLA now + * weight standardization uses F.batch_norm instead of std_mean (std_mean wasn't lowered) + * eps values adjusted, will be slight differences but should be quite close +* Improve test coverage and classifier interface of non-conv (vision transformer and mlp) models +* Cleanup a few classifier / flatten details for models w/ conv classifiers or early global pool +* Please report any regressions, this PR touched quite a few models. + +### June 8, 2021 +* Add first ResMLP weights, trained in PyTorch XLA on TPU-VM w/ my XLA branch. 24 block variant, 79.2 top-1. +* Add ResNet51-Q model w/ pretrained weights at 82.36 top-1. + * NFNet inspired block layout with quad layer stem and no maxpool + * Same param count (35.7M) and throughput as ResNetRS-50 but +1.5 top-1 @ 224x224 and +2.5 top-1 at 288x288 + +### May 25, 2021 +* Add LeViT, Visformer, ConViT (PR by Aman Arora), Twins (PR by paper authors) transformer models +* Add ResMLP and gMLP MLP vision models to the existing MLP Mixer impl +* Fix a number of torchscript issues with various vision transformer models +* Cleanup input_size/img_size override handling and improve testing / test coverage for all vision transformer and MLP models +* More flexible pos embedding resize (non-square) for ViT and TnT. Thanks [Alexander Soare](https://github.com/alexander-soare) +* Add `efficientnetv2_rw_m` model and weights (started training before official code). 84.8 top-1, 53M params. + +### May 14, 2021 +* Add EfficientNet-V2 official model defs w/ ported weights from official [Tensorflow/Keras](https://github.com/google/automl/tree/master/efficientnetv2) impl. + * 1k trained variants: `tf_efficientnetv2_s/m/l` + * 21k trained variants: `tf_efficientnetv2_s/m/l_in21k` + * 21k pretrained -> 1k fine-tuned: `tf_efficientnetv2_s/m/l_in21ft1k` + * v2 models w/ v1 scaling: `tf_efficientnetv2_b0` through `b3` + * Rename my prev V2 guess `efficientnet_v2s` -> `efficientnetv2_rw_s` + * Some blank `efficientnetv2_*` models in-place for future native PyTorch training + +### May 5, 2021 +* Add MLP-Mixer models and port pretrained weights from [Google JAX impl](https://github.com/google-research/vision_transformer/tree/linen) +* Add CaiT models and pretrained weights from [FB](https://github.com/facebookresearch/deit) +* Add ResNet-RS models and weights from [TF](https://github.com/tensorflow/tpu/tree/master/models/official/resnet/resnet_rs). Thanks [Aman Arora](https://github.com/amaarora) +* Add CoaT models and weights. Thanks [Mohammed Rizin](https://github.com/morizin) +* Add new ImageNet-21k weights & finetuned weights for TResNet, MobileNet-V3, ViT models. Thanks [mrT](https://github.com/mrT23) +* Add GhostNet models and weights. Thanks [Kai Han](https://github.com/iamhankai) +* Update ByoaNet attention modules + * Improve SA module inits + * Hack together experimental stand-alone Swin based attn module and `swinnet` + * Consistent '26t' model defs for experiments. +* Add improved Efficientnet-V2S (prelim model def) weights. 83.8 top-1. +* WandB logging support + +### April 13, 2021 +* Add Swin Transformer models and weights from https://github.com/microsoft/Swin-Transformer + +### April 12, 2021 +* Add ECA-NFNet-L1 (slimmed down F1 w/ SiLU, 41M params) trained with this code. 84% top-1 @ 320x320. Trained at 256x256. +* Add EfficientNet-V2S model (unverified model definition) weights. 83.3 top-1 @ 288x288. Only trained single res 224. Working on progressive training. +* Add ByoaNet model definition (Bring-your-own-attention) w/ SelfAttention block and corresponding SA/SA-like modules and model defs + * Lambda Networks - https://arxiv.org/abs/2102.08602 + * Bottleneck Transformers - https://arxiv.org/abs/2101.11605 + * Halo Nets - https://arxiv.org/abs/2103.12731 +* Adabelief optimizer contributed by Juntang Zhuang + +### April 1, 2021 +* Add snazzy `benchmark.py` script for bulk `timm` model benchmarking of train and/or inference +* Add Pooling-based Vision Transformer (PiT) models (from https://github.com/naver-ai/pit) + * Merged distilled variant into main for torchscript compatibility + * Some `timm` cleanup/style tweaks and weights have hub download support +* Cleanup Vision Transformer (ViT) models + * Merge distilled (DeiT) model into main so that torchscript can work + * Support updated weight init (defaults to old still) that closer matches original JAX impl (possibly better training from scratch) + * Separate hybrid model defs into different file and add several new model defs to fiddle with, support patch_size != 1 for hybrids + * Fix fine-tuning num_class changes (PiT and ViT) and pos_embed resizing (Vit) with distilled variants + * nn.Sequential for block stack (does not break downstream compat) +* TnT (Transformer-in-Transformer) models contributed by author (from https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/cv/TNT) +* Add RegNetY-160 weights from DeiT teacher model +* Add new NFNet-L0 w/ SE attn (rename `nfnet_l0b`->`nfnet_l0`) weights 82.75 top-1 @ 288x288 +* Some fixes/improvements for TFDS dataset wrapper + +### March 17, 2021 +* Add new ECA-NFNet-L0 (rename `nfnet_l0c`->`eca_nfnet_l0`) weights trained by myself. + * 82.6 top-1 @ 288x288, 82.8 @ 320x320, trained at 224x224 + * Uses SiLU activation, approx 2x faster than `dm_nfnet_f0` and 50% faster than `nfnet_f0s` w/ 1/3 param count +* Integrate [Hugging Face model hub](https://huggingface.co/models) into timm create_model and default_cfg handling for pretrained weight and config sharing (more on this soon!) +* Merge HardCoRe NAS models contributed by https://github.com/yoniaflalo +* Merge PyTorch trained EfficientNet-EL and pruned ES/EL variants contributed by [DeGirum](https://github.com/DeGirum) + + +### March 7, 2021 +* First 0.4.x PyPi release w/ NFNets (& related), ByoB (GPU-Efficient, RepVGG, etc). +* Change feature extraction for pre-activation nets (NFNets, ResNetV2) to return features before activation. +* Tested with PyTorch 1.8 release. Updated CI to use 1.8. +* Benchmarked several arch on RTX 3090, Titan RTX, and V100 across 1.7.1, 1.8, NGC 20.12, and 21.02. Some interesting performance variations to take note of https://gist.github.com/rwightman/bb59f9e245162cee0e38bd66bd8cd77f + +### Feb 18, 2021 +* Add pretrained weights and model variants for NFNet-F* models from [DeepMind Haiku impl](https://github.com/deepmind/deepmind-research/tree/master/nfnets). + * Models are prefixed with `dm_`. They require SAME padding conv, skipinit enabled, and activation gains applied in act fn. + * These models are big, expect to run out of GPU memory. With the GELU activiation + other options, they are roughly 1/2 the inference speed of my SiLU PyTorch optimized `s` variants. + * Original model results are based on pre-processing that is not the same as all other models so you'll see different results in the results csv (once updated). + * Matching the original pre-processing as closely as possible I get these results: + * `dm_nfnet_f6` - 86.352 + * `dm_nfnet_f5` - 86.100 + * `dm_nfnet_f4` - 85.834 + * `dm_nfnet_f3` - 85.676 + * `dm_nfnet_f2` - 85.178 + * `dm_nfnet_f1` - 84.696 + * `dm_nfnet_f0` - 83.464 + +### Feb 16, 2021 +* Add Adaptive Gradient Clipping (AGC) as per https://arxiv.org/abs/2102.06171. Integrated w/ PyTorch gradient clipping via mode arg that defaults to prev 'norm' mode. For backward arg compat, clip-grad arg must be specified to enable when using train.py. + * AGC w/ default clipping factor `--clip-grad .01 --clip-mode agc` + * PyTorch global norm of 1.0 (old behaviour, always norm), `--clip-grad 1.0` + * PyTorch value clipping of 10, `--clip-grad 10. --clip-mode value` + * AGC performance is definitely sensitive to the clipping factor. More experimentation needed to determine good values for smaller batch sizes and optimizers besides those in paper. So far I've found .001-.005 is necessary for stable RMSProp training w/ NFNet/NF-ResNet. + +### Feb 12, 2021 +* Update Normalization-Free nets to include new NFNet-F (https://arxiv.org/abs/2102.06171) model defs + +### Feb 10, 2021 +* First Normalization-Free model training experiments done, + * nf_resnet50 - 80.68 top-1 @ 288x288, 80.31 @ 256x256 + * nf_regnet_b1 - 79.30 @ 288x288, 78.75 @ 256x256 +* More model archs, incl a flexible ByobNet backbone ('Bring-your-own-blocks') + * GPU-Efficient-Networks (https://github.com/idstcv/GPU-Efficient-Networks), impl in `byobnet.py` + * RepVGG (https://github.com/DingXiaoH/RepVGG), impl in `byobnet.py` + * classic VGG (from torchvision, impl in `vgg.py`) +* Refinements to normalizer layer arg handling and normalizer+act layer handling in some models +* Default AMP mode changed to native PyTorch AMP instead of APEX. Issues not being fixed with APEX. Native works with `--channels-last` and `--torchscript` model training, APEX does not. +* Fix a few bugs introduced since last pypi release + +### Feb 8, 2021 +* Add several ResNet weights with ECA attention. 26t & 50t trained @ 256, test @ 320. 269d train @ 256, fine-tune @320, test @ 352. + * `ecaresnet26t` - 79.88 top-1 @ 320x320, 79.08 @ 256x256 + * `ecaresnet50t` - 82.35 top-1 @ 320x320, 81.52 @ 256x256 + * `ecaresnet269d` - 84.93 top-1 @ 352x352, 84.87 @ 320x320 +* Remove separate tiered (`t`) vs tiered_narrow (`tn`) ResNet model defs, all `tn` changed to `t` and `t` models removed (`seresnext26t_32x4d` only model w/ weights that was removed). +* Support model default_cfgs with separate train vs test resolution `test_input_size` and remove extra `_320` suffix ResNet model defs that were just for test. + +### Jan 30, 2021 +* Add initial "Normalization Free" NF-RegNet-B* and NF-ResNet model definitions based on [paper](https://arxiv.org/abs/2101.08692) + +### Jan 25, 2021 +* Add ResNetV2 Big Transfer (BiT) models w/ ImageNet-1k and 21k weights from https://github.com/google-research/big_transfer +* Add official R50+ViT-B/16 hybrid models + weights from https://github.com/google-research/vision_transformer +* ImageNet-21k ViT weights are added w/ model defs and representation layer (pre logits) support + * NOTE: ImageNet-21k classifier heads were zero'd in original weights, they are only useful for transfer learning +* Add model defs and weights for DeiT Vision Transformer models from https://github.com/facebookresearch/deit +* Refactor dataset classes into ImageDataset/IterableImageDataset + dataset specific parser classes +* Add Tensorflow-Datasets (TFDS) wrapper to allow use of TFDS image classification sets with train script + * Ex: `train.py /data/tfds --dataset tfds/oxford_iiit_pet --val-split test --model resnet50 -b 256 --amp --num-classes 37 --opt adamw --lr 3e-4 --weight-decay .001 --pretrained -j 2` +* Add improved .tar dataset parser that reads images from .tar, folder of .tar files, or .tar within .tar + * Run validation on full ImageNet-21k directly from tar w/ BiT model: `validate.py /data/fall11_whole.tar --model resnetv2_50x1_bitm_in21k --amp` +* Models in this update should be stable w/ possible exception of ViT/BiT, possibility of some regressions with train/val scripts and dataset handling + +### Jan 3, 2021 +* Add SE-ResNet-152D weights + * 256x256 val, 0.94 crop top-1 - 83.75 + * 320x320 val, 1.0 crop - 84.36 +* Update [results files](results/) + + +## Introduction + +Py**T**orch **Im**age **M**odels (`timm`) is a collection of image models, layers, utilities, optimizers, schedulers, data-loaders / augmentations, and reference training / validation scripts that aim to pull together a wide variety of SOTA models with ability to reproduce ImageNet training results. + +The work of many others is present here. I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code docstrings. Please let me know if I missed anything. + +## Models + +All model architecture families include variants with pretrained weights. There are specific model variants without any weights, it is NOT a bug. Help training new or better weights is always appreciated. Here are some example [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) to get you started. + +A full version of the list below with source links can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/models/). + +* Big Transfer ResNetV2 (BiT) - https://arxiv.org/abs/1912.11370 +* Bottleneck Transformers - https://arxiv.org/abs/2101.11605 +* CaiT (Class-Attention in Image Transformers) - https://arxiv.org/abs/2103.17239 +* CoaT (Co-Scale Conv-Attentional Image Transformers) - https://arxiv.org/abs/2104.06399 +* ConViT (Soft Convolutional Inductive Biases Vision Transformers)- https://arxiv.org/abs/2103.10697 +* CspNet (Cross-Stage Partial Networks) - https://arxiv.org/abs/1911.11929 +* DeiT (Vision Transformer) - https://arxiv.org/abs/2012.12877 +* DenseNet - https://arxiv.org/abs/1608.06993 +* DLA - https://arxiv.org/abs/1707.06484 +* DPN (Dual-Path Network) - https://arxiv.org/abs/1707.01629 +* EfficientNet (MBConvNet Family) + * EfficientNet NoisyStudent (B0-B7, L2) - https://arxiv.org/abs/1911.04252 + * EfficientNet AdvProp (B0-B8) - https://arxiv.org/abs/1911.09665 + * EfficientNet (B0-B7) - https://arxiv.org/abs/1905.11946 + * EfficientNet-EdgeTPU (S, M, L) - https://ai.googleblog.com/2019/08/efficientnet-edgetpu-creating.html + * EfficientNet V2 - https://arxiv.org/abs/2104.00298 + * FBNet-C - https://arxiv.org/abs/1812.03443 + * MixNet - https://arxiv.org/abs/1907.09595 + * MNASNet B1, A1 (Squeeze-Excite), and Small - https://arxiv.org/abs/1807.11626 + * MobileNet-V2 - https://arxiv.org/abs/1801.04381 + * Single-Path NAS - https://arxiv.org/abs/1904.02877 +* GhostNet - https://arxiv.org/abs/1911.11907 +* gMLP - https://arxiv.org/abs/2105.08050 +* GPU-Efficient Networks - https://arxiv.org/abs/2006.14090 +* Halo Nets - https://arxiv.org/abs/2103.12731 +* HardCoRe-NAS - https://arxiv.org/abs/2102.11646 +* HRNet - https://arxiv.org/abs/1908.07919 +* Inception-V3 - https://arxiv.org/abs/1512.00567 +* Inception-ResNet-V2 and Inception-V4 - https://arxiv.org/abs/1602.07261 +* Lambda Networks - https://arxiv.org/abs/2102.08602 +* LeViT (Vision Transformer in ConvNet's Clothing) - https://arxiv.org/abs/2104.01136 +* MLP-Mixer - https://arxiv.org/abs/2105.01601 +* MobileNet-V3 (MBConvNet w/ Efficient Head) - https://arxiv.org/abs/1905.02244 +* NASNet-A - https://arxiv.org/abs/1707.07012 +* NFNet-F - https://arxiv.org/abs/2102.06171 +* NF-RegNet / NF-ResNet - https://arxiv.org/abs/2101.08692 +* PNasNet - https://arxiv.org/abs/1712.00559 +* Pooling-based Vision Transformer (PiT) - https://arxiv.org/abs/2103.16302 +* RegNet - https://arxiv.org/abs/2003.13678 +* RepVGG - https://arxiv.org/abs/2101.03697 +* ResMLP - https://arxiv.org/abs/2105.03404 +* ResNet/ResNeXt + * ResNet (v1b/v1.5) - https://arxiv.org/abs/1512.03385 + * ResNeXt - https://arxiv.org/abs/1611.05431 + * 'Bag of Tricks' / Gluon C, D, E, S variations - https://arxiv.org/abs/1812.01187 + * Weakly-supervised (WSL) Instagram pretrained / ImageNet tuned ResNeXt101 - https://arxiv.org/abs/1805.00932 + * Semi-supervised (SSL) / Semi-weakly Supervised (SWSL) ResNet/ResNeXts - https://arxiv.org/abs/1905.00546 + * ECA-Net (ECAResNet) - https://arxiv.org/abs/1910.03151v4 + * Squeeze-and-Excitation Networks (SEResNet) - https://arxiv.org/abs/1709.01507 + * ResNet-RS - https://arxiv.org/abs/2103.07579 +* Res2Net - https://arxiv.org/abs/1904.01169 +* ResNeSt - https://arxiv.org/abs/2004.08955 +* ReXNet - https://arxiv.org/abs/2007.00992 +* SelecSLS - https://arxiv.org/abs/1907.00837 +* Selective Kernel Networks - https://arxiv.org/abs/1903.06586 +* Swin Transformer - https://arxiv.org/abs/2103.14030 +* Transformer-iN-Transformer (TNT) - https://arxiv.org/abs/2103.00112 +* TResNet - https://arxiv.org/abs/2003.13630 +* Twins (Spatial Attention in Vision Transformers) - https://arxiv.org/pdf/2104.13840.pdf +* Vision Transformer - https://arxiv.org/abs/2010.11929 +* VovNet V2 and V1 - https://arxiv.org/abs/1911.06667 +* Xception - https://arxiv.org/abs/1610.02357 +* Xception (Modified Aligned, Gluon) - https://arxiv.org/abs/1802.02611 +* Xception (Modified Aligned, TF) - https://arxiv.org/abs/1802.02611 + +## Features + +Several (less common) features that I often utilize in my projects are included. Many of their additions are the reason why I maintain my own set of models, instead of using others' via PIP: + +* All models have a common default configuration interface and API for + * accessing/changing the classifier - `get_classifier` and `reset_classifier` + * doing a forward pass on just the features - `forward_features` (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) + * these makes it easy to write consistent network wrappers that work with any of the models +* All models support multi-scale feature map extraction (feature pyramids) via create_model (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) + * `create_model(name, features_only=True, out_indices=..., output_stride=...)` + * `out_indices` creation arg specifies which feature maps to return, these indices are 0 based and generally correspond to the `C(i + 1)` feature level. + * `output_stride` creation arg controls output stride of the network by using dilated convolutions. Most networks are stride 32 by default. Not all networks support this. + * feature map channel counts, reduction level (stride) can be queried AFTER model creation via the `.feature_info` member +* All models have a consistent pretrained weight loader that adapts last linear if necessary, and from 3 to 1 channel input if desired +* High performance [reference training, validation, and inference scripts](https://rwightman.github.io/pytorch-image-models/scripts/) that work in several process/GPU modes: + * NVIDIA DDP w/ a single GPU per process, multiple processes with APEX present (AMP mixed-precision optional) + * PyTorch DistributedDataParallel w/ multi-gpu, single process (AMP disabled as it crashes when enabled) + * PyTorch w/ single GPU single process (AMP optional) +* A dynamic global pool implementation that allows selecting from average pooling, max pooling, average + max, or concat([average, max]) at model creation. All global pooling is adaptive average by default and compatible with pretrained weights. +* A 'Test Time Pool' wrapper that can wrap any of the included models and usually provides improved performance doing inference with input images larger than the training size. Idea adapted from original DPN implementation when I ported (https://github.com/cypw/DPNs) +* Learning rate schedulers + * Ideas adopted from + * [AllenNLP schedulers](https://github.com/allenai/allennlp/tree/master/allennlp/training/learning_rate_schedulers) + * [FAIRseq lr_scheduler](https://github.com/pytorch/fairseq/tree/master/fairseq/optim/lr_scheduler) + * SGDR: Stochastic Gradient Descent with Warm Restarts (https://arxiv.org/abs/1608.03983) + * Schedulers include `step`, `cosine` w/ restarts, `tanh` w/ restarts, `plateau` +* Optimizers: + * `rmsprop_tf` adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behaviour. + * `radam` by [Liyuan Liu](https://github.com/LiyuanLucasLiu/RAdam) (https://arxiv.org/abs/1908.03265) + * `novograd` by [Masashi Kimura](https://github.com/convergence-lab/novograd) (https://arxiv.org/abs/1905.11286) + * `lookahead` adapted from impl by [Liam](https://github.com/alphadl/lookahead.pytorch) (https://arxiv.org/abs/1907.08610) + * `fused` optimizers by name with [NVIDIA Apex](https://github.com/NVIDIA/apex/tree/master/apex/optimizers) installed + * `adamp` and `sgdp` by [Naver ClovAI](https://github.com/clovaai) (https://arxiv.org/abs/2006.08217) + * `adafactor` adapted from [FAIRSeq impl](https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py) (https://arxiv.org/abs/1804.04235) + * `adahessian` by [David Samuel](https://github.com/davda54/ada-hessian) (https://arxiv.org/abs/2006.00719) +* Random Erasing from [Zhun Zhong](https://github.com/zhunzhong07/Random-Erasing/blob/master/transforms.py) (https://arxiv.org/abs/1708.04896) +* Mixup (https://arxiv.org/abs/1710.09412) +* CutMix (https://arxiv.org/abs/1905.04899) +* AutoAugment (https://arxiv.org/abs/1805.09501) and RandAugment (https://arxiv.org/abs/1909.13719) ImageNet configurations modeled after impl for EfficientNet training (https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py) +* AugMix w/ JSD loss (https://arxiv.org/abs/1912.02781), JSD w/ clean + augmented mixing support works with AutoAugment and RandAugment as well +* SplitBachNorm - allows splitting batch norm layers between clean and augmented (auxiliary batch norm) data +* DropPath aka "Stochastic Depth" (https://arxiv.org/abs/1603.09382) +* DropBlock (https://arxiv.org/abs/1810.12890) +* Blur Pooling (https://arxiv.org/abs/1904.11486) +* Space-to-Depth by [mrT23](https://github.com/mrT23/TResNet/blob/master/src/models/tresnet/layers/space_to_depth.py) (https://arxiv.org/abs/1801.04590) -- original paper? +* Adaptive Gradient Clipping (https://arxiv.org/abs/2102.06171, https://github.com/deepmind/deepmind-research/tree/master/nfnets) +* An extensive selection of channel and/or spatial attention modules: + * Bottleneck Transformer - https://arxiv.org/abs/2101.11605 + * CBAM - https://arxiv.org/abs/1807.06521 + * Effective Squeeze-Excitation (ESE) - https://arxiv.org/abs/1911.06667 + * Efficient Channel Attention (ECA) - https://arxiv.org/abs/1910.03151 + * Gather-Excite (GE) - https://arxiv.org/abs/1810.12348 + * Global Context (GC) - https://arxiv.org/abs/1904.11492 + * Halo - https://arxiv.org/abs/2103.12731 + * Involution - https://arxiv.org/abs/2103.06255 + * Lambda Layer - https://arxiv.org/abs/2102.08602 + * Non-Local (NL) - https://arxiv.org/abs/1711.07971 + * Squeeze-and-Excitation (SE) - https://arxiv.org/abs/1709.01507 + * Selective Kernel (SK) - (https://arxiv.org/abs/1903.06586 + * Split (SPLAT) - https://arxiv.org/abs/2004.08955 + * Shifted Window (SWIN) - https://arxiv.org/abs/2103.14030 + +## Results + +Model validation results can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/results/) and in the [results tables](results/README.md) + +## Getting Started (Documentation) + +My current [documentation](https://rwightman.github.io/pytorch-image-models/) for `timm` covers the basics. + +[timmdocs](https://fastai.github.io/timmdocs/) is quickly becoming a much more comprehensive set of documentation for `timm`. A big thanks to [Aman Arora](https://github.com/amaarora) for his efforts creating timmdocs. + +[paperswithcode](https://paperswithcode.com/lib/timm) is a good resource for browsing the models within `timm`. + +## Train, Validation, Inference Scripts + +The root folder of the repository contains reference train, validation, and inference scripts that work with the included models and other features of this repository. They are adaptable for other datasets and use cases with a little hacking. See [documentation](https://rwightman.github.io/pytorch-image-models/scripts/) for some basics and [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) for some train examples that produce SOTA ImageNet results. + +## Awesome PyTorch Resources + +One of the greatest assets of PyTorch is the community and their contributions. A few of my favourite resources that pair well with the models and components here are listed below. + +### Object Detection, Instance and Semantic Segmentation +* Detectron2 - https://github.com/facebookresearch/detectron2 +* Segmentation Models (Semantic) - https://github.com/qubvel/segmentation_models.pytorch +* EfficientDet (Obj Det, Semantic soon) - https://github.com/rwightman/efficientdet-pytorch + +### Computer Vision / Image Augmentation +* Albumentations - https://github.com/albumentations-team/albumentations +* Kornia - https://github.com/kornia/kornia + +### Knowledge Distillation +* RepDistiller - https://github.com/HobbitLong/RepDistiller +* torchdistill - https://github.com/yoshitomo-matsubara/torchdistill + +### Metric Learning +* PyTorch Metric Learning - https://github.com/KevinMusgrave/pytorch-metric-learning + +### Training / Frameworks +* fastai - https://github.com/fastai/fastai + +## Licenses + +### Code +The code here is licensed Apache 2.0. I've taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc. I've made an effort to avoid any GPL / LGPL conflicts. That said, it is your responsibility to ensure you comply with licenses here and conditions of any dependent licenses. Where applicable, I've linked the sources/references for various components in docstrings. If you think I've missed anything please create an issue. + +### Pretrained Weights +So far all of the pretrained weights available here are pretrained on ImageNet with a select few that have some additional pretraining (see extra note below). ImageNet was released for non-commercial research purposes only (http://www.image-net.org/download-faq). It's not clear what the implications of that are for the use of pretrained weights from that dataset. Any models I have trained with ImageNet are done for research purposes and one should assume that the original dataset license applies to the weights. It's best to seek legal advice if you intend to use the pretrained weights in a commercial product. + +#### Pretrained on more than ImageNet +Several weights included or references here were pretrained with proprietary datasets that I do not have access to. These include the Facebook WSL, SSL, SWSL ResNe(Xt) and the Google Noisy Student EfficientNet models. The Facebook models have an explicit non-commercial license (CC-BY-NC 4.0, https://github.com/facebookresearch/semi-supervised-ImageNet1K-models, https://github.com/facebookresearch/WSL-Images). The Google models do not appear to have any restriction beyond the Apache 2.0 license (and ImageNet concerns). In either case, you should contact Facebook or Google with any questions. + +## Citing + +### BibTeX + +``` +@misc{rw2019timm, + author = {Ross Wightman}, + title = {PyTorch Image Models}, + year = {2019}, + publisher = {GitHub}, + journal = {GitHub repository}, + doi = {10.5281/zenodo.4414861}, + howpublished = {\url{https://github.com/rwightman/pytorch-image-models}} +} +``` + +### Latest DOI + +[![DOI](https://zenodo.org/badge/168799526.svg)](https://zenodo.org/badge/latestdoi/168799526) diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_1p.sh index 4270119d12ae9230d36987599968921921fdfb43..0985f163ee63662daf7907377caa930185a5dd46 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_1p.sh @@ -74,10 +74,16 @@ fi #################启动训练脚本################# #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh -python3 train.py \ +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + + +nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1c \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_8p.sh index f52176cfcda2b3c21df489b1e5aa2a1a79b93034..bf6c5f742dbf9db3fa988b9df134970a8da2ee16 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_full_8p.sh @@ -63,12 +63,18 @@ fi #################启动训练脚本################# # 训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + for i in $(seq 0 7) do - python3 train.py \ + nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1c \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_1p.sh index dcdf1e17e4ec12444b8d2c6011180e09ecde8fd8..04c2d333b4f16468c19c99cd3679cbd917c40464 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_1p.sh @@ -47,8 +47,6 @@ else exit 1 fi - - ###############指定训练脚本执行路径############### # cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 cur_path=`pwd` @@ -61,7 +59,6 @@ else test_path_dir=${cur_path}/test fi - #################创建日志输出目录,不需要修改################# if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} @@ -74,10 +71,15 @@ fi #################启动训练脚本################# #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh -python3 train.py \ +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1c \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_8p.sh index 1d634eed55e7cf1fa009984a9909e91e67c9c9c6..c32a993a6409ac0a955674959b63ea01908e59f7 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch/test/train_performance_8p.sh @@ -63,12 +63,17 @@ fi #################启动训练脚本################# # 训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + for i in $(seq 0 7) do - python3 train.py \ + nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1c \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README.md b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README.md index 76261cccf2de722c023d94286b41ea3ec8e0d491..c3df4f61b972928c330b5aad3e0df824543b9e29 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README.md @@ -1,399 +1,37 @@ -# PyTorch Image Models -- [Sponsors](#sponsors) -- [What's New](#whats-new) -- [Introduction](#introduction) -- [Models](#models) -- [Features](#features) -- [Results](#results) -- [Getting Started (Documentation)](#getting-started-documentation) -- [Train, Validation, Inference Scripts](#train-validation-inference-scripts) -- [Awesome PyTorch Resources](#awesome-pytorch-resources) -- [Licenses](#licenses) -- [Citing](#citing) +一、训练流程: + -## Sponsors +单卡训练流程: -A big thank you to my [GitHub Sponsors](https://github.com/sponsors/rwightman) for their support! + 1.安装环境 + 2.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 -In addition to the sponsors at the link above, I've received hardware and/or cloud resources from -* Nvidia (https://www.nvidia.com/en-us/) -* TFRC (https://www.tensorflow.org/tfrc) + +多卡训练流程 -I'm fortunate to be able to dedicate significant time and money of my own supporting this and other open source projects. However, as the projects increase in scope, outside support is needed to continue with the current trajectory of hardware, infrastructure, and electricty costs. + 1.安装环境 + 2.开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 -## What's New -### June 20, 2021 -* Release Vision Transformer 'AugReg' weights from [How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers](https://arxiv.org/abs/2106.10270) - * .npz weight loading support added, can load any of the 50K+ weights from the [AugReg series](https://console.cloud.google.com/storage/browser/vit_models/augreg) - * See [example notebook](https://colab.research.google.com/github/google-research/vision_transformer/blob/master/vit_jax_augreg.ipynb) from official impl for navigating the augreg weights - * Replaced all default weights w/ best AugReg variant (if possible). All AugReg 21k classifiers work. - * Highlights: `vit_large_patch16_384` (87.1 top-1), `vit_large_r50_s32_384` (86.2 top-1), `vit_base_patch16_384` (86.0 top-1) - * `vit_deit_*` renamed to just `deit_*` - * Remove my old small model, replace with DeiT compatible small w/ AugReg weights -* Add 1st training of my `gmixer_24_224` MLP /w GLU, 78.1 top-1 w/ 25M params. -* Add weights from official ResMLP release (https://github.com/facebookresearch/deit) -* Add `eca_nfnet_l2` weights from my 'lightweight' series. 84.7 top-1 at 384x384. -* Add distilled BiT 50x1 student and 152x2 Teacher weights from [Knowledge distillation: A good teacher is patient and consistent](https://arxiv.org/abs/2106.05237) -* NFNets and ResNetV2-BiT models work w/ Pytorch XLA now - * weight standardization uses F.batch_norm instead of std_mean (std_mean wasn't lowered) - * eps values adjusted, will be slight differences but should be quite close -* Improve test coverage and classifier interface of non-conv (vision transformer and mlp) models -* Cleanup a few classifier / flatten details for models w/ conv classifiers or early global pool -* Please report any regressions, this PR touched quite a few models. + +二、Docker容器训练: + +1.导入镜像二进制包docker import ubuntuarmpytorch.tar REPOSITORY:TAG, 比如: -### June 8, 2021 -* Add first ResMLP weights, trained in PyTorch XLA on TPU-VM w/ my XLA branch. 24 block variant, 79.2 top-1. -* Add ResNet51-Q model w/ pretrained weights at 82.36 top-1. - * NFNet inspired block layout with quad layer stem and no maxpool - * Same param count (35.7M) and throughput as ResNetRS-50 but +1.5 top-1 @ 224x224 and +2.5 top-1 at 288x288 + docker import ubuntuarmpytorch.tar pytorch:b020 -### May 25, 2021 -* Add LeViT, Visformer, ConViT (PR by Aman Arora), Twins (PR by paper authors) transformer models -* Add ResMLP and gMLP MLP vision models to the existing MLP Mixer impl -* Fix a number of torchscript issues with various vision transformer models -* Cleanup input_size/img_size override handling and improve testing / test coverage for all vision transformer and MLP models -* More flexible pos embedding resize (non-square) for ViT and TnT. Thanks [Alexander Soare](https://github.com/alexander-soare) -* Add `efficientnetv2_rw_m` model and weights (started training before official code). 84.8 top-1, 53M params. +2.执行docker_start.sh后带三个参数:步骤1生成的REPOSITORY:TAG;数据集路径;模型执行路径;比如: -### May 14, 2021 -* Add EfficientNet-V2 official model defs w/ ported weights from official [Tensorflow/Keras](https://github.com/google/automl/tree/master/efficientnetv2) impl. - * 1k trained variants: `tf_efficientnetv2_s/m/l` - * 21k trained variants: `tf_efficientnetv2_s/m/l_in21k` - * 21k pretrained -> 1k fine-tuned: `tf_efficientnetv2_s/m/l_in21ft1k` - * v2 models w/ v1 scaling: `tf_efficientnetv2_b0` through `b3` - * Rename my prev V2 guess `efficientnet_v2s` -> `efficientnetv2_rw_s` - * Some blank `efficientnetv2_*` models in-place for future native PyTorch training + ./docker_start.sh pytorch:b020 /train/imagenet /home/Gluon_ResNet50_v1c_for_PyTorch -### May 5, 2021 -* Add MLP-Mixer models and port pretrained weights from [Google JAX impl](https://github.com/google-research/vision_transformer/tree/linen) -* Add CaiT models and pretrained weights from [FB](https://github.com/facebookresearch/deit) -* Add ResNet-RS models and weights from [TF](https://github.com/tensorflow/tpu/tree/master/models/official/resnet/resnet_rs). Thanks [Aman Arora](https://github.com/amaarora) -* Add CoaT models and weights. Thanks [Mohammed Rizin](https://github.com/morizin) -* Add new ImageNet-21k weights & finetuned weights for TResNet, MobileNet-V3, ViT models. Thanks [mrT](https://github.com/mrT23) -* Add GhostNet models and weights. Thanks [Kai Han](https://github.com/iamhankai) -* Update ByoaNet attention modules - * Improve SA module inits - * Hack together experimental stand-alone Swin based attn module and `swinnet` - * Consistent '26t' model defs for experiments. -* Add improved Efficientnet-V2S (prelim model def) weights. 83.8 top-1. -* WandB logging support +3.执行步骤一训练流程(环境安装除外) + +三、测试结果 + +训练日志路径:在训练脚本的同目录下result文件夹里,如: -### April 13, 2021 -* Add Swin Transformer models and weights from https://github.com/microsoft/Swin-Transformer - -### April 12, 2021 -* Add ECA-NFNet-L1 (slimmed down F1 w/ SiLU, 41M params) trained with this code. 84% top-1 @ 320x320. Trained at 256x256. -* Add EfficientNet-V2S model (unverified model definition) weights. 83.3 top-1 @ 288x288. Only trained single res 224. Working on progressive training. -* Add ByoaNet model definition (Bring-your-own-attention) w/ SelfAttention block and corresponding SA/SA-like modules and model defs - * Lambda Networks - https://arxiv.org/abs/2102.08602 - * Bottleneck Transformers - https://arxiv.org/abs/2101.11605 - * Halo Nets - https://arxiv.org/abs/2103.12731 -* Adabelief optimizer contributed by Juntang Zhuang - -### April 1, 2021 -* Add snazzy `benchmark.py` script for bulk `timm` model benchmarking of train and/or inference -* Add Pooling-based Vision Transformer (PiT) models (from https://github.com/naver-ai/pit) - * Merged distilled variant into main for torchscript compatibility - * Some `timm` cleanup/style tweaks and weights have hub download support -* Cleanup Vision Transformer (ViT) models - * Merge distilled (DeiT) model into main so that torchscript can work - * Support updated weight init (defaults to old still) that closer matches original JAX impl (possibly better training from scratch) - * Separate hybrid model defs into different file and add several new model defs to fiddle with, support patch_size != 1 for hybrids - * Fix fine-tuning num_class changes (PiT and ViT) and pos_embed resizing (Vit) with distilled variants - * nn.Sequential for block stack (does not break downstream compat) -* TnT (Transformer-in-Transformer) models contributed by author (from https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/cv/TNT) -* Add RegNetY-160 weights from DeiT teacher model -* Add new NFNet-L0 w/ SE attn (rename `nfnet_l0b`->`nfnet_l0`) weights 82.75 top-1 @ 288x288 -* Some fixes/improvements for TFDS dataset wrapper - -### March 17, 2021 -* Add new ECA-NFNet-L0 (rename `nfnet_l0c`->`eca_nfnet_l0`) weights trained by myself. - * 82.6 top-1 @ 288x288, 82.8 @ 320x320, trained at 224x224 - * Uses SiLU activation, approx 2x faster than `dm_nfnet_f0` and 50% faster than `nfnet_f0s` w/ 1/3 param count -* Integrate [Hugging Face model hub](https://huggingface.co/models) into timm create_model and default_cfg handling for pretrained weight and config sharing (more on this soon!) -* Merge HardCoRe NAS models contributed by https://github.com/yoniaflalo -* Merge PyTorch trained EfficientNet-EL and pruned ES/EL variants contributed by [DeGirum](https://github.com/DeGirum) - - -### March 7, 2021 -* First 0.4.x PyPi release w/ NFNets (& related), ByoB (GPU-Efficient, RepVGG, etc). -* Change feature extraction for pre-activation nets (NFNets, ResNetV2) to return features before activation. -* Tested with PyTorch 1.8 release. Updated CI to use 1.8. -* Benchmarked several arch on RTX 3090, Titan RTX, and V100 across 1.7.1, 1.8, NGC 20.12, and 21.02. Some interesting performance variations to take note of https://gist.github.com/rwightman/bb59f9e245162cee0e38bd66bd8cd77f - -### Feb 18, 2021 -* Add pretrained weights and model variants for NFNet-F* models from [DeepMind Haiku impl](https://github.com/deepmind/deepmind-research/tree/master/nfnets). - * Models are prefixed with `dm_`. They require SAME padding conv, skipinit enabled, and activation gains applied in act fn. - * These models are big, expect to run out of GPU memory. With the GELU activiation + other options, they are roughly 1/2 the inference speed of my SiLU PyTorch optimized `s` variants. - * Original model results are based on pre-processing that is not the same as all other models so you'll see different results in the results csv (once updated). - * Matching the original pre-processing as closely as possible I get these results: - * `dm_nfnet_f6` - 86.352 - * `dm_nfnet_f5` - 86.100 - * `dm_nfnet_f4` - 85.834 - * `dm_nfnet_f3` - 85.676 - * `dm_nfnet_f2` - 85.178 - * `dm_nfnet_f1` - 84.696 - * `dm_nfnet_f0` - 83.464 - -### Feb 16, 2021 -* Add Adaptive Gradient Clipping (AGC) as per https://arxiv.org/abs/2102.06171. Integrated w/ PyTorch gradient clipping via mode arg that defaults to prev 'norm' mode. For backward arg compat, clip-grad arg must be specified to enable when using train.py. - * AGC w/ default clipping factor `--clip-grad .01 --clip-mode agc` - * PyTorch global norm of 1.0 (old behaviour, always norm), `--clip-grad 1.0` - * PyTorch value clipping of 10, `--clip-grad 10. --clip-mode value` - * AGC performance is definitely sensitive to the clipping factor. More experimentation needed to determine good values for smaller batch sizes and optimizers besides those in paper. So far I've found .001-.005 is necessary for stable RMSProp training w/ NFNet/NF-ResNet. - -### Feb 12, 2021 -* Update Normalization-Free nets to include new NFNet-F (https://arxiv.org/abs/2102.06171) model defs - -### Feb 10, 2021 -* First Normalization-Free model training experiments done, - * nf_resnet50 - 80.68 top-1 @ 288x288, 80.31 @ 256x256 - * nf_regnet_b1 - 79.30 @ 288x288, 78.75 @ 256x256 -* More model archs, incl a flexible ByobNet backbone ('Bring-your-own-blocks') - * GPU-Efficient-Networks (https://github.com/idstcv/GPU-Efficient-Networks), impl in `byobnet.py` - * RepVGG (https://github.com/DingXiaoH/RepVGG), impl in `byobnet.py` - * classic VGG (from torchvision, impl in `vgg.py`) -* Refinements to normalizer layer arg handling and normalizer+act layer handling in some models -* Default AMP mode changed to native PyTorch AMP instead of APEX. Issues not being fixed with APEX. Native works with `--channels-last` and `--torchscript` model training, APEX does not. -* Fix a few bugs introduced since last pypi release - -### Feb 8, 2021 -* Add several ResNet weights with ECA attention. 26t & 50t trained @ 256, test @ 320. 269d train @ 256, fine-tune @320, test @ 352. - * `ecaresnet26t` - 79.88 top-1 @ 320x320, 79.08 @ 256x256 - * `ecaresnet50t` - 82.35 top-1 @ 320x320, 81.52 @ 256x256 - * `ecaresnet269d` - 84.93 top-1 @ 352x352, 84.87 @ 320x320 -* Remove separate tiered (`t`) vs tiered_narrow (`tn`) ResNet model defs, all `tn` changed to `t` and `t` models removed (`seresnext26t_32x4d` only model w/ weights that was removed). -* Support model default_cfgs with separate train vs test resolution `test_input_size` and remove extra `_320` suffix ResNet model defs that were just for test. - -### Jan 30, 2021 -* Add initial "Normalization Free" NF-RegNet-B* and NF-ResNet model definitions based on [paper](https://arxiv.org/abs/2101.08692) - -### Jan 25, 2021 -* Add ResNetV2 Big Transfer (BiT) models w/ ImageNet-1k and 21k weights from https://github.com/google-research/big_transfer -* Add official R50+ViT-B/16 hybrid models + weights from https://github.com/google-research/vision_transformer -* ImageNet-21k ViT weights are added w/ model defs and representation layer (pre logits) support - * NOTE: ImageNet-21k classifier heads were zero'd in original weights, they are only useful for transfer learning -* Add model defs and weights for DeiT Vision Transformer models from https://github.com/facebookresearch/deit -* Refactor dataset classes into ImageDataset/IterableImageDataset + dataset specific parser classes -* Add Tensorflow-Datasets (TFDS) wrapper to allow use of TFDS image classification sets with train script - * Ex: `train.py /data/tfds --dataset tfds/oxford_iiit_pet --val-split test --model resnet50 -b 256 --amp --num-classes 37 --opt adamw --lr 3e-4 --weight-decay .001 --pretrained -j 2` -* Add improved .tar dataset parser that reads images from .tar, folder of .tar files, or .tar within .tar - * Run validation on full ImageNet-21k directly from tar w/ BiT model: `validate.py /data/fall11_whole.tar --model resnetv2_50x1_bitm_in21k --amp` -* Models in this update should be stable w/ possible exception of ViT/BiT, possibility of some regressions with train/val scripts and dataset handling - -### Jan 3, 2021 -* Add SE-ResNet-152D weights - * 256x256 val, 0.94 crop top-1 - 83.75 - * 320x320 val, 1.0 crop - 84.36 -* Update [results files](results/) - - -## Introduction - -Py**T**orch **Im**age **M**odels (`timm`) is a collection of image models, layers, utilities, optimizers, schedulers, data-loaders / augmentations, and reference training / validation scripts that aim to pull together a wide variety of SOTA models with ability to reproduce ImageNet training results. - -The work of many others is present here. I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code docstrings. Please let me know if I missed anything. - -## Models - -All model architecture families include variants with pretrained weights. There are specific model variants without any weights, it is NOT a bug. Help training new or better weights is always appreciated. Here are some example [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) to get you started. - -A full version of the list below with source links can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/models/). - -* Big Transfer ResNetV2 (BiT) - https://arxiv.org/abs/1912.11370 -* Bottleneck Transformers - https://arxiv.org/abs/2101.11605 -* CaiT (Class-Attention in Image Transformers) - https://arxiv.org/abs/2103.17239 -* CoaT (Co-Scale Conv-Attentional Image Transformers) - https://arxiv.org/abs/2104.06399 -* ConViT (Soft Convolutional Inductive Biases Vision Transformers)- https://arxiv.org/abs/2103.10697 -* CspNet (Cross-Stage Partial Networks) - https://arxiv.org/abs/1911.11929 -* DeiT (Vision Transformer) - https://arxiv.org/abs/2012.12877 -* DenseNet - https://arxiv.org/abs/1608.06993 -* DLA - https://arxiv.org/abs/1707.06484 -* DPN (Dual-Path Network) - https://arxiv.org/abs/1707.01629 -* EfficientNet (MBConvNet Family) - * EfficientNet NoisyStudent (B0-B7, L2) - https://arxiv.org/abs/1911.04252 - * EfficientNet AdvProp (B0-B8) - https://arxiv.org/abs/1911.09665 - * EfficientNet (B0-B7) - https://arxiv.org/abs/1905.11946 - * EfficientNet-EdgeTPU (S, M, L) - https://ai.googleblog.com/2019/08/efficientnet-edgetpu-creating.html - * EfficientNet V2 - https://arxiv.org/abs/2104.00298 - * FBNet-C - https://arxiv.org/abs/1812.03443 - * MixNet - https://arxiv.org/abs/1907.09595 - * MNASNet B1, A1 (Squeeze-Excite), and Small - https://arxiv.org/abs/1807.11626 - * MobileNet-V2 - https://arxiv.org/abs/1801.04381 - * Single-Path NAS - https://arxiv.org/abs/1904.02877 -* GhostNet - https://arxiv.org/abs/1911.11907 -* gMLP - https://arxiv.org/abs/2105.08050 -* GPU-Efficient Networks - https://arxiv.org/abs/2006.14090 -* Halo Nets - https://arxiv.org/abs/2103.12731 -* HardCoRe-NAS - https://arxiv.org/abs/2102.11646 -* HRNet - https://arxiv.org/abs/1908.07919 -* Inception-V3 - https://arxiv.org/abs/1512.00567 -* Inception-ResNet-V2 and Inception-V4 - https://arxiv.org/abs/1602.07261 -* Lambda Networks - https://arxiv.org/abs/2102.08602 -* LeViT (Vision Transformer in ConvNet's Clothing) - https://arxiv.org/abs/2104.01136 -* MLP-Mixer - https://arxiv.org/abs/2105.01601 -* MobileNet-V3 (MBConvNet w/ Efficient Head) - https://arxiv.org/abs/1905.02244 -* NASNet-A - https://arxiv.org/abs/1707.07012 -* NFNet-F - https://arxiv.org/abs/2102.06171 -* NF-RegNet / NF-ResNet - https://arxiv.org/abs/2101.08692 -* PNasNet - https://arxiv.org/abs/1712.00559 -* Pooling-based Vision Transformer (PiT) - https://arxiv.org/abs/2103.16302 -* RegNet - https://arxiv.org/abs/2003.13678 -* RepVGG - https://arxiv.org/abs/2101.03697 -* ResMLP - https://arxiv.org/abs/2105.03404 -* ResNet/ResNeXt - * ResNet (v1b/v1.5) - https://arxiv.org/abs/1512.03385 - * ResNeXt - https://arxiv.org/abs/1611.05431 - * 'Bag of Tricks' / Gluon C, D, E, S variations - https://arxiv.org/abs/1812.01187 - * Weakly-supervised (WSL) Instagram pretrained / ImageNet tuned ResNeXt101 - https://arxiv.org/abs/1805.00932 - * Semi-supervised (SSL) / Semi-weakly Supervised (SWSL) ResNet/ResNeXts - https://arxiv.org/abs/1905.00546 - * ECA-Net (ECAResNet) - https://arxiv.org/abs/1910.03151v4 - * Squeeze-and-Excitation Networks (SEResNet) - https://arxiv.org/abs/1709.01507 - * ResNet-RS - https://arxiv.org/abs/2103.07579 -* Res2Net - https://arxiv.org/abs/1904.01169 -* ResNeSt - https://arxiv.org/abs/2004.08955 -* ReXNet - https://arxiv.org/abs/2007.00992 -* SelecSLS - https://arxiv.org/abs/1907.00837 -* Selective Kernel Networks - https://arxiv.org/abs/1903.06586 -* Swin Transformer - https://arxiv.org/abs/2103.14030 -* Transformer-iN-Transformer (TNT) - https://arxiv.org/abs/2103.00112 -* TResNet - https://arxiv.org/abs/2003.13630 -* Twins (Spatial Attention in Vision Transformers) - https://arxiv.org/pdf/2104.13840.pdf -* Vision Transformer - https://arxiv.org/abs/2010.11929 -* VovNet V2 and V1 - https://arxiv.org/abs/1911.06667 -* Xception - https://arxiv.org/abs/1610.02357 -* Xception (Modified Aligned, Gluon) - https://arxiv.org/abs/1802.02611 -* Xception (Modified Aligned, TF) - https://arxiv.org/abs/1802.02611 - -## Features - -Several (less common) features that I often utilize in my projects are included. Many of their additions are the reason why I maintain my own set of models, instead of using others' via PIP: - -* All models have a common default configuration interface and API for - * accessing/changing the classifier - `get_classifier` and `reset_classifier` - * doing a forward pass on just the features - `forward_features` (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) - * these makes it easy to write consistent network wrappers that work with any of the models -* All models support multi-scale feature map extraction (feature pyramids) via create_model (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) - * `create_model(name, features_only=True, out_indices=..., output_stride=...)` - * `out_indices` creation arg specifies which feature maps to return, these indices are 0 based and generally correspond to the `C(i + 1)` feature level. - * `output_stride` creation arg controls output stride of the network by using dilated convolutions. Most networks are stride 32 by default. Not all networks support this. - * feature map channel counts, reduction level (stride) can be queried AFTER model creation via the `.feature_info` member -* All models have a consistent pretrained weight loader that adapts last linear if necessary, and from 3 to 1 channel input if desired -* High performance [reference training, validation, and inference scripts](https://rwightman.github.io/pytorch-image-models/scripts/) that work in several process/GPU modes: - * NVIDIA DDP w/ a single GPU per process, multiple processes with APEX present (AMP mixed-precision optional) - * PyTorch DistributedDataParallel w/ multi-gpu, single process (AMP disabled as it crashes when enabled) - * PyTorch w/ single GPU single process (AMP optional) -* A dynamic global pool implementation that allows selecting from average pooling, max pooling, average + max, or concat([average, max]) at model creation. All global pooling is adaptive average by default and compatible with pretrained weights. -* A 'Test Time Pool' wrapper that can wrap any of the included models and usually provides improved performance doing inference with input images larger than the training size. Idea adapted from original DPN implementation when I ported (https://github.com/cypw/DPNs) -* Learning rate schedulers - * Ideas adopted from - * [AllenNLP schedulers](https://github.com/allenai/allennlp/tree/master/allennlp/training/learning_rate_schedulers) - * [FAIRseq lr_scheduler](https://github.com/pytorch/fairseq/tree/master/fairseq/optim/lr_scheduler) - * SGDR: Stochastic Gradient Descent with Warm Restarts (https://arxiv.org/abs/1608.03983) - * Schedulers include `step`, `cosine` w/ restarts, `tanh` w/ restarts, `plateau` -* Optimizers: - * `rmsprop_tf` adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behaviour. - * `radam` by [Liyuan Liu](https://github.com/LiyuanLucasLiu/RAdam) (https://arxiv.org/abs/1908.03265) - * `novograd` by [Masashi Kimura](https://github.com/convergence-lab/novograd) (https://arxiv.org/abs/1905.11286) - * `lookahead` adapted from impl by [Liam](https://github.com/alphadl/lookahead.pytorch) (https://arxiv.org/abs/1907.08610) - * `fused` optimizers by name with [NVIDIA Apex](https://github.com/NVIDIA/apex/tree/master/apex/optimizers) installed - * `adamp` and `sgdp` by [Naver ClovAI](https://github.com/clovaai) (https://arxiv.org/abs/2006.08217) - * `adafactor` adapted from [FAIRSeq impl](https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py) (https://arxiv.org/abs/1804.04235) - * `adahessian` by [David Samuel](https://github.com/davda54/ada-hessian) (https://arxiv.org/abs/2006.00719) -* Random Erasing from [Zhun Zhong](https://github.com/zhunzhong07/Random-Erasing/blob/master/transforms.py) (https://arxiv.org/abs/1708.04896) -* Mixup (https://arxiv.org/abs/1710.09412) -* CutMix (https://arxiv.org/abs/1905.04899) -* AutoAugment (https://arxiv.org/abs/1805.09501) and RandAugment (https://arxiv.org/abs/1909.13719) ImageNet configurations modeled after impl for EfficientNet training (https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py) -* AugMix w/ JSD loss (https://arxiv.org/abs/1912.02781), JSD w/ clean + augmented mixing support works with AutoAugment and RandAugment as well -* SplitBachNorm - allows splitting batch norm layers between clean and augmented (auxiliary batch norm) data -* DropPath aka "Stochastic Depth" (https://arxiv.org/abs/1603.09382) -* DropBlock (https://arxiv.org/abs/1810.12890) -* Blur Pooling (https://arxiv.org/abs/1904.11486) -* Space-to-Depth by [mrT23](https://github.com/mrT23/TResNet/blob/master/src/models/tresnet/layers/space_to_depth.py) (https://arxiv.org/abs/1801.04590) -- original paper? -* Adaptive Gradient Clipping (https://arxiv.org/abs/2102.06171, https://github.com/deepmind/deepmind-research/tree/master/nfnets) -* An extensive selection of channel and/or spatial attention modules: - * Bottleneck Transformer - https://arxiv.org/abs/2101.11605 - * CBAM - https://arxiv.org/abs/1807.06521 - * Effective Squeeze-Excitation (ESE) - https://arxiv.org/abs/1911.06667 - * Efficient Channel Attention (ECA) - https://arxiv.org/abs/1910.03151 - * Gather-Excite (GE) - https://arxiv.org/abs/1810.12348 - * Global Context (GC) - https://arxiv.org/abs/1904.11492 - * Halo - https://arxiv.org/abs/2103.12731 - * Involution - https://arxiv.org/abs/2103.06255 - * Lambda Layer - https://arxiv.org/abs/2102.08602 - * Non-Local (NL) - https://arxiv.org/abs/1711.07971 - * Squeeze-and-Excitation (SE) - https://arxiv.org/abs/1709.01507 - * Selective Kernel (SK) - (https://arxiv.org/abs/1903.06586 - * Split (SPLAT) - https://arxiv.org/abs/2004.08955 - * Shifted Window (SWIN) - https://arxiv.org/abs/2103.14030 - -## Results - -Model validation results can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/results/) and in the [results tables](results/README.md) - -## Getting Started (Documentation) - -My current [documentation](https://rwightman.github.io/pytorch-image-models/) for `timm` covers the basics. - -[timmdocs](https://fastai.github.io/timmdocs/) is quickly becoming a much more comprehensive set of documentation for `timm`. A big thanks to [Aman Arora](https://github.com/amaarora) for his efforts creating timmdocs. - -[paperswithcode](https://paperswithcode.com/lib/timm) is a good resource for browsing the models within `timm`. - -## Train, Validation, Inference Scripts - -The root folder of the repository contains reference train, validation, and inference scripts that work with the included models and other features of this repository. They are adaptable for other datasets and use cases with a little hacking. See [documentation](https://rwightman.github.io/pytorch-image-models/scripts/) for some basics and [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) for some train examples that produce SOTA ImageNet results. - -## Awesome PyTorch Resources - -One of the greatest assets of PyTorch is the community and their contributions. A few of my favourite resources that pair well with the models and components here are listed below. - -### Object Detection, Instance and Semantic Segmentation -* Detectron2 - https://github.com/facebookresearch/detectron2 -* Segmentation Models (Semantic) - https://github.com/qubvel/segmentation_models.pytorch -* EfficientDet (Obj Det, Semantic soon) - https://github.com/rwightman/efficientdet-pytorch - -### Computer Vision / Image Augmentation -* Albumentations - https://github.com/albumentations-team/albumentations -* Kornia - https://github.com/kornia/kornia - -### Knowledge Distillation -* RepDistiller - https://github.com/HobbitLong/RepDistiller -* torchdistill - https://github.com/yoshitomo-matsubara/torchdistill - -### Metric Learning -* PyTorch Metric Learning - https://github.com/KevinMusgrave/pytorch-metric-learning - -### Training / Frameworks -* fastai - https://github.com/fastai/fastai - -## Licenses - -### Code -The code here is licensed Apache 2.0. I've taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc. I've made an effort to avoid any GPL / LGPL conflicts. That said, it is your responsibility to ensure you comply with licenses here and conditions of any dependent licenses. Where applicable, I've linked the sources/references for various components in docstrings. If you think I've missed anything please create an issue. - -### Pretrained Weights -So far all of the pretrained weights available here are pretrained on ImageNet with a select few that have some additional pretraining (see extra note below). ImageNet was released for non-commercial research purposes only (http://www.image-net.org/download-faq). It's not clear what the implications of that are for the use of pretrained weights from that dataset. Any models I have trained with ImageNet are done for research purposes and one should assume that the original dataset license applies to the weights. It's best to seek legal advice if you intend to use the pretrained weights in a commercial product. - -#### Pretrained on more than ImageNet -Several weights included or references here were pretrained with proprietary datasets that I do not have access to. These include the Facebook WSL, SSL, SWSL ResNe(Xt) and the Google Noisy Student EfficientNet models. The Facebook models have an explicit non-commercial license (CC-BY-NC 4.0, https://github.com/facebookresearch/semi-supervised-ImageNet1K-models, https://github.com/facebookresearch/WSL-Images). The Google models do not appear to have any restriction beyond the Apache 2.0 license (and ImageNet concerns). In either case, you should contact Facebook or Google with any questions. - -## Citing - -### BibTeX - -``` -@misc{rw2019timm, - author = {Ross Wightman}, - title = {PyTorch Image Models}, - year = {2019}, - publisher = {GitHub}, - journal = {GitHub repository}, - doi = {10.5281/zenodo.4414861}, - howpublished = {\url{https://github.com/rwightman/pytorch-image-models}} -} -``` - -### Latest DOI - -[![DOI](https://zenodo.org/badge/168799526.svg)](https://zenodo.org/badge/latestdoi/168799526) + /home/Gluon_ResNet50_v1c_for_PyTorch/test/output/0 \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README_raw.md b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README_raw.md new file mode 100644 index 0000000000000000000000000000000000000000..76261cccf2de722c023d94286b41ea3ec8e0d491 --- /dev/null +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/README_raw.md @@ -0,0 +1,399 @@ +# PyTorch Image Models +- [Sponsors](#sponsors) +- [What's New](#whats-new) +- [Introduction](#introduction) +- [Models](#models) +- [Features](#features) +- [Results](#results) +- [Getting Started (Documentation)](#getting-started-documentation) +- [Train, Validation, Inference Scripts](#train-validation-inference-scripts) +- [Awesome PyTorch Resources](#awesome-pytorch-resources) +- [Licenses](#licenses) +- [Citing](#citing) + +## Sponsors + +A big thank you to my [GitHub Sponsors](https://github.com/sponsors/rwightman) for their support! + +In addition to the sponsors at the link above, I've received hardware and/or cloud resources from +* Nvidia (https://www.nvidia.com/en-us/) +* TFRC (https://www.tensorflow.org/tfrc) + +I'm fortunate to be able to dedicate significant time and money of my own supporting this and other open source projects. However, as the projects increase in scope, outside support is needed to continue with the current trajectory of hardware, infrastructure, and electricty costs. + +## What's New + +### June 20, 2021 +* Release Vision Transformer 'AugReg' weights from [How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers](https://arxiv.org/abs/2106.10270) + * .npz weight loading support added, can load any of the 50K+ weights from the [AugReg series](https://console.cloud.google.com/storage/browser/vit_models/augreg) + * See [example notebook](https://colab.research.google.com/github/google-research/vision_transformer/blob/master/vit_jax_augreg.ipynb) from official impl for navigating the augreg weights + * Replaced all default weights w/ best AugReg variant (if possible). All AugReg 21k classifiers work. + * Highlights: `vit_large_patch16_384` (87.1 top-1), `vit_large_r50_s32_384` (86.2 top-1), `vit_base_patch16_384` (86.0 top-1) + * `vit_deit_*` renamed to just `deit_*` + * Remove my old small model, replace with DeiT compatible small w/ AugReg weights +* Add 1st training of my `gmixer_24_224` MLP /w GLU, 78.1 top-1 w/ 25M params. +* Add weights from official ResMLP release (https://github.com/facebookresearch/deit) +* Add `eca_nfnet_l2` weights from my 'lightweight' series. 84.7 top-1 at 384x384. +* Add distilled BiT 50x1 student and 152x2 Teacher weights from [Knowledge distillation: A good teacher is patient and consistent](https://arxiv.org/abs/2106.05237) +* NFNets and ResNetV2-BiT models work w/ Pytorch XLA now + * weight standardization uses F.batch_norm instead of std_mean (std_mean wasn't lowered) + * eps values adjusted, will be slight differences but should be quite close +* Improve test coverage and classifier interface of non-conv (vision transformer and mlp) models +* Cleanup a few classifier / flatten details for models w/ conv classifiers or early global pool +* Please report any regressions, this PR touched quite a few models. + +### June 8, 2021 +* Add first ResMLP weights, trained in PyTorch XLA on TPU-VM w/ my XLA branch. 24 block variant, 79.2 top-1. +* Add ResNet51-Q model w/ pretrained weights at 82.36 top-1. + * NFNet inspired block layout with quad layer stem and no maxpool + * Same param count (35.7M) and throughput as ResNetRS-50 but +1.5 top-1 @ 224x224 and +2.5 top-1 at 288x288 + +### May 25, 2021 +* Add LeViT, Visformer, ConViT (PR by Aman Arora), Twins (PR by paper authors) transformer models +* Add ResMLP and gMLP MLP vision models to the existing MLP Mixer impl +* Fix a number of torchscript issues with various vision transformer models +* Cleanup input_size/img_size override handling and improve testing / test coverage for all vision transformer and MLP models +* More flexible pos embedding resize (non-square) for ViT and TnT. Thanks [Alexander Soare](https://github.com/alexander-soare) +* Add `efficientnetv2_rw_m` model and weights (started training before official code). 84.8 top-1, 53M params. + +### May 14, 2021 +* Add EfficientNet-V2 official model defs w/ ported weights from official [Tensorflow/Keras](https://github.com/google/automl/tree/master/efficientnetv2) impl. + * 1k trained variants: `tf_efficientnetv2_s/m/l` + * 21k trained variants: `tf_efficientnetv2_s/m/l_in21k` + * 21k pretrained -> 1k fine-tuned: `tf_efficientnetv2_s/m/l_in21ft1k` + * v2 models w/ v1 scaling: `tf_efficientnetv2_b0` through `b3` + * Rename my prev V2 guess `efficientnet_v2s` -> `efficientnetv2_rw_s` + * Some blank `efficientnetv2_*` models in-place for future native PyTorch training + +### May 5, 2021 +* Add MLP-Mixer models and port pretrained weights from [Google JAX impl](https://github.com/google-research/vision_transformer/tree/linen) +* Add CaiT models and pretrained weights from [FB](https://github.com/facebookresearch/deit) +* Add ResNet-RS models and weights from [TF](https://github.com/tensorflow/tpu/tree/master/models/official/resnet/resnet_rs). Thanks [Aman Arora](https://github.com/amaarora) +* Add CoaT models and weights. Thanks [Mohammed Rizin](https://github.com/morizin) +* Add new ImageNet-21k weights & finetuned weights for TResNet, MobileNet-V3, ViT models. Thanks [mrT](https://github.com/mrT23) +* Add GhostNet models and weights. Thanks [Kai Han](https://github.com/iamhankai) +* Update ByoaNet attention modules + * Improve SA module inits + * Hack together experimental stand-alone Swin based attn module and `swinnet` + * Consistent '26t' model defs for experiments. +* Add improved Efficientnet-V2S (prelim model def) weights. 83.8 top-1. +* WandB logging support + +### April 13, 2021 +* Add Swin Transformer models and weights from https://github.com/microsoft/Swin-Transformer + +### April 12, 2021 +* Add ECA-NFNet-L1 (slimmed down F1 w/ SiLU, 41M params) trained with this code. 84% top-1 @ 320x320. Trained at 256x256. +* Add EfficientNet-V2S model (unverified model definition) weights. 83.3 top-1 @ 288x288. Only trained single res 224. Working on progressive training. +* Add ByoaNet model definition (Bring-your-own-attention) w/ SelfAttention block and corresponding SA/SA-like modules and model defs + * Lambda Networks - https://arxiv.org/abs/2102.08602 + * Bottleneck Transformers - https://arxiv.org/abs/2101.11605 + * Halo Nets - https://arxiv.org/abs/2103.12731 +* Adabelief optimizer contributed by Juntang Zhuang + +### April 1, 2021 +* Add snazzy `benchmark.py` script for bulk `timm` model benchmarking of train and/or inference +* Add Pooling-based Vision Transformer (PiT) models (from https://github.com/naver-ai/pit) + * Merged distilled variant into main for torchscript compatibility + * Some `timm` cleanup/style tweaks and weights have hub download support +* Cleanup Vision Transformer (ViT) models + * Merge distilled (DeiT) model into main so that torchscript can work + * Support updated weight init (defaults to old still) that closer matches original JAX impl (possibly better training from scratch) + * Separate hybrid model defs into different file and add several new model defs to fiddle with, support patch_size != 1 for hybrids + * Fix fine-tuning num_class changes (PiT and ViT) and pos_embed resizing (Vit) with distilled variants + * nn.Sequential for block stack (does not break downstream compat) +* TnT (Transformer-in-Transformer) models contributed by author (from https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/cv/TNT) +* Add RegNetY-160 weights from DeiT teacher model +* Add new NFNet-L0 w/ SE attn (rename `nfnet_l0b`->`nfnet_l0`) weights 82.75 top-1 @ 288x288 +* Some fixes/improvements for TFDS dataset wrapper + +### March 17, 2021 +* Add new ECA-NFNet-L0 (rename `nfnet_l0c`->`eca_nfnet_l0`) weights trained by myself. + * 82.6 top-1 @ 288x288, 82.8 @ 320x320, trained at 224x224 + * Uses SiLU activation, approx 2x faster than `dm_nfnet_f0` and 50% faster than `nfnet_f0s` w/ 1/3 param count +* Integrate [Hugging Face model hub](https://huggingface.co/models) into timm create_model and default_cfg handling for pretrained weight and config sharing (more on this soon!) +* Merge HardCoRe NAS models contributed by https://github.com/yoniaflalo +* Merge PyTorch trained EfficientNet-EL and pruned ES/EL variants contributed by [DeGirum](https://github.com/DeGirum) + + +### March 7, 2021 +* First 0.4.x PyPi release w/ NFNets (& related), ByoB (GPU-Efficient, RepVGG, etc). +* Change feature extraction for pre-activation nets (NFNets, ResNetV2) to return features before activation. +* Tested with PyTorch 1.8 release. Updated CI to use 1.8. +* Benchmarked several arch on RTX 3090, Titan RTX, and V100 across 1.7.1, 1.8, NGC 20.12, and 21.02. Some interesting performance variations to take note of https://gist.github.com/rwightman/bb59f9e245162cee0e38bd66bd8cd77f + +### Feb 18, 2021 +* Add pretrained weights and model variants for NFNet-F* models from [DeepMind Haiku impl](https://github.com/deepmind/deepmind-research/tree/master/nfnets). + * Models are prefixed with `dm_`. They require SAME padding conv, skipinit enabled, and activation gains applied in act fn. + * These models are big, expect to run out of GPU memory. With the GELU activiation + other options, they are roughly 1/2 the inference speed of my SiLU PyTorch optimized `s` variants. + * Original model results are based on pre-processing that is not the same as all other models so you'll see different results in the results csv (once updated). + * Matching the original pre-processing as closely as possible I get these results: + * `dm_nfnet_f6` - 86.352 + * `dm_nfnet_f5` - 86.100 + * `dm_nfnet_f4` - 85.834 + * `dm_nfnet_f3` - 85.676 + * `dm_nfnet_f2` - 85.178 + * `dm_nfnet_f1` - 84.696 + * `dm_nfnet_f0` - 83.464 + +### Feb 16, 2021 +* Add Adaptive Gradient Clipping (AGC) as per https://arxiv.org/abs/2102.06171. Integrated w/ PyTorch gradient clipping via mode arg that defaults to prev 'norm' mode. For backward arg compat, clip-grad arg must be specified to enable when using train.py. + * AGC w/ default clipping factor `--clip-grad .01 --clip-mode agc` + * PyTorch global norm of 1.0 (old behaviour, always norm), `--clip-grad 1.0` + * PyTorch value clipping of 10, `--clip-grad 10. --clip-mode value` + * AGC performance is definitely sensitive to the clipping factor. More experimentation needed to determine good values for smaller batch sizes and optimizers besides those in paper. So far I've found .001-.005 is necessary for stable RMSProp training w/ NFNet/NF-ResNet. + +### Feb 12, 2021 +* Update Normalization-Free nets to include new NFNet-F (https://arxiv.org/abs/2102.06171) model defs + +### Feb 10, 2021 +* First Normalization-Free model training experiments done, + * nf_resnet50 - 80.68 top-1 @ 288x288, 80.31 @ 256x256 + * nf_regnet_b1 - 79.30 @ 288x288, 78.75 @ 256x256 +* More model archs, incl a flexible ByobNet backbone ('Bring-your-own-blocks') + * GPU-Efficient-Networks (https://github.com/idstcv/GPU-Efficient-Networks), impl in `byobnet.py` + * RepVGG (https://github.com/DingXiaoH/RepVGG), impl in `byobnet.py` + * classic VGG (from torchvision, impl in `vgg.py`) +* Refinements to normalizer layer arg handling and normalizer+act layer handling in some models +* Default AMP mode changed to native PyTorch AMP instead of APEX. Issues not being fixed with APEX. Native works with `--channels-last` and `--torchscript` model training, APEX does not. +* Fix a few bugs introduced since last pypi release + +### Feb 8, 2021 +* Add several ResNet weights with ECA attention. 26t & 50t trained @ 256, test @ 320. 269d train @ 256, fine-tune @320, test @ 352. + * `ecaresnet26t` - 79.88 top-1 @ 320x320, 79.08 @ 256x256 + * `ecaresnet50t` - 82.35 top-1 @ 320x320, 81.52 @ 256x256 + * `ecaresnet269d` - 84.93 top-1 @ 352x352, 84.87 @ 320x320 +* Remove separate tiered (`t`) vs tiered_narrow (`tn`) ResNet model defs, all `tn` changed to `t` and `t` models removed (`seresnext26t_32x4d` only model w/ weights that was removed). +* Support model default_cfgs with separate train vs test resolution `test_input_size` and remove extra `_320` suffix ResNet model defs that were just for test. + +### Jan 30, 2021 +* Add initial "Normalization Free" NF-RegNet-B* and NF-ResNet model definitions based on [paper](https://arxiv.org/abs/2101.08692) + +### Jan 25, 2021 +* Add ResNetV2 Big Transfer (BiT) models w/ ImageNet-1k and 21k weights from https://github.com/google-research/big_transfer +* Add official R50+ViT-B/16 hybrid models + weights from https://github.com/google-research/vision_transformer +* ImageNet-21k ViT weights are added w/ model defs and representation layer (pre logits) support + * NOTE: ImageNet-21k classifier heads were zero'd in original weights, they are only useful for transfer learning +* Add model defs and weights for DeiT Vision Transformer models from https://github.com/facebookresearch/deit +* Refactor dataset classes into ImageDataset/IterableImageDataset + dataset specific parser classes +* Add Tensorflow-Datasets (TFDS) wrapper to allow use of TFDS image classification sets with train script + * Ex: `train.py /data/tfds --dataset tfds/oxford_iiit_pet --val-split test --model resnet50 -b 256 --amp --num-classes 37 --opt adamw --lr 3e-4 --weight-decay .001 --pretrained -j 2` +* Add improved .tar dataset parser that reads images from .tar, folder of .tar files, or .tar within .tar + * Run validation on full ImageNet-21k directly from tar w/ BiT model: `validate.py /data/fall11_whole.tar --model resnetv2_50x1_bitm_in21k --amp` +* Models in this update should be stable w/ possible exception of ViT/BiT, possibility of some regressions with train/val scripts and dataset handling + +### Jan 3, 2021 +* Add SE-ResNet-152D weights + * 256x256 val, 0.94 crop top-1 - 83.75 + * 320x320 val, 1.0 crop - 84.36 +* Update [results files](results/) + + +## Introduction + +Py**T**orch **Im**age **M**odels (`timm`) is a collection of image models, layers, utilities, optimizers, schedulers, data-loaders / augmentations, and reference training / validation scripts that aim to pull together a wide variety of SOTA models with ability to reproduce ImageNet training results. + +The work of many others is present here. I've tried to make sure all source material is acknowledged via links to github, arxiv papers, etc in the README, documentation, and code docstrings. Please let me know if I missed anything. + +## Models + +All model architecture families include variants with pretrained weights. There are specific model variants without any weights, it is NOT a bug. Help training new or better weights is always appreciated. Here are some example [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) to get you started. + +A full version of the list below with source links can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/models/). + +* Big Transfer ResNetV2 (BiT) - https://arxiv.org/abs/1912.11370 +* Bottleneck Transformers - https://arxiv.org/abs/2101.11605 +* CaiT (Class-Attention in Image Transformers) - https://arxiv.org/abs/2103.17239 +* CoaT (Co-Scale Conv-Attentional Image Transformers) - https://arxiv.org/abs/2104.06399 +* ConViT (Soft Convolutional Inductive Biases Vision Transformers)- https://arxiv.org/abs/2103.10697 +* CspNet (Cross-Stage Partial Networks) - https://arxiv.org/abs/1911.11929 +* DeiT (Vision Transformer) - https://arxiv.org/abs/2012.12877 +* DenseNet - https://arxiv.org/abs/1608.06993 +* DLA - https://arxiv.org/abs/1707.06484 +* DPN (Dual-Path Network) - https://arxiv.org/abs/1707.01629 +* EfficientNet (MBConvNet Family) + * EfficientNet NoisyStudent (B0-B7, L2) - https://arxiv.org/abs/1911.04252 + * EfficientNet AdvProp (B0-B8) - https://arxiv.org/abs/1911.09665 + * EfficientNet (B0-B7) - https://arxiv.org/abs/1905.11946 + * EfficientNet-EdgeTPU (S, M, L) - https://ai.googleblog.com/2019/08/efficientnet-edgetpu-creating.html + * EfficientNet V2 - https://arxiv.org/abs/2104.00298 + * FBNet-C - https://arxiv.org/abs/1812.03443 + * MixNet - https://arxiv.org/abs/1907.09595 + * MNASNet B1, A1 (Squeeze-Excite), and Small - https://arxiv.org/abs/1807.11626 + * MobileNet-V2 - https://arxiv.org/abs/1801.04381 + * Single-Path NAS - https://arxiv.org/abs/1904.02877 +* GhostNet - https://arxiv.org/abs/1911.11907 +* gMLP - https://arxiv.org/abs/2105.08050 +* GPU-Efficient Networks - https://arxiv.org/abs/2006.14090 +* Halo Nets - https://arxiv.org/abs/2103.12731 +* HardCoRe-NAS - https://arxiv.org/abs/2102.11646 +* HRNet - https://arxiv.org/abs/1908.07919 +* Inception-V3 - https://arxiv.org/abs/1512.00567 +* Inception-ResNet-V2 and Inception-V4 - https://arxiv.org/abs/1602.07261 +* Lambda Networks - https://arxiv.org/abs/2102.08602 +* LeViT (Vision Transformer in ConvNet's Clothing) - https://arxiv.org/abs/2104.01136 +* MLP-Mixer - https://arxiv.org/abs/2105.01601 +* MobileNet-V3 (MBConvNet w/ Efficient Head) - https://arxiv.org/abs/1905.02244 +* NASNet-A - https://arxiv.org/abs/1707.07012 +* NFNet-F - https://arxiv.org/abs/2102.06171 +* NF-RegNet / NF-ResNet - https://arxiv.org/abs/2101.08692 +* PNasNet - https://arxiv.org/abs/1712.00559 +* Pooling-based Vision Transformer (PiT) - https://arxiv.org/abs/2103.16302 +* RegNet - https://arxiv.org/abs/2003.13678 +* RepVGG - https://arxiv.org/abs/2101.03697 +* ResMLP - https://arxiv.org/abs/2105.03404 +* ResNet/ResNeXt + * ResNet (v1b/v1.5) - https://arxiv.org/abs/1512.03385 + * ResNeXt - https://arxiv.org/abs/1611.05431 + * 'Bag of Tricks' / Gluon C, D, E, S variations - https://arxiv.org/abs/1812.01187 + * Weakly-supervised (WSL) Instagram pretrained / ImageNet tuned ResNeXt101 - https://arxiv.org/abs/1805.00932 + * Semi-supervised (SSL) / Semi-weakly Supervised (SWSL) ResNet/ResNeXts - https://arxiv.org/abs/1905.00546 + * ECA-Net (ECAResNet) - https://arxiv.org/abs/1910.03151v4 + * Squeeze-and-Excitation Networks (SEResNet) - https://arxiv.org/abs/1709.01507 + * ResNet-RS - https://arxiv.org/abs/2103.07579 +* Res2Net - https://arxiv.org/abs/1904.01169 +* ResNeSt - https://arxiv.org/abs/2004.08955 +* ReXNet - https://arxiv.org/abs/2007.00992 +* SelecSLS - https://arxiv.org/abs/1907.00837 +* Selective Kernel Networks - https://arxiv.org/abs/1903.06586 +* Swin Transformer - https://arxiv.org/abs/2103.14030 +* Transformer-iN-Transformer (TNT) - https://arxiv.org/abs/2103.00112 +* TResNet - https://arxiv.org/abs/2003.13630 +* Twins (Spatial Attention in Vision Transformers) - https://arxiv.org/pdf/2104.13840.pdf +* Vision Transformer - https://arxiv.org/abs/2010.11929 +* VovNet V2 and V1 - https://arxiv.org/abs/1911.06667 +* Xception - https://arxiv.org/abs/1610.02357 +* Xception (Modified Aligned, Gluon) - https://arxiv.org/abs/1802.02611 +* Xception (Modified Aligned, TF) - https://arxiv.org/abs/1802.02611 + +## Features + +Several (less common) features that I often utilize in my projects are included. Many of their additions are the reason why I maintain my own set of models, instead of using others' via PIP: + +* All models have a common default configuration interface and API for + * accessing/changing the classifier - `get_classifier` and `reset_classifier` + * doing a forward pass on just the features - `forward_features` (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) + * these makes it easy to write consistent network wrappers that work with any of the models +* All models support multi-scale feature map extraction (feature pyramids) via create_model (see [documentation](https://rwightman.github.io/pytorch-image-models/feature_extraction/)) + * `create_model(name, features_only=True, out_indices=..., output_stride=...)` + * `out_indices` creation arg specifies which feature maps to return, these indices are 0 based and generally correspond to the `C(i + 1)` feature level. + * `output_stride` creation arg controls output stride of the network by using dilated convolutions. Most networks are stride 32 by default. Not all networks support this. + * feature map channel counts, reduction level (stride) can be queried AFTER model creation via the `.feature_info` member +* All models have a consistent pretrained weight loader that adapts last linear if necessary, and from 3 to 1 channel input if desired +* High performance [reference training, validation, and inference scripts](https://rwightman.github.io/pytorch-image-models/scripts/) that work in several process/GPU modes: + * NVIDIA DDP w/ a single GPU per process, multiple processes with APEX present (AMP mixed-precision optional) + * PyTorch DistributedDataParallel w/ multi-gpu, single process (AMP disabled as it crashes when enabled) + * PyTorch w/ single GPU single process (AMP optional) +* A dynamic global pool implementation that allows selecting from average pooling, max pooling, average + max, or concat([average, max]) at model creation. All global pooling is adaptive average by default and compatible with pretrained weights. +* A 'Test Time Pool' wrapper that can wrap any of the included models and usually provides improved performance doing inference with input images larger than the training size. Idea adapted from original DPN implementation when I ported (https://github.com/cypw/DPNs) +* Learning rate schedulers + * Ideas adopted from + * [AllenNLP schedulers](https://github.com/allenai/allennlp/tree/master/allennlp/training/learning_rate_schedulers) + * [FAIRseq lr_scheduler](https://github.com/pytorch/fairseq/tree/master/fairseq/optim/lr_scheduler) + * SGDR: Stochastic Gradient Descent with Warm Restarts (https://arxiv.org/abs/1608.03983) + * Schedulers include `step`, `cosine` w/ restarts, `tanh` w/ restarts, `plateau` +* Optimizers: + * `rmsprop_tf` adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behaviour. + * `radam` by [Liyuan Liu](https://github.com/LiyuanLucasLiu/RAdam) (https://arxiv.org/abs/1908.03265) + * `novograd` by [Masashi Kimura](https://github.com/convergence-lab/novograd) (https://arxiv.org/abs/1905.11286) + * `lookahead` adapted from impl by [Liam](https://github.com/alphadl/lookahead.pytorch) (https://arxiv.org/abs/1907.08610) + * `fused` optimizers by name with [NVIDIA Apex](https://github.com/NVIDIA/apex/tree/master/apex/optimizers) installed + * `adamp` and `sgdp` by [Naver ClovAI](https://github.com/clovaai) (https://arxiv.org/abs/2006.08217) + * `adafactor` adapted from [FAIRSeq impl](https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py) (https://arxiv.org/abs/1804.04235) + * `adahessian` by [David Samuel](https://github.com/davda54/ada-hessian) (https://arxiv.org/abs/2006.00719) +* Random Erasing from [Zhun Zhong](https://github.com/zhunzhong07/Random-Erasing/blob/master/transforms.py) (https://arxiv.org/abs/1708.04896) +* Mixup (https://arxiv.org/abs/1710.09412) +* CutMix (https://arxiv.org/abs/1905.04899) +* AutoAugment (https://arxiv.org/abs/1805.09501) and RandAugment (https://arxiv.org/abs/1909.13719) ImageNet configurations modeled after impl for EfficientNet training (https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py) +* AugMix w/ JSD loss (https://arxiv.org/abs/1912.02781), JSD w/ clean + augmented mixing support works with AutoAugment and RandAugment as well +* SplitBachNorm - allows splitting batch norm layers between clean and augmented (auxiliary batch norm) data +* DropPath aka "Stochastic Depth" (https://arxiv.org/abs/1603.09382) +* DropBlock (https://arxiv.org/abs/1810.12890) +* Blur Pooling (https://arxiv.org/abs/1904.11486) +* Space-to-Depth by [mrT23](https://github.com/mrT23/TResNet/blob/master/src/models/tresnet/layers/space_to_depth.py) (https://arxiv.org/abs/1801.04590) -- original paper? +* Adaptive Gradient Clipping (https://arxiv.org/abs/2102.06171, https://github.com/deepmind/deepmind-research/tree/master/nfnets) +* An extensive selection of channel and/or spatial attention modules: + * Bottleneck Transformer - https://arxiv.org/abs/2101.11605 + * CBAM - https://arxiv.org/abs/1807.06521 + * Effective Squeeze-Excitation (ESE) - https://arxiv.org/abs/1911.06667 + * Efficient Channel Attention (ECA) - https://arxiv.org/abs/1910.03151 + * Gather-Excite (GE) - https://arxiv.org/abs/1810.12348 + * Global Context (GC) - https://arxiv.org/abs/1904.11492 + * Halo - https://arxiv.org/abs/2103.12731 + * Involution - https://arxiv.org/abs/2103.06255 + * Lambda Layer - https://arxiv.org/abs/2102.08602 + * Non-Local (NL) - https://arxiv.org/abs/1711.07971 + * Squeeze-and-Excitation (SE) - https://arxiv.org/abs/1709.01507 + * Selective Kernel (SK) - (https://arxiv.org/abs/1903.06586 + * Split (SPLAT) - https://arxiv.org/abs/2004.08955 + * Shifted Window (SWIN) - https://arxiv.org/abs/2103.14030 + +## Results + +Model validation results can be found in the [documentation](https://rwightman.github.io/pytorch-image-models/results/) and in the [results tables](results/README.md) + +## Getting Started (Documentation) + +My current [documentation](https://rwightman.github.io/pytorch-image-models/) for `timm` covers the basics. + +[timmdocs](https://fastai.github.io/timmdocs/) is quickly becoming a much more comprehensive set of documentation for `timm`. A big thanks to [Aman Arora](https://github.com/amaarora) for his efforts creating timmdocs. + +[paperswithcode](https://paperswithcode.com/lib/timm) is a good resource for browsing the models within `timm`. + +## Train, Validation, Inference Scripts + +The root folder of the repository contains reference train, validation, and inference scripts that work with the included models and other features of this repository. They are adaptable for other datasets and use cases with a little hacking. See [documentation](https://rwightman.github.io/pytorch-image-models/scripts/) for some basics and [training hparams](https://rwightman.github.io/pytorch-image-models/training_hparam_examples) for some train examples that produce SOTA ImageNet results. + +## Awesome PyTorch Resources + +One of the greatest assets of PyTorch is the community and their contributions. A few of my favourite resources that pair well with the models and components here are listed below. + +### Object Detection, Instance and Semantic Segmentation +* Detectron2 - https://github.com/facebookresearch/detectron2 +* Segmentation Models (Semantic) - https://github.com/qubvel/segmentation_models.pytorch +* EfficientDet (Obj Det, Semantic soon) - https://github.com/rwightman/efficientdet-pytorch + +### Computer Vision / Image Augmentation +* Albumentations - https://github.com/albumentations-team/albumentations +* Kornia - https://github.com/kornia/kornia + +### Knowledge Distillation +* RepDistiller - https://github.com/HobbitLong/RepDistiller +* torchdistill - https://github.com/yoshitomo-matsubara/torchdistill + +### Metric Learning +* PyTorch Metric Learning - https://github.com/KevinMusgrave/pytorch-metric-learning + +### Training / Frameworks +* fastai - https://github.com/fastai/fastai + +## Licenses + +### Code +The code here is licensed Apache 2.0. I've taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc. I've made an effort to avoid any GPL / LGPL conflicts. That said, it is your responsibility to ensure you comply with licenses here and conditions of any dependent licenses. Where applicable, I've linked the sources/references for various components in docstrings. If you think I've missed anything please create an issue. + +### Pretrained Weights +So far all of the pretrained weights available here are pretrained on ImageNet with a select few that have some additional pretraining (see extra note below). ImageNet was released for non-commercial research purposes only (http://www.image-net.org/download-faq). It's not clear what the implications of that are for the use of pretrained weights from that dataset. Any models I have trained with ImageNet are done for research purposes and one should assume that the original dataset license applies to the weights. It's best to seek legal advice if you intend to use the pretrained weights in a commercial product. + +#### Pretrained on more than ImageNet +Several weights included or references here were pretrained with proprietary datasets that I do not have access to. These include the Facebook WSL, SSL, SWSL ResNe(Xt) and the Google Noisy Student EfficientNet models. The Facebook models have an explicit non-commercial license (CC-BY-NC 4.0, https://github.com/facebookresearch/semi-supervised-ImageNet1K-models, https://github.com/facebookresearch/WSL-Images). The Google models do not appear to have any restriction beyond the Apache 2.0 license (and ImageNet concerns). In either case, you should contact Facebook or Google with any questions. + +## Citing + +### BibTeX + +``` +@misc{rw2019timm, + author = {Ross Wightman}, + title = {PyTorch Image Models}, + year = {2019}, + publisher = {GitHub}, + journal = {GitHub repository}, + doi = {10.5281/zenodo.4414861}, + howpublished = {\url{https://github.com/rwightman/pytorch-image-models}} +} +``` + +### Latest DOI + +[![DOI](https://zenodo.org/badge/168799526.svg)](https://zenodo.org/badge/latestdoi/168799526) diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_1p.sh index 9bbf9a4a5422fbba84afb7942c32698967256029..723dc9f8a8efe62bb0146397a5ce76ee6b780663 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_1p.sh @@ -74,10 +74,16 @@ fi #################启动训练脚本################# #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh -python3 train.py \ +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + + +nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1d \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_8p.sh index 99aa5a232dfdfa4aa09d4e1da10288b6f1dab970..e8c85f7a347f8ffdd941de78139fbe7487091073 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_full_8p.sh @@ -63,12 +63,18 @@ fi #################启动训练脚本################# # 训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + for i in $(seq 0 7) do - python3 train.py \ + nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1d \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_1p.sh index 0d1d73aaac2631199e89856715cfde2b28792638..794f9ca5c6c310ac2fab12b5aeb870b67065a34c 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_1p.sh @@ -74,10 +74,16 @@ fi #################启动训练脚本################# #训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh -python3 train.py \ +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + + +nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1d \ diff --git a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_8p.sh index 4592db04183db5952dde0c648ff08168df527636..c7514edcdeb8b7459805e58485faf34e0b2b5a50 100644 --- a/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch/test/train_performance_8p.sh @@ -63,12 +63,18 @@ fi #################启动训练脚本################# # 训练开始时间,不需要修改 start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env_npu.sh + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + for i in $(seq 0 7) do - python3 train.py \ + nohup python3.7 train.py \ ${data_path} \ -b ${batch_size} \ --model gluon_resnet50_v1d \