From ebbf621ac0e6a918afcc5249c2378f40dfddd9b7 Mon Sep 17 00:00:00 2001 From: liuyuxin Date: Thu, 4 Aug 2022 12:17:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=97=E6=99=BA][Densenet121][Pytorch]=20De?= =?UTF-8?q?nsenet121=E6=A8=A1=E5=9E=8B=E8=84=9A=E6=9C=AC=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Densenet121_for_PyTorch/densenet121_1p_main.py | 5 ++++- .../Densenet121_for_PyTorch/densenet121_8p_main.py | 11 ++++++++--- .../Densenet121_for_PyTorch/docker_start.sh | 4 ++-- .../sdk_infer/docker_start_infer.sh | 2 +- .../pipeline/densenet121_opencv.pipeline | 4 ++-- .../sdk_infer/sdk_run_infer/run_densenet.sh | 9 +-------- .../Densenet121_for_PyTorch/test/train_full_1p.sh | 2 +- .../Densenet121_for_PyTorch/test/train_full_8p.sh | 4 ++-- .../test/train_performance_1p.sh | 2 +- .../test/train_performance_8p.sh | 2 +- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py index c4a606d6a9..e9a5438e98 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_1p_main.py @@ -143,6 +143,7 @@ def main(): if args.seed is not None: + seed = args.seed random.seed(seed) os.environ['PYTHONHASHSEED'] = str(seed) np.random.seed(seed) @@ -250,7 +251,8 @@ def main_worker(gpu, ngpus_per_node, args): weight_decay=args.weight_decay) if args.amp: - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale, combine_grad=True) + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=args.loss_scale, combine_grad=True) # optionally resume from a checkpoint if args.resume: @@ -260,6 +262,7 @@ def main_worker(gpu, ngpus_per_node, args): args.start_epoch = checkpoint['epoch'] best_acc1 = checkpoint['best_acc1'] model.load_state_dict(checkpoint['state_dict']) + model = nn.DataParallel(model) optimizer.load_state_dict(checkpoint['optimizer']) if args.amp: amp.load_state_dict(checkpoint['amp']) diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py index f2b148daa4..46b32dd9b8 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/densenet121_8p_main.py @@ -153,6 +153,7 @@ def main(): print("===============main()=================") if args.seed is not None: + seed = args.seed random.seed(args.seed) torch.manual_seed(args.seed) cudnn.deterministic = True @@ -288,8 +289,10 @@ def main_worker(gpu, ngpus_per_node, args): weight_decay=args.weight_decay) if args.amp: - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale, combine_grad=True) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=args.loss_scale, combine_grad=True) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], + broadcast_buffers=False) # optionally resume from a checkpoint if args.resume: @@ -299,6 +302,7 @@ def main_worker(gpu, ngpus_per_node, args): args.start_epoch = checkpoint['epoch'] best_acc1 = checkpoint['best_acc1'] model.load_state_dict(checkpoint['state_dict']) + model = nn.DataParallel(model) optimizer.load_state_dict(checkpoint['optimizer']) if args.amp: amp.load_state_dict(checkpoint['amp']) @@ -330,7 +334,8 @@ def main_worker(gpu, ngpus_per_node, args): best_acc1 = max(acc1, best_acc1) if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0 and epoch == args.epochs - 1): + and args.rank % ngpus_per_node == 0 + and epoch == args.epochs - 1): if args.amp: save_checkpoint({ 'epoch': epoch + 1, diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/docker_start.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/docker_start.sh index 944bca3cda..cf8052518d 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/docker_start.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/docker_start.sh @@ -4,7 +4,7 @@ docker_image=$1 data_dir=$2 model_dir=$3 -docker run -it --ipc=host \ +docker run -it -u root --ipc=host \ --device=/dev/davinci0 \ --device=/dev/davinci1 \ --device=/dev/davinci2 \ @@ -22,4 +22,4 @@ docker run -it --ipc=host \ -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ - /bin/bash \ No newline at end of file + /bin/bash diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/docker_start_infer.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/docker_start_infer.sh index 072b0819ae..deac57c423 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/docker_start_infer.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/docker_start_infer.sh @@ -37,7 +37,7 @@ function param_check() { param_check -docker run -it \ +docker run -it -u root \ --device=/dev/davinci0 \ --device=/dev/davinci_manager \ --device=/dev/devmm_svm \ diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/pipeline/densenet121_opencv.pipeline b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/pipeline/densenet121_opencv.pipeline index 4357b974bc..4027490b11 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/pipeline/densenet121_opencv.pipeline +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/pipeline/densenet121_opencv.pipeline @@ -38,7 +38,7 @@ "mxpi_tensorinfer0": { "props": { "dataSource": "mxpi_opencvcentercrop0", - "modelPath": "./models/densenet121/densenet121_304.om", + "modelPath": "./models/densenet121/densenet121_pytorch_1.3.om", "waitingTime": "2000", "outputDeviceId": "-1" }, @@ -50,7 +50,7 @@ "dataSource": "mxpi_tensorinfer0", "postProcessConfigPath": "./models/densenet121/densenet121_aipp.cfg", "labelPath": "./models/densenet121/imagenet1000_clsidx_to_labels.names", - "postProcessLibPath": "../../../lib/modelpostprocessors/libresnet50postprocess.so" + "postProcessLibPath": "../../../../lib/modelpostprocessors/libresnet50postprocess.so" }, "factory": "mxpi_classpostprocessor", "next": "mxpi_dataserialize0" diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/run_densenet.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/run_densenet.sh index fe7de08296..7d04a39fa1 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/run_densenet.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/sdk_run_infer/run_densenet.sh @@ -22,12 +22,5 @@ CUR_PATH=$(cd "$(dirname "$0")" || { warn "Failed to check path/to/run.sh" ; exi info() { echo -e "\033[1;34m[INFO ][MxStream] $1\033[1;37m" ; } warn() { echo >&2 -e "\033[1;31m[WARN ][MxStream] $1\033[1;37m" ; } -export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:${LD_LIBRARY_PATH} -export GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner -export GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins - -#to set PYTHONPATH, import the StreamManagerApi.py -export PYTHONPATH=$PYTHONPATH:${MX_SDK_HOME}/python - -python3.7 main_densenet_opencv.py +python3 main_densenet_opencv.py exit 0 diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh index 80dcfbf8c3..39e1cb45c4 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh @@ -175,4 +175,4 @@ echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${C 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 +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh index 4c8482b67c..1b00b4168e 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh @@ -133,7 +133,7 @@ then --device-list '0,1,2,3,4,5,6,7' \ --amp \ --benchmark 0 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & done else for i in $(seq 0 7) @@ -213,4 +213,4 @@ echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${C 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 "TrainAccuracy = ${train_accuracy}" >> ${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 +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh index 48c18be1d4..d57dbe2a73 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh @@ -176,4 +176,4 @@ echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${Cas 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 +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh index 0175d3c3e4..2f9653a51f 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh @@ -219,4 +219,4 @@ echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${Cas 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 +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -- Gitee