forked from huawei/mindspore2022
add standalone train to ssd
This commit is contained in:
parent
5ee636c519
commit
0b34ee6546
|
|
@ -312,6 +312,12 @@ To train the model, run `train.py`. If the `mindrecord_dir` is empty, it will ge
|
|||
bash run_distribute_train.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE] [CONFIG_PATH] [PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)
|
||||
```
|
||||
|
||||
- Standalone training
|
||||
|
||||
```shell
|
||||
bash run_standalone_train.sh [DEVICE_ID] [EPOCH_SIZE] [LR] [DATASET] [PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)
|
||||
```
|
||||
|
||||
We need five or seven parameters for this scripts.
|
||||
|
||||
- `DEVICE_NUM`: the device number for distributed train.
|
||||
|
|
|
|||
|
|
@ -110,6 +110,11 @@ SSD方法基于前向卷积网络,该网络产生固定大小的边界框集
|
|||
sh run_distribute_train.sh [DEVICE_NUM] [EPOCH_SIZE] [LR] [DATASET] [RANK_TABLE_FILE] [CONFIG_PATH]
|
||||
```
|
||||
|
||||
```shell script
|
||||
# Ascend单卡训练
|
||||
bash run_standalone_train.sh [DEVICE_ID] [EPOCH_SIZE] [LR] [DATASET]
|
||||
```
|
||||
|
||||
```shell script
|
||||
# Ascend处理器环境运行eval
|
||||
sh run_eval.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID] [CONFIG_PATH]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2021 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 "=============================================================================================================="
|
||||
echo "Please run the script as: "
|
||||
echo "sh run_distribute_train.sh DEVICE_ID EPOCH_SIZE LR DATASET PRE_TRAINED PRE_TRAINED_EPOCH_SIZE"
|
||||
echo "for example: sh run_distribute_train.sh 0 500 0.2 coco /opt/ssd-300.ckpt(optional) 200(optional)"
|
||||
echo "It is better to use absolute path."
|
||||
echo "================================================================================================================="
|
||||
|
||||
if [ $# != 4 ] && [ $# != 6 ]
|
||||
then
|
||||
echo "Usage: sh run_distribute_train.sh [DEVICE_ID] [EPOCH_SIZE] [LR] [DATASET] \
|
||||
[PRE_TRAINED](optional) [PRE_TRAINED_EPOCH_SIZE](optional)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Before start distribute train, first create mindrecord files.
|
||||
BASE_PATH=$(cd "`dirname $0`" || exit; pwd)
|
||||
cd $BASE_PATH/../ || exit
|
||||
python train.py --only_create_dataset=True --dataset=$4
|
||||
|
||||
echo "After running the script, the network runs in the background. The log will be generated in LOGx/log.txt"
|
||||
DEVICE_ID=$1
|
||||
EPOCH_SIZE=$2
|
||||
LR=$3
|
||||
DATASET=$4
|
||||
PRE_TRAINED=$5
|
||||
PRE_TRAINED_EPOCH_SIZE=$6
|
||||
|
||||
export DEVICE_ID=$DEVICE_ID
|
||||
rm -rf LOG$DEVICE_ID
|
||||
mkdir ./LOG$DEVICE_ID
|
||||
cp ./*.py ./LOG$DEVICE_ID
|
||||
cp -r ./src ./LOG$DEVICE_ID
|
||||
cd ./LOG$DEVICE_ID || exit
|
||||
|
||||
echo "start training with device $DEVICE_ID"
|
||||
env > env.log
|
||||
if [ $# == 4 ]
|
||||
then
|
||||
python train.py \
|
||||
--lr=$LR \
|
||||
--dataset=$DATASET \
|
||||
--device_id=$DEVICE_ID \
|
||||
--epoch_size=$EPOCH_SIZE > log.txt 2>&1 &
|
||||
fi
|
||||
|
||||
if [ $# == 6 ]
|
||||
then
|
||||
python train.py \
|
||||
--lr=$LR \
|
||||
--dataset=$DATASET \
|
||||
--device_id=$DEVICE_ID \
|
||||
--pre_trained=$PRE_TRAINED \
|
||||
--pre_trained_epoch_size=$PRE_TRAINED_EPOCH_SIZE \
|
||||
--epoch_size=$EPOCH_SIZE > log.txt 2>&1 &
|
||||
fi
|
||||
|
||||
cd ../
|
||||
|
|
@ -34,7 +34,7 @@ parser.add_argument('--log_path', type=str, default='outputs/', help='checkpoint
|
|||
|
||||
# detect_related
|
||||
parser.add_argument('--nms_thresh', type=float, default=0.5, help='threshold for NMS')
|
||||
parser.add_argument('--ann_file', type=str, default='', help='path to annotation')
|
||||
parser.add_argument('--ann_val_file', type=str, default='', help='path to annotation')
|
||||
parser.add_argument('--eval_ignore_threshold', type=float, default=0.001, help='threshold to throw low quality boxes')
|
||||
|
||||
parser.add_argument('--img_id_file_path', type=str, default='', help='path of image dataset')
|
||||
|
|
@ -64,7 +64,7 @@ if __name__ == "__main__":
|
|||
# init detection engine
|
||||
detection = DetectionEngine(args)
|
||||
|
||||
coco = COCO(args.ann_file)
|
||||
coco = COCO(args.ann_val_file)
|
||||
result_path = args.result_files
|
||||
|
||||
files = os.listdir(args.img_id_file_path)
|
||||
|
|
@ -91,8 +91,9 @@ if __name__ == "__main__":
|
|||
detection.do_nms_for_results()
|
||||
result_file_path = detection.write_result()
|
||||
args.logger.info('result file path: {}'.format(result_file_path))
|
||||
args.logger.info('\n=============coco eval reulst=========\n')
|
||||
eval_result = detection.get_eval_result()
|
||||
|
||||
for item in eval_result:
|
||||
print(item)
|
||||
cost_time = time.time() - start_time
|
||||
args.logger.info('\n=============coco eval reulst=========\n' + eval_result)
|
||||
args.logger.info('testing cost time {:.2f}h'.format(cost_time / 3600.))
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ function infer()
|
|||
|
||||
function cal_acc()
|
||||
{
|
||||
python3.7 ../postprocess.py --ann_file=$annotation_file --img_id_file_path=$data_path --result_files=./result_Files &> acc.log &
|
||||
python3.7 ../postprocess.py --ann_avl_file=$annotation_file --img_id_file_path=$data_path --result_files=./result_Files &> acc.log &
|
||||
}
|
||||
|
||||
compile_app
|
||||
|
|
|
|||
Loading…
Reference in New Issue