!19058 add prarmeter for ssd-resnet50 inference

Merge pull request !19058 from 于振华/fix_ssd_resnet50_master
This commit is contained in:
i-robot 2021-06-30 03:44:30 +00:00 committed by Gitee
commit 83a6fb44d5
4 changed files with 19 additions and 10 deletions

View File

@ -300,7 +300,7 @@ Current batch_ Size can only be set to 1.
```shell
# Ascend310 inference
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [DEVICE_ID]
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [ANNO_FILE] [DEVICE_ID]
```
Inference result will be stored in the example path, you can find result like the followings in acc.log.

View File

@ -256,6 +256,13 @@ python export.py --ckpt_file [CKPT_PATH] --device_target [DEVICE_TARGET] --file_
在还行推理之前我们需要先导出模型。Air模型只能在昇腾910环境上导出mindir可以在任意环境上导出。batch_size只支持1。
```shell
# Ascend310 inference
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [ANNO_FILE] [DEVICE_ID]
```
推理结果被保存到了当前目录可以在acc.log中获得类似下面的结果。
```shell
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.327
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.475

View File

@ -25,6 +25,7 @@ batch_size = 1
parser = argparse.ArgumentParser(description="ssd acc calculation")
parser.add_argument("--result_path", type=str, required=True, help="result files path.")
parser.add_argument("--img_path", type=str, required=True, help="image file path.")
parser.add_argument("--anno_file", type=str, required=True, help="annotation file.")
parser.add_argument("--drop", action="store_true", help="drop iscrowd images or not.")
args = parser.parse_args()
@ -34,15 +35,13 @@ def get_imgSize(file_name):
def get_result(result_path, img_id_file_path):
"""print the mAP"""
anno_json = os.path.join(config.coco_root, config.instances_set.format(config.val_data_type))
if args.drop:
from pycocotools.coco import COCO
train_cls = config.classes
train_cls_dict = {}
for i, cls in enumerate(train_cls):
train_cls_dict[cls] = i
coco = COCO(anno_json)
coco = COCO(args.anno_file)
classs_dict = {}
cat_ids = coco.loadCats(coco.getCatIds())
for cat in cat_ids:
@ -83,7 +82,7 @@ def get_result(result_path, img_id_file_path):
"img_id": img_id,
"image_shape": image_shape
})
mAP = metrics(pred_data, anno_json)
mAP = metrics(pred_data, args.anno_file)
print(f" mAP:{mAP}")
if __name__ == '__main__':

View File

@ -14,9 +14,10 @@
# limitations under the License.
# ============================================================================
if [[ $# -lt 3 || $# -gt 4 ]]; then
echo "Usage: bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [DEVICE_ID]
if [[ $# -lt 4 || $# -gt 5 ]]; then
echo "Usage: bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DVPP] [ANNO_FILE] [DEVICE_ID]
DVPP is mandatory, and must choose from [DVPP|CPU], it's case-insensitive
ANNO_PATH is mandatory, and should specify annotation file path of your data including file name.
DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero"
exit 1
fi
@ -31,15 +32,17 @@ get_real_path(){
model=$(get_real_path $1)
data_path=$(get_real_path $2)
DVPP=${3^^}
anno=$(get_real_path $4)
device_id=0
if [ $# == 4 ]; then
device_id=$4
if [ $# == 5 ]; then
device_id=$5
fi
echo "mindir name: "$model
echo "dataset path: "$data_path
echo "image process mode: "$DVPP
echo "anno file: "$anno
echo "device id: "$device_id
export ASCEND_HOME=/usr/local/Ascend/
@ -85,7 +88,7 @@ function infer()
function cal_acc()
{
python3.7 ../postprocess.py --result_path=./result_Files --img_path=$data_path --drop &> acc.log &
python3.7 ../postprocess.py --result_path=./result_Files --img_path=$data_path --anno_file=$anno --drop &> acc.log &
}
compile_app