From b42ba6c48b453ae8a7e5d27006531f217f042ebb Mon Sep 17 00:00:00 2001 From: chenzomi Date: Tue, 26 May 2020 10:06:33 +0800 Subject: [PATCH] fix bug in model zoo for mobilenet --- mindspore/model_zoo/mobilenetv2/Readme.md | 2 +- mindspore/model_zoo/mobilenetv2/eval.py | 4 +++- .../mobilenetv2/scripts/run_infer.sh | 2 +- .../mobilenetv2/scripts/run_train.sh | 8 +++---- mindspore/model_zoo/mobilenetv2/train.py | 2 +- mindspore/model_zoo/mobilenetv3/Readme.md | 2 +- .../mobilenetv3/scripts/run_infer.sh | 10 ++++----- .../mobilenetv3/scripts/run_train.sh | 22 +++++++++---------- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/mindspore/model_zoo/mobilenetv2/Readme.md b/mindspore/model_zoo/mobilenetv2/Readme.md index 0244aeb1bf..2ee9f0a6ab 100644 --- a/mindspore/model_zoo/mobilenetv2/Readme.md +++ b/mindspore/model_zoo/mobilenetv2/Readme.md @@ -133,7 +133,7 @@ result: {'acc': 0.71976314102564111} ckpt=/path/to/checkpoint/mobilenet-200_625. #### Inference Performance -| Parameters | GoogLeNet | | | +| Parameters | | | | | -------------------------- | ----------------------------- | ------------------------- | -------------------- | | Model Version | V1 | | | | Resource | Huawei 910 | NV SMX2 V100-32G | Huawei 310 | diff --git a/mindspore/model_zoo/mobilenetv2/eval.py b/mindspore/model_zoo/mobilenetv2/eval.py index 9e08749289..61e9c5ecd7 100644 --- a/mindspore/model_zoo/mobilenetv2/eval.py +++ b/mindspore/model_zoo/mobilenetv2/eval.py @@ -36,21 +36,23 @@ args_opt = parser.parse_args() if __name__ == '__main__': config_platform = None + net = None if args_opt.platform == "Ascend": config_platform = config_ascend device_id = int(os.getenv('DEVICE_ID')) context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=device_id, save_graphs=False) + net = mobilenet_v2(num_classes=config_platform.num_classes, platform="Ascend") elif args_opt.platform == "GPU": config_platform = config_gpu context.set_context(mode=context.GRAPH_MODE, device_target="GPU", save_graphs=False) + net = mobilenet_v2(num_classes=config_platform.num_classes, platform="GPU") else: raise ValueError("Unsupport platform.") loss = nn.SoftmaxCrossEntropyWithLogits( is_grad=False, sparse=True, reduction='mean') - net = mobilenet_v2(num_classes=config_platform.num_classes) if args_opt.platform == "Ascend": net.to_float(mstype.float16) diff --git a/mindspore/model_zoo/mobilenetv2/scripts/run_infer.sh b/mindspore/model_zoo/mobilenetv2/scripts/run_infer.sh index ee2660be7b..e200e600bf 100644 --- a/mindspore/model_zoo/mobilenetv2/scripts/run_infer.sh +++ b/mindspore/model_zoo/mobilenetv2/scripts/run_infer.sh @@ -52,4 +52,4 @@ python ${BASEPATH}/../eval.py \ --platform=$1 \ --dataset_path=$2 \ --checkpoint_path=$3 \ - &> infer.log & # dataset val folder path + &> ../infer.log & # dataset val folder path diff --git a/mindspore/model_zoo/mobilenetv2/scripts/run_train.sh b/mindspore/model_zoo/mobilenetv2/scripts/run_train.sh index 5812a37305..95f9b39b93 100644 --- a/mindspore/model_zoo/mobilenetv2/scripts/run_train.sh +++ b/mindspore/model_zoo/mobilenetv2/scripts/run_train.sh @@ -36,13 +36,13 @@ run_ascend() fi mkdir ../train cd ../train || exit - python ${BASEPATH}/../launch.py \ + python ${BASEPATH}/../src/launch.py \ --nproc_per_node=$2 \ --visible_devices=$4 \ --server_id=$3 \ - --training_script=${BASEPATH}/train.py \ + --training_script=${BASEPATH}/../train.py \ --dataset_path=$5 \ - --platform=$1 &> train.log & # dataset train folder + --platform=$1 &> ../train.log & # dataset train folder } run_gpu() @@ -73,7 +73,7 @@ run_gpu() python ${BASEPATH}/../train.py \ --dataset_path=$4 \ --platform=$1 \ - &> train.log & # dataset train folder + &> ../train.log & # dataset train folder } if [ $# -gt 5 ] || [ $# -lt 4 ] diff --git a/mindspore/model_zoo/mobilenetv2/train.py b/mindspore/model_zoo/mobilenetv2/train.py index 90def9989a..9b7b63aaca 100644 --- a/mindspore/model_zoo/mobilenetv2/train.py +++ b/mindspore/model_zoo/mobilenetv2/train.py @@ -216,7 +216,7 @@ if __name__ == '__main__': init() epoch_size = config_ascend.epoch_size - net = mobilenet_v2(num_classes=config_ascend.num_classes) + net = mobilenet_v2(num_classes=config_ascend.num_classes, platform="Ascend") net.to_float(mstype.float16) for _, cell in net.cells_and_names(): if isinstance(cell, nn.Dense): diff --git a/mindspore/model_zoo/mobilenetv3/Readme.md b/mindspore/model_zoo/mobilenetv3/Readme.md index 75f3e2fbe2..fa5ca1ae77 100644 --- a/mindspore/model_zoo/mobilenetv3/Readme.md +++ b/mindspore/model_zoo/mobilenetv3/Readme.md @@ -133,7 +133,7 @@ result: {'acc': 0.71976314102564111} ckpt=/path/to/checkpoint/mobilenet-200_625. #### Inference Performance -| Parameters | GoogLeNet | | | +| Parameters | | | | | -------------------------- | ----------------------------- | ------------------------- | -------------------- | | Model Version | V1 | | | | Resource | Huawei 910 | NV SMX2 V100-32G | Huawei 310 | diff --git a/mindspore/model_zoo/mobilenetv3/scripts/run_infer.sh b/mindspore/model_zoo/mobilenetv3/scripts/run_infer.sh index 0254d1c554..e200e600bf 100644 --- a/mindspore/model_zoo/mobilenetv3/scripts/run_infer.sh +++ b/mindspore/model_zoo/mobilenetv3/scripts/run_infer.sh @@ -42,14 +42,14 @@ export RANK_ID=0 export RANK_SIZE=1 if [ -d "eval" ]; then - rm -rf ./eval + rm -rf ../eval fi -mkdir ./eval -cd ./eval || exit +mkdir ../eval +cd ../eval || exit # luanch -python ${BASEPATH}/eval.py \ +python ${BASEPATH}/../eval.py \ --platform=$1 \ --dataset_path=$2 \ --checkpoint_path=$3 \ - &> infer.log & # dataset val folder path + &> ../infer.log & # dataset val folder path diff --git a/mindspore/model_zoo/mobilenetv3/scripts/run_train.sh b/mindspore/model_zoo/mobilenetv3/scripts/run_train.sh index ee4edb93eb..78b79b235f 100644 --- a/mindspore/model_zoo/mobilenetv3/scripts/run_train.sh +++ b/mindspore/model_zoo/mobilenetv3/scripts/run_train.sh @@ -31,17 +31,17 @@ run_ascend() export PYTHONPATH=${BASEPATH}:$PYTHONPATH if [ -d "train" ]; then - rm -rf ./train + rm -rf ../train fi - mkdir ./train - cd ./train || exit - python ${BASEPATH}/launch.py \ + mkdir ../train + cd ../train || exit + python ${BASEPATH}/../src/launch.py \ --nproc_per_node=$2 \ --visible_devices=$4 \ --server_id=$3 \ - --training_script=${BASEPATH}/train.py \ + --training_script=${BASEPATH}/../train.py \ --dataset_path=$5 \ - --platform=$1 &> train.log & # dataset train folder + --platform=$1 &> ../train.log & # dataset train folder } run_gpu() @@ -62,17 +62,17 @@ run_gpu() export PYTHONPATH=${BASEPATH}:$PYTHONPATH if [ -d "train" ]; then - rm -rf ./train + rm -rf ../train fi - mkdir ./train - cd ./train || exit + mkdir ../train + cd ../train || exit export CUDA_VISIBLE_DEVICES="$3" mpirun -n $2 --allow-run-as-root \ - python ${BASEPATH}/train.py \ + python ${BASEPATH}/../train.py \ --dataset_path=$4 \ --platform=$1 \ - &> train.log & # dataset train folder + &> ../train.log & # dataset train folder } if [ $# -gt 5 ] || [ $# -lt 4 ]