Browse Source

upload 310 infer

master
cqu_hgh 2 years ago
parent
commit
a0df8f6531
4 changed files with 63 additions and 11 deletions
  1. +32
    -4
      README_CN.md
  2. +2
    -3
      export.py
  3. +26
    -2
      scripts/export.sh
  4. +3
    -2
      scripts/run_infer_310.sh

+ 32
- 4
README_CN.md View File

@@ -25,10 +25,9 @@
- [用法](#用法-1)
- [Ascend处理器上运行后评估各个任务的模型](#Ascend处理器上运行后评估各个任务的模型)
- [GPU上运行后评估各个任务的模型](#GPU上运行后评估各个任务的模型)
- [模型描述](#模型描述)
- [性能](#性能)
- [预训练性能](#预训练性能)
- [推理性能](#推理性能)
- [310推理](#310推理)
- [导出模型](#导出模型)
- [用法](#在ascend310执行推理)
- [随机情况说明](#随机情况说明)
- [ModelZoo主页](#modelzoo主页)

@@ -406,6 +405,35 @@ evaling...
Accuracy : 0.8082890070921985
```

## 310推理

### 导出模型

```shell
bash scripts/export.sh
# export finetune ckpt to mindir
```

参数`ckpt_file`,`file_format`需要在`export.sh`中设置。

### 在Ascend310执行推理

以下展示了使用mindir模型执行推理的示例。

```shell
# Ascend310推理
bash scripts/run_infer_310.sh [MINDIR_PATH] [DATA_FILE_PATH] [NEED_PREPROCESS] [DEVICE_ID] [DATASET]
```
- `MINDIR_PATH` 为ckpt导出的mindir模型文件路径。
- `DATA_FILE_PATH` 为预处理为MindRecord格式的测试数据。
- `NEED_PREPROCESS` 表示数据是否需要预处理,取值范围为:'y' 或者 'n'。
- `DEVICE_ID` 可选,默认值为0。
- `DATASET` 为执行推理的数据集,可选,数据集包括['atis', 'mrda', 'swda', 'udc'],默认值为'atis'。

### 结果

推理结果保存在脚本执行的当前路径,精度计算结果可以在acc.log中看到。

# 随机情况说明

run_dgu.sh中设置train_data_shuffle为true,eval_data_shuffle为false,默认对数据集进行轮换操作。


+ 2
- 3
export.py View File

@@ -20,12 +20,11 @@ import mindspore.common.dtype as mstype
from mindspore import Tensor, context, load_checkpoint, export

from src.finetune_eval_config import bert_net_cfg
from src.finetune_eval_model import BertCLSModel
from src.bert_for_finetune import BertCLS
parser = argparse.ArgumentParser(description="Bert export")
parser.add_argument("--device_id", type=int, default=0, help="Device id")
parser.add_argument("--batch_size", type=int, default=16, help="batch size")
parser.add_argument("--number_labels", type=int, default=16, help="batch size")
parser.add_argument("--batch_size", type=int, default=1, help="batch size")
parser.add_argument("--number_labels", type=int, default=26, help="batch size")
parser.add_argument("--ckpt_file", type=str, required=True, help="Bert ckpt file.")
parser.add_argument("--file_name", type=str, default="Bert", help="bert output air name.")
parser.add_argument("--file_format", type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format")


+ 26
- 2
scripts/export.sh View File

@@ -15,9 +15,33 @@
# ============================================================================

python export.py --device_id=0 \
--batch_size=32 \
--batch_size=1 \
--number_labels=26 \
--ckpt_file=/home/ma-user/work/ckpt/atis_intent/0.9791666666666666_atis_intent-11_155.ckpt \
--ckpt_file=./ckpt/atis_intent/atis_intent-11_155.ckpt \
--file_name=atis_intent.mindir \
--file_format=MINDIR \
--device_target=Ascend

python export.py --device_id=0 \
--batch_size=1 \
--number_labels=5 \
--ckpt_file=./ckpt/mrda/mrda-7_2364.ckpt \
--file_name=mrda.mindir \
--file_format=MINDIR \
--device_target=Ascend

python export.py --device_id=0 \
--batch_size=1 \
--number_labels=42 \
--ckpt_file=./ckpt/swda/swda-3_6094.ckpt \
--file_name=swda.mindir \
--file_format=MINDIR \
--device_target=Ascend

python export.py --device_id=0 \
--batch_size=1 \
--number_labels=2 \
--ckpt_file=./ckpt/udc/udc-2_31250.ckpt \
--file_name=udc.mindir \
--file_format=MINDIR \
--device_target=Ascend

+ 3
- 2
scripts/run_infer_310.sh View File

@@ -15,9 +15,10 @@
# ============================================================================

if [[ $# -lt 4 || $# -gt 5 ]]; then
echo "Usage: bash run_infer_310.sh [MINDIR_PATH] [DATA_FILE_PATH] [NEED_PREPROCESS] [DEVICE_ID] [DATASET]
echo "Usage: bash scripts/run_infer_310.sh [MINDIR_PATH] [DATA_FILE_PATH] [NEED_PREPROCESS] [DEVICE_ID] [DATASET]
NEED_PREPROCESS means weather need preprocess or not, it's value is 'y' or 'n'.
DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero"
DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero.
Example: bash scripts/run_infer_310.sh ./mindir/atis_intent.mindir ./data/atis_intent/atis_intent_test.mindrecord y 0 atis"
exit 1
fi



Loading…
Cancel
Save