diff --git a/research/cv/PAGENet/README.md b/research/cv/PAGENet/README.md index 13245b0e33e107025d47d7dab430bcef808f1fce..f01974c3f1fc3d806b9ac5d564c025c0a5ccb95a 100644 --- a/research/cv/PAGENet/README.md +++ b/research/cv/PAGENet/README.md @@ -37,7 +37,7 @@ PAGE-Net缃戠粶鐢变笁涓儴鍒嗙粍鎴愶紝鎻愬彇鐗瑰緛鐨凜NN妯″潡锛岄噾瀛楀娉ㄦ剰 ### 鏁版嵁闆嗛厤缃� -鏁版嵁闆嗙洰褰曚慨鏀瑰湪config.py涓紝璁粌闆嗗彉閲忎负train_dataset_imgs,train_dataset_gts,train_dataset_edges, +鏁版嵁闆嗙洰褰曚慨鏀瑰湪config.py涓紝璁粌闆嗗彉閲忎负train_dataset_imgs,train_dataset_gts,train_dataset_edges, vgg_init 娴嬭瘯闆嗚矾寰勮鑷淇敼 娴嬭瘯闆嗚嫢瑕佷娇鐢ㄨ嚜宸辩殑鏁版嵁闆嗭紝璇锋坊鍔犳暟鎹泦璺緞锛屽苟鍦╰rain.py涓坊鍔犳柊澧炵殑鏁版嵁闆� @@ -84,11 +84,10 @@ PAGE-Net缃戠粶鐢变笁涓儴鍒嗙粍鎴愶紝鎻愬彇鐗瑰緛鐨凜NN妯″潡锛岄噾瀛楀娉ㄦ剰 鈹溾攢鈹€ default_config_ascend.yaml # 鍙傛暟閰嶇疆鑴氭湰鏂囦欢(ascned) 鈹溾攢鈹€ default_config_gpu.yaml # 鍙傛暟閰嶇疆鑴氭湰鏂囦欢(gpu) 鈹溾攢鈹€ scripts - 鈹� 鈹溾攢鈹€ run_standalone_train_gpu.sh # 鍗曞崱璁粌鑴氭湰鏂囦欢(gpu) - 鈹� 鈹溾攢鈹€ run_standalone_train.sh # 鍗曞崱璁粌鑴氭湰鏂囦欢(ascend) + 鈹� 鈹溾攢鈹€ run_standalone_train.sh # 鍗曞崱璁粌鑴氭湰鏂囦欢(ascend & gpu) 鈹� 鈹溾攢鈹€ run_distribute_train_gpu.sh # 澶氬崱璁粌鑴氭湰鏂囦欢(gpu) 鈹� 鈹溾攢鈹€ run_distribute_train.sh # 澶氬崱璁粌鑴氭湰鏂囦欢(ascend) - 鈹� 鈹溾攢鈹€ run_eval.sh # 璇勪及鑴氭湰鏂囦欢 + 鈹� 鈹溾攢鈹€ run_eval.sh # 璇勪及鑴氭湰鏂囦欢(ascend & gpu) 鈹溾攢鈹€ src | 鈹溾攢鈹€ model_utils | | 鈹溾攢鈹€ config.py @@ -124,17 +123,15 @@ model: "output/PAGENET.ckpt" # 娴嬭瘯鏃朵娇鐢ㄧ殑checkpoint鏂囦欢 ### 璁粌 -```markdown -cd scripts -bash run_standalone_train_gpu.sh [CONFIG_PATH] #杩愯gpu鍗曞崱璁粌 -bash run_standalone_train.sh [CONFIG_PATH] #杩愯ascend鍗曞崱璁粌,config璺緞榛樿涓篴scend +```shell +bash scripts/run_standalone_train.sh [DEVICE_ID] [CONFIG_PATH] #杩愯鍗曞崱璁粌,config璺緞榛樿涓篴scend ``` ### 鍒嗗竷寮忚缁� -```markdown -bash run_distribute_train_gpu.sh [CONFIG_PATH] #杩愯gpu鍒嗗竷寮忚缁� -bash run_distribute_train.sh 8 rank_table_8pcs.json [CONFIG_PATH] #杩愯ascend鍒嗗竷寮忚缁冿紝config璺緞榛樿涓篴scend +```shell +bash scripts/run_distribute_gpu.sh [DEVICE_NUM] [CONFIG_PATH] #杩愯gpu鍒嗗竷寮忚缁� +bash scripts/run_distribute_train.sh [DEVICE_NUM] [RANK_TABLE_FILE] [CONFIG_PATH] #杩愯ascend鍒嗗竷寮忚缁冿紝config璺緞榛樿涓篴scend ``` ### 浜戜笂璁粌 @@ -152,13 +149,13 @@ bash run_distribute_train.sh 8 rank_table_8pcs.json [CONFIG_PATH] #杩愯asce ## 璇勪及杩囩▼ ```markdown -bash run_eval.sh [CONFIG_PATH] #杩愯鎺ㄧ悊 +bash scripts/eval.sh [DEVICE_ID] [CONFIG_PATH] #杩愯鎺ㄧ悊 ``` ## 瀵煎嚭杩囩▼ -```markdown -python export.py #瀵煎嚭mindir锛屾ā鍨嬫枃浠惰矾寰勪负config涓殑ckpt_file +```shell +python export.py --config_path=[CONFIG_PATH] #瀵煎嚭mindir锛屾ā鍨嬫枃浠惰矾寰勪负config涓殑ckpt_file ``` ## 妯″瀷鎻忚堪 diff --git a/research/cv/PAGENet/default_config_gpu.yaml b/research/cv/PAGENet/default_config_gpu.yaml index acea6fe35d5016245e3b23b5c6cacc189dc93f69..34f822a6ea5c70b9ac1bd581d87537f9c9a2c21d 100644 --- a/research/cv/PAGENet/default_config_gpu.yaml +++ b/research/cv/PAGENet/default_config_gpu.yaml @@ -11,7 +11,7 @@ test_task: "DUT-OMRON" test_img_path: "./dataset/test_dataset/DUT-OMRON/DUT-OMRON-image" test_gt_path: "./dataset/test_dataset/DUT-OMRON/DUT-OMRON-mask" -vgg_init: "" +vgg_init: "vgg16_20M.ckpt" batch_size: 10 train_size: 224 diff --git a/research/cv/PAGENet/eval.py b/research/cv/PAGENet/eval.py index a4f1c3048012aef9401aab123b40cc77aec361c1..f6a09e8a2f98c35d3791a1ae4e6d3459376fc461 100644 --- a/research/cv/PAGENet/eval.py +++ b/research/cv/PAGENet/eval.py @@ -41,7 +41,7 @@ def main(test_img_path, test_gt_path, ckpt_file): mae = nn.MAE() F_score = nn.F1() # model - model = MindsporeModel() + model = MindsporeModel(config) ckpt_file_name = ckpt_file ms.load_checkpoint(ckpt_file_name, net=model) diff --git a/research/cv/PAGENet/export.py b/research/cv/PAGENet/export.py index 047048dfe2bac21b86328bcf3049eeec5999c97f..2a493a322b5d89b942ac939a8385a8531a892507 100644 --- a/research/cv/PAGENet/export.py +++ b/research/cv/PAGENet/export.py @@ -32,10 +32,10 @@ def run_export(): """ context.set_context(mode=context.GRAPH_MODE, device_target=config.device_target) - net = MindsporeModel() + net = MindsporeModel(config) if not os.path.exists(config.ckpt_file): - print("config.ckpt_file is None.") + raise ValueError("config.ckpt_file is None.") param_dict = load_checkpoint(config.ckpt_file) load_param_into_net(net, param_dict) diff --git a/research/cv/PAGENet/scripts/run_distribute_train.sh b/research/cv/PAGENet/scripts/run_distribute_train.sh index 1cb94a54a5efc506f0f1895cbc86dbc548897d32..fcbe4f5c4f530c54504e6498b8ba47243ee1e67f 100644 --- a/research/cv/PAGENet/scripts/run_distribute_train.sh +++ b/research/cv/PAGENet/scripts/run_distribute_train.sh @@ -14,16 +14,35 @@ # limitations under the License. # ============================================================================ +if [ $# != 3 ] +then + echo "Usage: bash scripts/run_distribute_train.sh [DEVICE_NUM] [RANK_TABLE_FILE] [CONFIG_PATH]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + BASE_DIR=$(cd "$(dirname "$0")" || exit; pwd) RANK_SIZE=$1 -RANK_TABLE_FILE=$2 - -echo $RANK_TABLE_FILE +RANK_TABLE_FILE=$(get_real_path $2) +CONFIG_PATH=$(get_real_path $3) if [ ! -f ${RANK_TABLE_FILE} ]; then -echo "${RANK_TABLE_FILE} file not exists" +echo "rank table ${RANK_TABLE_FILE} file not exists" exit fi + +if [ ! -f ${CONFIG_PATH} ]; then +echo "config path ${CONFIG_PATH} file not exists" +exit +fi + export RANK_TABLE_FILE=${RANK_TABLE_FILE} export RANK_SIZE=${RANK_SIZE} rank_start=0 @@ -36,11 +55,13 @@ do rm -rf device$DEVICE_ID mkdir device$DEVICE_ID - ln -s $BASE_DIR/../data ./device$DEVICE_ID cp -r $BASE_DIR/../src ./device$DEVICE_ID cp $BASE_DIR/../*.py ./device$DEVICE_ID - cp $BASE_DIR/../*.ckpt ./device$DEVICE_ID + cp $BASE_DIR/../*.yaml ./device$DEVICE_ID cd ./device$DEVICE_ID - python -u ./train.py --train_mode 'distribute' config_path $3 > train.log 2>&1 & + python -u ./train.py \ + --train_mode="distribute" \ + --device_target="Ascend" \ + --config_path=$CONFIG_PATH > train.log 2>&1 & cd ../ done diff --git a/research/cv/PAGENet/scripts/run_distribute_train_gpu.sh b/research/cv/PAGENet/scripts/run_distribute_train_gpu.sh index f7b7ef4b79da599196b4bf25665ad39f719f8cd6..b7c2bfd8ffabb3f82e34a14a709d98caa0396c52 100644 --- a/research/cv/PAGENet/scripts/run_distribute_train_gpu.sh +++ b/research/cv/PAGENet/scripts/run_distribute_train_gpu.sh @@ -15,9 +15,9 @@ # ============================================================================ # Get absolute path -if [ $# != 1 ] +if [ $# != 2 ] then - echo "Usage: bash run_distribute_gpu.sh [CONFIG_PATH]" + echo "Usage: bash scripts/run_distribute_gpu.sh [DEVICE_NUM] [CONFIG_PATH]" exit 1 fi @@ -31,9 +31,18 @@ get_real_path(){ # Get current script path BASE_PATH=$(cd "`dirname $0`" || exit; pwd) +CONFIG_PATH=$(get_real_path $2) + +if [ ! -f ${CONFIG_PATH} ]; then +echo "config path ${CONFIG_PATH} file not exists" +exit +fi cd $BASE_PATH/.. -mpirun --allow-run-as-root -n 8 python train.py --train_mode 'distribute' --config_path $1 &> distribute.log 2>&1 & +mpirun --allow-run-as-root -n $1 python train.py \ + --train_mode="distribute" \ + --device_target="GPU" \ + --config_path=$CONFIG_PATH &> distribute.log 2>&1 & echo "The train log is at ../distribute.log." diff --git a/research/cv/PAGENet/scripts/run_eval.sh b/research/cv/PAGENet/scripts/run_eval.sh index d744bc2937bf3872ea1c3c589686c6561ef26496..b355fe10c3a27e55a602e44dfcaab4a3b9c4011a 100644 --- a/research/cv/PAGENet/scripts/run_eval.sh +++ b/research/cv/PAGENet/scripts/run_eval.sh @@ -13,11 +13,31 @@ # See the License for the specific language governing permissions and # limitations under the License. # ========================================================================= -if [ $# != 1 ] +if [ $# != 2 ] then - echo "Usage: bash run_eval.sh [CONFIG_PATH]" + echo "Usage: bash scripts/eval.sh [DEVICE_ID] [CONFIG_PATH]" exit 1 fi +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} -cd .. -python eval.py --config_path $1 &> test.log 2>&1 & +export DEVICE_ID=$1 +export CUDA_VISIBLE_DEVICES=$1 +export RANK_ID=0 +CONFIG_PATH=$(get_real_path $2) + +if [ ! -f ${CONFIG_PATH} ]; then +echo "config path ${CONFIG_PATH} file not exists" +exit +fi +# Get current script path +BASE_PATH=$(cd "`dirname $0`" || exit; pwd) + +cd $BASE_PATH/.. +python eval.py --config_path=$CONFIG_PATH &> test.log 2>&1 & +echo "The eval log is at $BASE_PATH/../test.log." diff --git a/research/cv/PAGENet/scripts/run_standalone_train.sh b/research/cv/PAGENet/scripts/run_standalone_train.sh index 6c0d7ed79423c3a32926914c62f734f6b0f41420..2ff24f2df42fd487753d259a63c1bd4394c6137f 100644 --- a/research/cv/PAGENet/scripts/run_standalone_train.sh +++ b/research/cv/PAGENet/scripts/run_standalone_train.sh @@ -13,7 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -421 + +if [ $# != 2 ] +then + echo "Usage: bash scripts/run_standalone_train.sh [DEVICE_ID] [CONFIG_PATH]" +exit 1 +fi + get_real_path(){ if [ "${1:0:1}" == "/" ]; then echo "$1" @@ -21,13 +27,21 @@ get_real_path(){ echo "$(realpath -m $PWD/$1)" fi } -export DEVICE_ID=0 -export RANK_ID=0 + +export DEVICE_ID=$1 +export CUDA_VISIBLE_DEVICES=$1 +export RANK_ID=0 +CONFIG_PATH=$(get_real_path $2) + +if [ ! -f ${CONFIG_PATH} ]; then +echo "config path ${CONFIG_PATH} file not exists" +exit +fi # Get current script path BASE_PATH=$(cd "`dirname $0`" || exit; pwd) cd $BASE_PATH/.. -python train.py --config_path $1 &> standalone_train.log 2>&1 & +python train.py --config_path=$CONFIG_PATH &> standalone_train.log 2>&1 & -echo "The train log is at ../standalone_train.log." \ No newline at end of file +echo "The train log is at $BASE_PATH/../standalone_train.log." diff --git a/research/cv/PAGENet/scripts/run_standalone_train_gpu.sh b/research/cv/PAGENet/scripts/run_standalone_train_gpu.sh deleted file mode 100644 index e26938b192dd2620e216198f952e91c59a26f026..0000000000000000000000000000000000000000 --- a/research/cv/PAGENet/scripts/run_standalone_train_gpu.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -echo "Usage: bash run_standalone_train_gpu.sh " -# Get absolute path -get_real_path(){ - if [ "${1:0:1}" == "/" ]; then - echo "$1" - else - echo "$(realpath -m $PWD/$1)" - fi -} - -# Get current script path -BASE_PATH=$(cd "`dirname $0`" || exit; pwd) - -cd $BASE_PATH/.. - -python train.py --train_mode 'single' --config_path $1 &> standalone_train.log 2>&1 & - -echo "The train log is at ../standalone_train.log." diff --git a/research/cv/PAGENet/src/model_utils/config.py b/research/cv/PAGENet/src/model_utils/config.py index 647f3cdcaf7c612cb4feed9984fe1fcf5acba461..d04085728314afcac93aabeda26f89eed0105bb5 100644 --- a/research/cv/PAGENet/src/model_utils/config.py +++ b/research/cv/PAGENet/src/model_utils/config.py @@ -129,6 +129,7 @@ def get_config(): "../../default_config_ascend.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() + print(f"config path is {path_args.config_path}") default, helper, choices = parse_yaml(path_args.config_path) args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) diff --git a/research/cv/PAGENet/train.py b/research/cv/PAGENet/train.py index 755c8fbe25582c6b6a8544e1ca7469e4af9e568e..fe22a8f31d03f354228a877a2e571e7a72b3c221 100644 --- a/research/cv/PAGENet/train.py +++ b/research/cv/PAGENet/train.py @@ -25,6 +25,8 @@ from src.model_utils.config import config from src.model_utils.moxing_adapter import moxing_wrapper from src.mytrainonestep import CustomTrainOneStepCell +ms.set_seed(1) + @moxing_wrapper() def main(): context.set_context(mode=config.MODE,