diff --git a/contrib/VehicleCounting/CMakeLists.txt b/contrib/VehicleCounting/CMakeLists.txt index 256331d9dc5b64ee1dc74f6cb097d11cfac00d74..1154e1450b3b0d37f694e6f14d10de80117ade3a 100644 --- a/contrib/VehicleCounting/CMakeLists.txt +++ b/contrib/VehicleCounting/CMakeLists.txt @@ -28,6 +28,11 @@ link_directories( add_executable(${OUTPUT_NAME} main.cpp VideoProcess/VideoProcess.cpp VideoProcess/VideoProcess.h Yolov4Detection/Yolov4Detection.cpp Yolov4Detection/Yolov4Detection.h VideoProcess/KalmanTracker.h VideoProcess/KalmanTracker.cpp VideoProcess/Hungarian.h VideoProcess/Hungarian.cpp VideoProcess/MOTConnection.h VideoProcess/MOTConnection.cpp VideoProcess/DataType.h ReadConfig/GetConfig.h ReadConfig/GetConfig.cpp) +set(cpprest_DIR ${MX_SDK_HOME}/opensource/lib/libcpprest.so) +if(EXISTS ${cpprest_DIR}) + target_link_libraries(${OUTPUT_NAME} cpprest) + add_definitions(-DMX_VERSION_5) +endif() target_link_libraries(${OUTPUT_NAME} avcodec avdevice @@ -39,7 +44,6 @@ target_link_libraries(${OUTPUT_NAME} swresample glog mxbase - cpprest opencv_world pthread m yolov3postprocess diff --git a/contrib/VehicleCounting/README.md b/contrib/VehicleCounting/README.md index 2a60dc08797d8f49d32098d09904f02414c016a6..46a7e17e8493e02da41a636cf53a283235c1e308 100644 --- a/contrib/VehicleCounting/README.md +++ b/contrib/VehicleCounting/README.md @@ -4,8 +4,11 @@ ### 1.1 支持的产品 支持Atlas 500A2 ### 1.2 支持的版本 -mxVision 5.0.RC1 -Ascend-CANN-toolkit (310使用6.3.RC1,310B使用6.2.RC1) +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 5.0.0 | 7.0.0 | 23.0.0 | +| 6.0.RC2 | 8.0.RC2 | 24.1.RC2 | ### 1.3 软件方案介绍 车流统计项目实现:输入类型是视频数据(需要将视频转换为.264的视频格式),ffmpeg打开视频流获取视频帧信息,图像经过尺寸大小变换,满足模型的输入尺寸要求;将尺寸变换后的图像数据依次输入Yolov4检测模型进行推理,模型输出经过后处理后,使用SORT算法进行车辆动向得到车辆动向,再设置标志对车辆进行计数,最后得到某时刻已经通过的车辆数。 @@ -29,9 +32,10 @@ Ascend-CANN-toolkit (310使用6.3.RC1,310B使用6.2.RC1) ``` . ├── data -│ └── test1.264 +│ └── test.264 ├── model │ ├── aipp_yolov4_608_608.config +| ├── aipp_yolov3_416_416.config │ ├── coco.names │ ├── yolov4_bs.om ├── BlockingQueue @@ -55,8 +59,7 @@ Ascend-CANN-toolkit (310使用6.3.RC1,310B使用6.2.RC1) ├── CMakeLists.txt ├── main.cpp ├── params.config -├── README.md -└── run.sh +└── README.md ``` @@ -68,14 +71,8 @@ Ascend-CANN-toolkit (310使用6.3.RC1,310B使用6.2.RC1) ## 2 环境依赖 环境依赖软件和版本如下表: - - | 软件 | 版本 | 说明 | 获取方式 | -| ------------------- | ------------ | ----------------------------- | ------------------------------------------------------------ | -| mxVision | 5.0.RC1 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | -| Ascend-CANN-toolkit | 6.3.RC1或6.2.RC1 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | -| 操作系统 | ubuntu 22.04 | 操作系统 | Ubuntu官网获取 | -| ffmpeg | 4.2.1 | 视频转码解码库(编译运行使用) | [参考依赖-第三方依赖软件](../VideoGestureRecognition/README.md/)| +| ffmpeg | 4.2.1 | 视频转码解码库(编译运行使用) | [参考依赖-第三方依赖软件](../VideoGestureRecognition/README.md/)| | pc端ffmpeg | 2021-09-01 | 将视频文件格式转换为.264 | [安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/pc%E7%AB%AFffmpeg%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B.md)| @@ -83,16 +80,13 @@ Ascend-CANN-toolkit (310使用6.3.RC1,310B使用6.2.RC1) ## 3 模型转换 **步骤1** 模型获取 -[下载模型](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/VehicleCounting/modle.rar) - -解压 unrar x modle.rar - +下载[模型](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/VehicleCounting/VehicleCountingModels.zip), 并解压。 **步骤2** 模型存放 -将获取到的YOLOv4模型onnx文件存放至:"样例项目所在目录/model/"。 +将获取到的模型文件存放至:"样例项目所在目录/model/"。 **步骤3** 模型转换 -在onnx文件所在目录下执行一下命令 +在模型文件所在目录下执行以下命令 ``` # 设置环境变量(请确认install_path路径是否正确) @@ -108,20 +102,15 @@ YOLOv4: atc --model=./yolov4_dynamic_bs.onnx --framework=5 --output=yolov4_bs --input_format=NCHW --soc_version=Ascend310B1 --insert_op_conf=./aipp_yolov4_608_608.config --input_shape="input:1,3,608,608" --out_nodes="Conv_434:0;Conv_418:0;Conv_402:0" YOLOv3: -atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310B1 --insert_op_conf=./aipp_yolov3_416_416.config --input_shape="input/input_data:1,416,416,3" --out_nodes="conv_lbbox/BiasAdd:0;conv_mbbox/BiasAdd:0;convv_sbbox/BiasAdd:0" +atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310B1 --insert_op_conf=./aipp_yolov3_416_416.config --input_shape="input:1,416,416,3" --out_nodes="yolov3/yolov3_head/Conv_6/BiasAdd:0;yolov3/yolov3_head/Conv_14/BiasAdd:0;yolov3/yolov3_head/Conv_22/BiasAdd:0" # 说明:out_nodes制定了输出节点的顺序,需要与模型后处理适配。 ``` -模型转换使用了ATC工具,如需更多信息请参考: - - https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/tutorials/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99.md - -备注:若推理芯片为310B,需要将atc-env脚本中模型转换atc命令中的soc_version参数设置为Ascend310B1。 ## 4 编译与运行 -**步骤1** 通过pc端ffmpeg软件将输入视频格式转换为.264格式,如下所示为MP4转换为h.264命令: +**步骤1** 通过pc端ffmpeg软件将输入视频格式转换为.264格式,如下所示为MP4转换为h.264命令, 将转换得到的视频文件存放至:"样例项目所在目录/data/"。: [样例视频](https://github.com/jjw-DL/YOLOV3-SORT/tree/master/input) @@ -220,9 +209,17 @@ Scanning dependencies of target stream_pull_test ## 5 常见问题 ### 模型更换问题 -**问题描述** 在用YOLOv4模型替换YOLOv3模型的时候,由于模型的输入的图片resize大小不一样以及模型输出的通道顺序也不一样,会导致模型无法正常推理和后处理 +**问题描述** 在用YOLOv3模型替换YOLOv4模型的时候,由于模型的输入的图片resize大小不一样以及模型输出的通道顺序也不一样,会导致模型无法正常推理和后处理 + +**解决方案** 修改代码中相应的模型参数,YOLOv3模型输入图片大小为416x416,modelType为0,YOLOv4模型输入图片大小为608x608,modelType为1。 +``` +// 在YoloV4Detection.cpp的ResizeFrame函数中进行如下修改 +const uint32_t resizeHeight = 416; +const uint32_t resizeWidth = 416; -**解决方案** 将YolovDetection.cpp中的图片resize大小由416x416改为608x608,并将main.cpp文件里的modelType由0改为1 +// 在main.cpp中的InitYolov4Param中进行如下修改 +initParam.modelType = 0; +``` ### config文件读取异常 **问题描述** 未提及修改main.cpp中的configUtil.LoadConfiguration的路径,运行程序会报error diff --git a/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.cpp b/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.cpp index bbdfe8b2ae7a57573608e8e5d3632f53e76884e1..23747f88de82b40d0e97b509fe1380a8abc21e06 100644 --- a/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.cpp +++ b/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.cpp @@ -62,7 +62,7 @@ APP_ERROR Yolov4Detection::LoadLabels(const std::string &labelPath, std::map> &config) + std::string> &config) { MxBase::ConfigData configData; const std::string checkTensor = initParam.checkTensor ? "true" : "false"; @@ -77,9 +77,14 @@ void Yolov4Detection::SetYolov4PostProcessConfig(const InitParam &initParam, std configData.SetJsonValue("INPUT_TYPE", std::to_string(initParam.inputType)); configData.SetJsonValue("ANCHOR_DIM", std::to_string(initParam.anchorDim)); configData.SetJsonValue("CHECK_MODEL", checkTensor); - auto jsonStr = configData.GetCfgJson().serialize(); - config["postProcessConfigContent"] = std::make_shared(jsonStr); - config["labelPath"] = std::make_shared(initParam.labelPath); + #ifdef MX_VERSION_5 + auto jsonStr = configData.GetCfgJson().serialize(); + config["postProcessConfigContent"] = jsonStr; + #else + auto jsonStr = configData.GetCfgJson(); + config["postProcessConfigContent"] = jsonStr; + #endif + config["labelPath"] = initParam.labelPath; } APP_ERROR Yolov4Detection::FrameInit(const InitParam &initParam) @@ -108,7 +113,7 @@ APP_ERROR Yolov4Detection::FrameInit(const InitParam &initParam) LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; return ret; } - std::map> config; + std::map config; SetYolov4PostProcessConfig(initParam, config); post = std::make_shared(); ret = post->Init(config); diff --git a/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.h b/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.h index 4d8dc6b590172caa6899bb1636e5e2c47ae7ca03..9e62007fb0c906459bedd4df583db425d0e3709f 100644 --- a/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.h +++ b/contrib/VehicleCounting/Yolov4Detection/Yolov4Detection.h @@ -55,7 +55,7 @@ public: const uint32_t &width, std::vector> &objInfos); protected: APP_ERROR LoadLabels(const std::string &labelPath, std::map &labelMap); - void SetYolov4PostProcessConfig(const InitParam &initParam, std::map> &config); + void SetYolov4PostProcessConfig(const InitParam &initParam, std::map &config); private: std::shared_ptr yDvppWrapper; std::shared_ptr model; diff --git a/contrib/VehicleCounting/build.sh b/contrib/VehicleCounting/build.sh deleted file mode 100644 index 1a587653ad402f01bf7bb634b0dcaad05a950396..0000000000000000000000000000000000000000 --- a/contrib/VehicleCounting/build.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -# Copyright(C) 2021. Huawei Technologies Co.,Ltd. All rights reserved. -# -# 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. - -set -e - -# curr path -cur_path=$(cd "$(dirname "$0")" || exit; pwd) - -# build type -build_type="Release" - -function prepare_env() -{ - export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:/usr/local/Ascend/driver/lib64/:$LD_LIBRARY_PATH -} - -function prepare_path() { - if [ -d "$1" ]; then - rm -rf "$1" - echo "dir $1 exist, erase it and recreate." - else - echo "dir $1 is not exist." - fi - mkdir -p "$1" - cd "$1" -} - -function build() { - echo "current dir: $cur_path" - prepare_env - path_build=${cur_path}/build - prepare_path "$path_build" - - cmake -DCMAKE_BUILD_TYPE=$build_type .. - # shellcheck disable=SC2181 - if [ $? -ne 0 ]; then - echo "cmake failed" - exit 0 - fi - make -j8 - # shellcheck disable=SC2181 - if [ $? -ne 0 ]; then - echo "make failed" - exit 0 - fi - cd .. -} - -build \ No newline at end of file diff --git a/contrib/VehicleCounting/main.cpp b/contrib/VehicleCounting/main.cpp index ba225e11c02d4a32f8a22a6da44d628254d288c2..43913fdcc5f6f0e72478094f7df114e1a8598c12 100644 --- a/contrib/VehicleCounting/main.cpp +++ b/contrib/VehicleCounting/main.cpp @@ -72,7 +72,7 @@ int main() { configUtil.LoadConfiguration("$ENV{MX_SDK_HOME}/config/logging.conf", configData, MxBase::ConfigMode::CONFIGFILE); configData.SetFileValue("global_level", 1); MxBase::Log::SetLogParameters(configData); - std::string streamName = "./data/test1.264"; + std::string streamName = "./data/test.264"; // read config file and set params std::string m_sPath="./params.config"; std::map m_mapConfig;