From 21187aa861cd9b688e164594e033fefb70249941 Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 06:38:54 +0000 Subject: [PATCH 1/9] add ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md. Signed-off-by: lrving <2415912278@qq.com> --- .../built-in/cv/YOLOv3_for_ACL/README_EN.md | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md diff --git a/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md new file mode 100644 index 000000000..806f8b624 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md @@ -0,0 +1,126 @@ + + +# Yolov3 Inference for Tensorflow + +This repository provides a script and recipe to Inference the Yolov3 model. + +## Notice +**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** + +Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. + +| Conditions | Need | +| --- | --- | +| CANN Version | >=5.0.3 | +| Chip Platform| Ascend310/Ascend310P3 | +| 3rd Party Requirements| Please follow the 'requirements.txt' | + +## Quick Start Guide + +### 1. Clone the respository + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL +``` + +### 2. Requirements + +opencv-python==4.2.0.34 + + +### 3. Download and preprocess the dataset + +1. dataset + To compare with official implement, for example, we use [get_coco_dataset.sh](https://github.com/pjreddie/darknet/blob/master/scripts/get_coco_dataset.sh) to prepare our dataset. + +2. annotation file + + cd scripts + + Using script generate `coco2014_minival.txt` file. Modify the path in `coco_minival_anns.py` and `5k.txt`, then execute: + + ``` + python3 coco_minival_anns.py + ``` + + One line for one image, in the format like `image_index image_absolute_path img_width img_height box_1 box_2 ... box_n`. + Box_x format: + + - `label_index x_min y_min x_max y_max`. (The origin of coordinates is at the left top corner, left top => (xmin, ymin), right bottom => (xmax, ymax).) + - `image_index` is the line index which starts from zero. `label_index` is in range [0, class_num - 1]. + + For example: + + ``` + 0 xxx/xxx/a.jpg 1920 1080 0 453 369 473 391 1 588 245 608 268 + 1 xxx/xxx/b.jpg 1920 1080 1 466 403 485 422 2 793 300 809 320 + ... + ``` + + +### 3. Offline Inference + +**Convert pb to om.** + +- Configure the env according to your installation path + + ``` + #Please modify the environment settings as needed + export install_path=/usr/local/Ascend + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + ``` + +- convert pb to om + + [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov3_tf.pb) + + For Ascend310: + ``` + atc --model=yolov3_tf.pb --framework=3 --output=yolov3_tf_aipp --output_type=FP32 --soc_version=Ascend310 --input_shape="input:1,416,416,3" --log=info --insert_op_conf=yolov3_tf_aipp.cfg + ``` + For Ascend310P3: + ``` + atc --model=yolov3_tf.pb --framework=3 --output=yolov3_tf_aipp --output_type=FP32 --soc_version=Ascend310P3 --input_shape="input:1,416,416,3" --log=info --insert_op_conf=yolov3_tf_aipp.cfg + ``` + +- Build the program + + For Ascend310: + ``` + unset ASCEND310P3_DVPP + bash build.sh + ``` + For Ascend310P3: + ``` + export ASCEND310P3_DVPP=1 + bash build.sh + ``` + +- Run the program: + + ``` + cd scripts + bash benchmark_tf.sh --batchSize=1 --modelType=yolov3 --imgType=raw --precision=fp16 --outputType=fp32 --useDvpp=1 --deviceId=0 --modelPath=yolov3_tf_aipp.om --trueValuePath=instance_val2014.json --imgInfoFile=coco2014_minival.txt --classNamePath=../../coco.names + ``` + + + +## Performance + +### Result + +Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. + +#### Inference accuracy results + +IoU=0.5 +| model | Npu_nums | **mAP** | +| :----: | :------: | :-----: | +| Yolov3 | 1 | 55.3% | + +## Reference +[1] https://gitee.com/ascend/ModelZoo-TensorFlow/tree/master/TensorFlow/built-in/cv/detection/YoloV3_ID0076_for_TensorFlow -- Gitee From a9010cdceb331db5003343e2100ddfd6900aeefe Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 06:41:59 +0000 Subject: [PATCH 2/9] update ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md. Signed-off-by: lrving <2415912278@qq.com> --- .../built-in/cv/YOLOv3_for_ACL/README_EN.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md index 806f8b624..efdce8678 100644 --- a/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md +++ b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README_EN.md @@ -1,4 +1,4 @@ - +English|[中文](README.md) # Yolov3 Inference for Tensorflow @@ -63,15 +63,9 @@ opencv-python==4.2.0.34 **Convert pb to om.** -- Configure the env according to your installation path +- configure the env - ``` - #Please modify the environment settings as needed - export install_path=/usr/local/Ascend - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp + Please follow the [guide](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719) to set the envs ``` - convert pb to om -- Gitee From bc95afe6002a4ca32f6f70c14f08998d8269cc8c Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:04:22 +0000 Subject: [PATCH 3/9] update ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README.md. Signed-off-by: lrving <2415912278@qq.com> --- .../built-in/cv/YOLOv3_for_ACL/README.md | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README.md index f7d191f51..78e184231 100644 --- a/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL/README.md @@ -1,40 +1,40 @@ +中文|[English](README_EN.md) +# Yolov3 TensorFlow离线推理 -# Yolov3 Inference for Tensorflow +此链接提供Yolov3 TensorFlow模型在NPU上离线推理的脚本和方法 -This repository provides a script and recipe to Inference the Yolov3 model. +## 注意 +**此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。** -## Notice -**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** - -Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. +在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。 | Conditions | Need | | --- | --- | -| CANN Version | >=5.0.3 | -| Chip Platform| Ascend310/Ascend310P3 | -| 3rd Party Requirements| Please follow the 'requirements.txt' | +| CANN版本 | >=5.0.3 | +| 芯片平台| Ascend310/Ascend310P3 | +| 第三方依赖| 请参考 'requirements.txt' | -## Quick Start Guide +## 快速指南 -### 1. Clone the respository +### 1. 拷贝代码 ```shell git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/YOLOv3_for_ACL ``` -### 2. Requirements +### 2. 必要条件 opencv-python==4.2.0.34 -### 3. Download and preprocess the dataset +### 3. 下载数据集和预处理 -1. dataset - To compare with official implement, for example, we use [get_coco_dataset.sh](https://github.com/pjreddie/darknet/blob/master/scripts/get_coco_dataset.sh) to prepare our dataset. +1. 数据集 + 例如,与官方实施相比,我们使用 [get_coco_dataset.sh](https://github.com/pjreddie/darknet/blob/master/scripts/get_coco_dataset.sh) 准备我们的数据集。 -2. annotation file +2. 注释文件 cd scripts @@ -50,7 +50,7 @@ opencv-python==4.2.0.34 - `label_index x_min y_min x_max y_max`. (The origin of coordinates is at the left top corner, left top => (xmin, ymin), right bottom => (xmax, ymax).) - `image_index` is the line index which starts from zero. `label_index` is in range [0, class_num - 1]. - For example: + 例如: ``` 0 xxx/xxx/a.jpg 1920 1080 0 453 369 473 391 1 588 245 608 268 @@ -59,24 +59,17 @@ opencv-python==4.2.0.34 ``` -### 3. Offline Inference +### 3. 离线推理 -**Convert pb to om.** +**离线模型转换** -- Configure the env according to your installation path +- 环境变量设置 - ``` - #Please modify the environment settings as needed - export install_path=/usr/local/Ascend - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` + 请参考[说明](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719),设置环境变量 -- convert pb to om +- Pb模型转换为om模型 - [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov3_tf.pb) + [pb模型下载链接](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov3_tf.pb) For Ascend310: ``` @@ -87,7 +80,7 @@ opencv-python==4.2.0.34 atc --model=yolov3_tf.pb --framework=3 --output=yolov3_tf_aipp --output_type=FP32 --soc_version=Ascend310P3 --input_shape="input:1,416,416,3" --log=info --insert_op_conf=yolov3_tf_aipp.cfg ``` -- Build the program +- 编译程序 For Ascend310: ``` @@ -100,7 +93,7 @@ opencv-python==4.2.0.34 bash build.sh ``` -- Run the program: +- 开始运行: ``` cd scripts @@ -109,18 +102,18 @@ opencv-python==4.2.0.34 -## Performance +## 推理结果 -### Result +### 结果 -Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. +本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。 -#### Inference accuracy results +#### 推理精度结果 IoU=0.5 | model | Npu_nums | **mAP** | | :----: | :------: | :-----: | | Yolov3 | 1 | 55.3% | -## Reference +## 参考 [1] https://gitee.com/ascend/ModelZoo-TensorFlow/tree/master/TensorFlow/built-in/cv/detection/YoloV3_ID0076_for_TensorFlow -- Gitee From 232135bcf288d0a9dd8bdff3d516f92b6cc28e51 Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:14:32 +0000 Subject: [PATCH 4/9] add ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README_EN.md. Signed-off-by: lrving <2415912278@qq.com> --- .../built-in/cv/YOLOv4_for_ACL/README_EN.md | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README_EN.md diff --git a/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README_EN.md b/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README_EN.md new file mode 100644 index 000000000..8f8cc59ac --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README_EN.md @@ -0,0 +1,91 @@ +English|[中文](README.md) + +# YOLOv4 Inference for Tensorflow + +This repository provides a script and recipe to Inference of the YOLOv4 model. + +## Notice +**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** + +Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. + +| Conditions | Need | +| --- | --- | +| CANN Version | >=5.0.3 | +| Chip Platform| Ascend310/Ascend310P3 | +| 3rd Party Requirements| Please follow the 'requirements.txt' | + +## Quick Start Guide + +### 1. Clone the respository + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL +``` + +### 2. Download and preprocess the dataset + +1. Download the COCO-2017 validation dataset by yourself. + +2. Put pictures to **'scripts/val2017'** + +3. Images Preprocess: +``` +cd scripts +mkdir input_bins +python3 preprocess.py ./val2017/ ./input_bins/ +``` + The pictures will be preprocessed to bin files. + +4. Split ground-truth labels from **instances_val2017.json** +``` +python3 load_coco_json.py +``` + +### 3. Offline Inference + +**Convert pb to om.** + +- configure the env + + Please follow the [guide](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719) to set the envs + +- convert pb to om + + [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov4_tf.pb) + + ``` + atc --model=yolov4_tf.pb --framework=3 --output=yolov4_tf_1batch --output_type=FP32 --soc_version=Ascend310 --input_shape="x:1,416,416,3" --log=info + ``` + +- Build the program + + ``` + bash build.sh + ``` + +- Run the program: + + ``` + cd scripts + bash benchmark_tf.sh + ``` + +## Performance + +### Result + +Our result was obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. + +#### Inference accuracy results + +| model | **data** | mAP | +| :---------------: | :-------: | :-------------: | +| offline Inference | 5000 images | 60.7% | + + +## Reference +[1] https://github.com/hunglc007/tensorflow-yolov4-tflite + +[2] https://github.com/rafaelpadilla/Object-Detection-Metrics -- Gitee From 64ea11cc6689b2463ef60aa97e8d413905c17d48 Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:21:23 +0000 Subject: [PATCH 5/9] update ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README.md. Signed-off-by: lrving <2415912278@qq.com> --- .../built-in/cv/YOLOv4_for_ACL/README.md | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README.md index 70a81cab7..17bcc4b9d 100644 --- a/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL/README.md @@ -1,36 +1,36 @@ +中文|[English](README_EN.md) +# YOLOv4 TensorFlow离线推理 -# YOLOv4 Inference for Tensorflow +此链接提供YOLOv4 TensorFlow模型在NPU上离线推理的脚本和方法 -This repository provides a script and recipe to Inference of the YOLOv4 model. +## 注意 +**此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。** -## Notice -**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** - -Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. +在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。 | Conditions | Need | | --- | --- | -| CANN Version | >=5.0.3 | -| Chip Platform| Ascend310/Ascend310P3 | -| 3rd Party Requirements| Please follow the 'requirements.txt' | +| CANN版本 | >=5.0.3 | +| 芯片平台| Ascend310/Ascend310P3 | +| 第三方依赖| 请参考 'requirements.txt' | -## Quick Start Guide +## 快速指南 -### 1. Clone the respository +### 1. 拷贝代码 ```shell git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/YOLOv4_for_ACL ``` -### 2. Download and preprocess the dataset +### 2. 下载数据集和预处理 -1. Download the COCO-2017 validation dataset by yourself. +1. 自行下载COCO-2017验证数据集。 -2. Put pictures to **'scripts/val2017'** +2. 将图片放到 **'scripts/val2017'** -3. Images Preprocess: +3. 图像预处理: ``` cd scripts mkdir input_bins @@ -43,55 +43,50 @@ python3 preprocess.py ./val2017/ ./input_bins/ python3 load_coco_json.py ``` -### 3. Offline Inference +### 3. 离线推理 -**Convert pb to om.** +**离线模型转换** -- configure the env +- 环境变量设置 - ``` - export install_path=/usr/local/Ascend - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` + 请参考[说明](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719),设置环境变量 + +- Pb模型转换为om模型 -- convert pb to om - [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov4_tf.pb) + [pb模型下载链接](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/yolov4_tf.pb) ``` atc --model=yolov4_tf.pb --framework=3 --output=yolov4_tf_1batch --output_type=FP32 --soc_version=Ascend310 --input_shape="x:1,416,416,3" --log=info ``` -- Build the program +- 编译程序 ``` bash build.sh ``` -- Run the program: +- 开始运行: ``` cd scripts bash benchmark_tf.sh ``` -## Performance +## 推理结果 -### Result +### 结果 -Our result was obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. +本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。 -#### Inference accuracy results +#### 推理精度结果 | model | **data** | mAP | | :---------------: | :-------: | :-------------: | | offline Inference | 5000 images | 60.7% | -## Reference +## 参考 [1] https://github.com/hunglc007/tensorflow-yolov4-tflite [2] https://github.com/rafaelpadilla/Object-Detection-Metrics -- Gitee From 295bd38a4a2c697206c39cb7649efd73579b81ff Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:34:45 +0000 Subject: [PATCH 6/9] add ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README_EN.md. Signed-off-by: lrving <2415912278@qq.com> --- .../contrib/cv/Yolov5_for_ACL/README_EN.md | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README_EN.md diff --git a/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README_EN.md b/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README_EN.md new file mode 100644 index 000000000..794499120 --- /dev/null +++ b/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README_EN.md @@ -0,0 +1,95 @@ +English|[中文](README.md) + +# Yolov5 Inference for Tensorflow + +This repository provides a script and recipe to Inference of the Yolov5 model. + +## Notice +**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** + +Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. + +| Conditions | Need | +| --- | --- | +| CANN Version | >=5.0.3 | +| Chip Platform| Ascend310/Ascend310P3 | +| 3rd Party Requirements| Please follow the 'requirements.txt' | + +## Quick Start Guide + +### 1. Clone the respository + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd Modelzoo-TensorFlow/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL +``` + +### 2. Download and preprocess the dataset + +1. Refer to this [url](https://github.com/hunglc007/tensorflow-yolov4-tflite/README.md) to download and preprocess the dataset +The operation is as follows: +``` +# run script in /script/get_coco_dataset_2017.sh to download COCO 2017 Dataset +# preprocess coco dataset +cd data +mkdir dataset +cd .. +cd scripts +python coco_convert.py --input ./coco/annotations/instances_val2017.json --output val2017.pkl +python coco_annotation.py --coco_path ./coco +``` +There will generate coco2017 test data set under *data/dataset/*. + +### 3. Offline Inference + +**Convert pb to om.** + +- configure the env + + Please follow the [guide](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719) to set the envs + +- convert pb to om + + ``` + atc --model=yolov5_tf2_gpu.pb --framework=3 --output=yolov5_tf2_gpu --soc_version=Ascend310 --input_shape="Input:1,640,640,3" --out_nodes="Identity:0;Identity_1:0;Identity_2:0;Identity_3:0;Identity_4:0;Identity_5:0" --log=info + ``` + +- Build the program + + ``` + bash build.sh + ``` + +- Run the program: + + ``` + cd offline_inference + bash benchmark_tf.sh + ``` + +- Run the post process: + + ``` + cd .. + python3 offline_inference/postprocess.py + ``` + +## Performance + +### Result + +Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. + +#### Inference accuracy results + +| model | **data** | AP/AR | +| :---------------: | :-------: | :-----------: | +| offline Inference | 4952 images | 0.221/0.214 | + + +## Reference +[1] https://github.com/hunglc007/tensorflow-yolov4-tflite + +[2] https://github.com/ultralytics/yolov5 + +[3]https://github.com/khoadinh44/YOLOv5_customized_data -- Gitee From e0eecdc2ebf498e7c3b78fbbc2ea15aee8d85cd3 Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:40:35 +0000 Subject: [PATCH 7/9] update ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README.md. Signed-off-by: lrving <2415912278@qq.com> --- .../contrib/cv/Yolov5_for_ACL/README.md | 62 +++++++++---------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README.md b/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README.md index d7d5bed61..bff0e02ee 100644 --- a/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README.md +++ b/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL/README.md @@ -1,33 +1,33 @@ +中文|[English](README_EN.md) +# Yolov5 TensorFlow离线推理 -# Yolov5 Inference for Tensorflow +此链接提供Yolov5 TensorFlow模型在NPU上离线推理的脚本和方法 -This repository provides a script and recipe to Inference of the Yolov5 model. +## 注意 +**此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。** -## Notice -**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** - -Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. +在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。 | Conditions | Need | | --- | --- | -| CANN Version | >=5.0.3 | -| Chip Platform| Ascend310/Ascend310P3 | -| 3rd Party Requirements| Please follow the 'requirements.txt' | +| CANN版本 | >=5.0.3 | +| 芯片平台| Ascend310/Ascend310P3 | +| 第三方依赖| 请参考 'requirements.txt' | -## Quick Start Guide +## 快速指南 -### 1. Clone the respository +### 1. 拷贝代码 ```shell git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git cd Modelzoo-TensorFlow/ACL_TensorFlow/contrib/cv/Yolov5_for_ACL ``` -### 2. Download and preprocess the dataset +### 2. 下载数据集和预处理 -1. Refer to this [url](https://github.com/hunglc007/tensorflow-yolov4-tflite/README.md) to download and preprocess the dataset -The operation is as follows: +1. 参考此URL[url](https://github.com/hunglc007/tensorflow-yolov4-tflite/README.md)下载并预处理数据集 +操作如下: ``` # run script in /script/get_coco_dataset_2017.sh to download COCO 2017 Dataset # preprocess coco dataset @@ -38,62 +38,56 @@ cd scripts python coco_convert.py --input ./coco/annotations/instances_val2017.json --output val2017.pkl python coco_annotation.py --coco_path ./coco ``` -There will generate coco2017 test data set under *data/dataset/*. +生成coco2017测试数据集目录 *data/dataset/*. -### 3. Offline Inference +### 3. 离线推理 -**Convert pb to om.** +**离线模型转换** -- configure the env +- 环境变量设置 - ``` - export install_path=/usr/local/Ascend - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` + 请参考[说明](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719),设置环境变量 -- convert pb to om +- Pb模型转换为om模型 ``` atc --model=yolov5_tf2_gpu.pb --framework=3 --output=yolov5_tf2_gpu --soc_version=Ascend310 --input_shape="Input:1,640,640,3" --out_nodes="Identity:0;Identity_1:0;Identity_2:0;Identity_3:0;Identity_4:0;Identity_5:0" --log=info ``` -- Build the program +- 编译程序 ``` bash build.sh ``` -- Run the program: +- 开始运行: ``` cd offline_inference bash benchmark_tf.sh ``` -- Run the post process: +- 运行后期处理: ``` cd .. python3 offline_inference/postprocess.py ``` -## Performance +## 推理结果 -### Result +### 结果 -Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. +本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。 -#### Inference accuracy results +#### 推理精度结果 | model | **data** | AP/AR | | :---------------: | :-------: | :-----------: | | offline Inference | 4952 images | 0.221/0.214 | -## Reference +## 参考 [1] https://github.com/hunglc007/tensorflow-yolov4-tflite [2] https://github.com/ultralytics/yolov5 -- Gitee From 69efc944cb6faffbc5988aa8d735e8649bb3c6c3 Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:53:57 +0000 Subject: [PATCH 8/9] add ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README_EN.md. Signed-off-by: lrving <2415912278@qq.com> --- .../cv/Resnet50v1.5_for_ACL/README_EN.md | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README_EN.md diff --git a/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README_EN.md b/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README_EN.md new file mode 100644 index 000000000..ba5015856 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README_EN.md @@ -0,0 +1,84 @@ +English|[中文](README.md) + +# Resnet50v1.5 Inference for Tensorflow + +This repository provides a script and recipe to Inference of the Resnet50v1.5 model. + +## Notice +**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** + +Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. + +| Conditions | Need | +| --- | --- | +| CANN Version | >=5.0.3 | +| Chip Platform| Ascend310/Ascend310P3 | +| 3rd Party Requirements| Please follow the 'requirements.txt' | + +## Quick Start Guide + +### 1. Clone the respository + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL +``` + +### 2. Download and preprocess the dataset + +1. Download the ImageNet2012 Validation dataset by yourself. You can get the validation pictures(50000 JPEGS and a ILSVRC2012val-label-index.txt) + +2. Put JPEGS to **'scripts/ILSVRC2012val'** and label text to **'scripts/'** + +3. Images Preprocess: +``` +cd scripts +mkdir input_bins +python3 resnet50v15_preprocessing.py ./ILSVRC2012val/ ./input_bins/ +``` +The jpegs pictures will be preprocessed to bin fils. + +### 3. Offline Inference + +**Convert pb to om.** + +- configure the env + + Please follow the [guide](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719) to set the envs + +- convert pb to om + + [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/Official/cv/Resnet50v1.5_for_ACL/resnet50v15_tf.pb) + + ``` + atc --model=resnet50v15_tf.pb --framework=3 --output=resnet50v15_tf_1batch --output_type=FP32 --soc_version=Ascend310 --input_shape="input_tensor:1,224,224,3" --insert_op_conf=resnet50v15_aipp.cfg --enable_small_channel=1 --log=info + ``` + +- Build the program + + ``` + bash build.sh + ``` + +- Run the program: + + ``` + cd scripts + bash benchmark_tf.sh + ``` + +## Performance + +### Result + +Our result was obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. + +#### Inference accuracy results + +| model | **data** | Top1/Top5 | +| :---------------: | :-------: | :-------------: | +| offline Inference | 50000 images | 76.5 %/ 93.1% | + +## Reference + +[1] https://github.com/IntelAI/models -- Gitee From f0b35c2b631d3e619681bc37c702940f8ad3043a Mon Sep 17 00:00:00 2001 From: lrving <2415912278@qq.com> Date: Wed, 19 Oct 2022 07:58:55 +0000 Subject: [PATCH 9/9] update ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README.md. Signed-off-by: lrving <2415912278@qq.com> --- .../cv/Resnet50v1.5_for_ACL/README.md | 62 +++++++++---------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README.md index 694ccc3ad..e5cc170ec 100644 --- a/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL/README.md @@ -1,90 +1,84 @@ +中文|[English](README_EN.md) +# Resnet50v1.5 TensorFlow离线推理 -# Resnet50v1.5 Inference for Tensorflow +此链接提供Resnet50v1.5 TensorFlow模型在NPU上离线推理的脚本和方法 -This repository provides a script and recipe to Inference of the Resnet50v1.5 model. +## 注意 +**此案例仅为您学习Ascend软件栈提供参考,不用于商业目的。** -## Notice -**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** - -Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. +在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败。 | Conditions | Need | | --- | --- | -| CANN Version | >=5.0.3 | -| Chip Platform| Ascend310/Ascend310P3 | -| 3rd Party Requirements| Please follow the 'requirements.txt' | +| CANN版本 | >=5.0.3 | +| 芯片平台| Ascend310/Ascend310P3 | +| 第三方依赖| 请参考 'requirements.txt' | -## Quick Start Guide +## 快速指南 -### 1. Clone the respository +### 1. 拷贝代码 ```shell git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Resnet50v1.5_for_ACL ``` -### 2. Download and preprocess the dataset +### 2. 下载数据集和预处理 -1. Download the ImageNet2012 Validation dataset by yourself. You can get the validation pictures(50000 JPEGS and a ILSVRC2012val-label-index.txt) +1. 请自行下载ImageNet2012测试数据集。 你可以获得验证图片(50000 JPEGS and a ILSVRC2012val-label-index.txt) 2. Put JPEGS to **'scripts/ILSVRC2012val'** and label text to **'scripts/'** -3. Images Preprocess: +3. 图像预处理: ``` cd scripts mkdir input_bins python3 resnet50v15_preprocessing.py ./ILSVRC2012val/ ./input_bins/ ``` -The jpegs pictures will be preprocessed to bin fils. +jpegs图片将被预处理为bin-fils。 -### 3. Offline Inference +### 3. 离线推理 -**Convert pb to om.** +**离线模型转换** -- configure the env +- 环境变量设置 - ``` - export install_path=/usr/local/Ascend - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` + 请参考[说明](https://gitee.com/ascend/ModelZoo-TensorFlow/wikis/02.%E7%A6%BB%E7%BA%BF%E6%8E%A8%E7%90%86%E6%A1%88%E4%BE%8B/Ascend%E5%B9%B3%E5%8F%B0%E6%8E%A8%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=6458719),设置环境变量 -- convert pb to om +- Pb模型转换为om模型 - [pb download link](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/Official/cv/Resnet50v1.5_for_ACL/resnet50v15_tf.pb) + [pb模型下载链接](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/modelzoo/Official/cv/Resnet50v1.5_for_ACL/resnet50v15_tf.pb) ``` atc --model=resnet50v15_tf.pb --framework=3 --output=resnet50v15_tf_1batch --output_type=FP32 --soc_version=Ascend310 --input_shape="input_tensor:1,224,224,3" --insert_op_conf=resnet50v15_aipp.cfg --enable_small_channel=1 --log=info ``` -- Build the program +- 编译程序 ``` bash build.sh ``` -- Run the program: +- 开始运行: ``` cd scripts bash benchmark_tf.sh ``` -## Performance +## 推理结果 -### Result +### 结果 -Our result was obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. +本结果是通过运行上面适配的推理脚本获得的。要获得相同的结果,请按照《快速指南》中的步骤操作。 -#### Inference accuracy results +#### 推理精度结果 | model | **data** | Top1/Top5 | | :---------------: | :-------: | :-------------: | | offline Inference | 50000 images | 76.5 %/ 93.1% | -## Reference +## 参考 [1] https://github.com/IntelAI/models -- Gitee