From 30d62e97a173776e3bd89532f754c18f837eb3a1 Mon Sep 17 00:00:00 2001 From: lvhan028 Date: Wed, 29 Jun 2022 12:05:56 +0800 Subject: [PATCH] update the circleci config file by adding workflows both for linux, windows and linux-gpu (#368) * update circleci by adding more workflows * fix test workflow failure on windows platform * fix docker exec command for SDK unittests --- .circleci/config.yml | 65 ++-- .circleci/docker/Dockerfile | 41 +++ .circleci/scripts/linux/build.sh | 16 + .../scripts/linux/convert_onnxruntime.sh | 18 + .../scripts/linux/install_onnxruntime.sh | 30 ++ .circleci/scripts/linux/install_python.sh | 17 + .../scripts/windows/install_onnxruntime.ps1 | 19 ++ .circleci/scripts/windows/install_opencv.ps1 | 3 + .circleci/test.yml | 313 ++++++++++++++++++ requirements/codebases.txt | 7 + tests/test_csrc/capi/test_classifier.cpp | 2 +- tests/test_csrc/capi/test_detector.cpp | 2 +- tests/test_csrc/capi/test_model.cpp | 2 +- tests/test_csrc/capi/test_restorer.cpp | 2 +- tests/test_csrc/capi/test_segmentor.cpp | 2 +- tests/test_csrc/capi/test_text_detector.cpp | 2 +- tests/test_csrc/capi/test_text_recognizer.cpp | 4 +- .../test_csrc/model/test_directory_model.cpp | 2 +- tests/test_csrc/model/test_zip_model.cpp | 2 + tests/test_csrc/net/test_ncnn_net.cpp | 2 +- tests/test_csrc/net/test_openvino_net.cpp | 2 +- tests/test_csrc/net/test_ort_net.cpp | 2 +- tests/test_csrc/net/test_ppl_net.cpp | 2 +- tests/test_csrc/net/test_trt_net.cpp | 2 +- .../preprocess/test_default_format_bundle.cpp | 14 +- tests/test_csrc/preprocess/test_load.cpp | 2 +- tests/test_csrc/test_resource.h | 6 +- 27 files changed, 526 insertions(+), 55 deletions(-) create mode 100644 .circleci/docker/Dockerfile create mode 100644 .circleci/scripts/linux/build.sh create mode 100644 .circleci/scripts/linux/convert_onnxruntime.sh create mode 100644 .circleci/scripts/linux/install_onnxruntime.sh create mode 100644 .circleci/scripts/linux/install_python.sh create mode 100644 .circleci/scripts/windows/install_onnxruntime.ps1 create mode 100644 .circleci/scripts/windows/install_opencv.ps1 create mode 100644 .circleci/test.yml create mode 100644 requirements/codebases.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index cca73cd0e..a7405f052 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,36 +1,39 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. -# See: https://circleci.com/docs/2.0/configuration-reference version: 2.1 -# Define a job to be invoked later in a workflow. -# See: https://circleci.com/docs/2.0/configuration-reference/#jobs -jobs: - lint: - # Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub. - # See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor - docker: - - image: cimg/python:3.7.4 - # Add steps to the job - # See: https://circleci.com/docs/2.0/configuration-reference/#steps - steps: - - checkout - - run: - name: Install pre-commit hook - command: | - pip install pre-commit - pre-commit install - - run: - name: Linting - command: pre-commit run --all-files - - run: - name: Check docstring coverage - command: | - pip install interrogate - interrogate -v --ignore-init-method --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmdeploy +# this allows you to use CircleCI's dynamic configuration feature +setup: true + +# the path-filtering orb is required to continue a pipeline based on +# the path of an updated fileset +orbs: + path-filtering: circleci/path-filtering@0.1.2 -# Invoke jobs via workflows -# See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: - pr_stage_test: + # the always-run workflow is always triggered, regardless of the pipeline parameters. + always-run: jobs: - - lint + # the path-filtering/filter job determines which pipeline + # parameters to update. + - path-filtering/filter: + name: check-updated-files + # 3-column, whitespace-delimited mapping. One mapping per + # line: + # + mapping: | + .circle/.* lint_only false + cmake/.* lint_only false + configs/.* lint_only false + csrc/.* lint_only false + demo/csrc/.* lint_only false + docker/.* lint_only false + mmdeploy/.* lint_only false + requirements/.* lint_only false + tests/.* lint_only false + third_party/.* lint_only false + tools/.* lint_only false + base-revision: master + # this is the path of the configuration we should trigger once + # path filtering and pipeline parameter value updates are + # complete. In this case, we are using the parent dynamic + # configuration itself. + config-path: .circleci/test.yml diff --git a/.circleci/docker/Dockerfile b/.circleci/docker/Dockerfile new file mode 100644 index 000000000..488131435 --- /dev/null +++ b/.circleci/docker/Dockerfile @@ -0,0 +1,41 @@ +FROM nvcr.io/nvidia/tensorrt:21.04-py3 + +ARG CUDA=11.3 +ARG PYTHON_VERSION=3.8 +ARG TORCH_VERSION=1.10.0 +ARG TORCHVISION_VERSION=0.11.0 +ARG MMCV_VERSION=1.5.0 +ARG PPLCV_VERSION=0.6.2 +ENV FORCE_CUDA="1" + +ENV DEBIAN_FRONTEND=noninteractive + +### update apt and install libs +RUN apt-get update &&\ + apt-get install -y libopencv-dev --no-install-recommends &&\ + rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + chmod +x ~/miniconda.sh && \ + ~/miniconda.sh -b -p /opt/conda && \ + rm ~/miniconda.sh && \ + /opt/conda/bin/conda install -y python=${PYTHON_VERSION} && \ + /opt/conda/bin/conda clean -ya + +### pytorch +RUN /opt/conda/bin/conda install pytorch==${TORCH_VERSION} torchvision==${TORCHVISION_VERSION} cudatoolkit=${CUDA} -c pytorch -c conda-forge +ENV PATH /opt/conda/bin:$PATH + +### install mmcv-full +RUN /opt/conda/bin/pip install mmcv-full==${MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA//./}/torch${TORCH_VERSION}/index.html + +WORKDIR /workspace + +### build ppl.cv +RUN git clone https://github.com/openppl-public/ppl.cv.git &&\ + cd ppl.cv &&\ + git checkout tags/v${PPLCV_VERSION} -b v${PPLCV_VERSION} &&\ + ./build.sh cuda + +# RUN ln -sf /opt/conda /home/circleci/project/conda +ENV TENSORRT_DIR=/workspace/tensorrt diff --git a/.circleci/scripts/linux/build.sh b/.circleci/scripts/linux/build.sh new file mode 100644 index 000000000..0a6426dac --- /dev/null +++ b/.circleci/scripts/linux/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +ARGS=("$@") + +cd mmdeploy +MMDEPLOY_DIR=$(pwd) +mkdir -p build && cd build +cmake .. -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_TEST=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ + -DMMDEPLOY_BUILD_SDK_CXX_API=ON -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON \ + -DMMDEPLOY_TARGET_DEVICES="$1" -DMMDEPLOY_TARGET_BACKENDS="$2" "${ARGS[@]:2}" + +make -j$(nproc) && make install +cd install/example +mkdir -p build +cd build +cmake .. -DMMDeploy_DIR="$MMDEPLOY_DIR"/build/install/lib/cmake/MMDeploy "${ARGS[@]:2}" && make -j$(nproc) diff --git a/.circleci/scripts/linux/convert_onnxruntime.sh b/.circleci/scripts/linux/convert_onnxruntime.sh new file mode 100644 index 000000000..4ac57f453 --- /dev/null +++ b/.circleci/scripts/linux/convert_onnxruntime.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ $# != 2 ]; then + echo "wrong command. usage: bash converter.sh " + exit 1 +fi + +if [ "$1" == 'mmcls' ]; then + python3 -m pip install mmcls + git clone --recursive https://github.com/open-mmlab/mmclassification.git + wget https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth + python3 mmdeploy/tools/deploy.py \ + mmdeploy/configs/mmcls/classification_onnxruntime_dynamic.py \ + mmclassification/configs/resnet/resnet18_8xb32_in1k.py \ + resnet18_8xb32_in1k_20210831-fbbb1da6.pth \ + mmclassification/demo/demo.JPEG \ + --work-dir "$2" --dump-info +fi diff --git a/.circleci/scripts/linux/install_onnxruntime.sh b/.circleci/scripts/linux/install_onnxruntime.sh new file mode 100644 index 000000000..797673b6b --- /dev/null +++ b/.circleci/scripts/linux/install_onnxruntime.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ $# != 2 ]; then + echo "wrong command. usage: bash install_onnxruntime.sh " + exit 1 +fi + +PLATFORM=$1 +VERSION=$2 + +if [ "$PLATFORM" == 'cpu' ]; then + python -m pip install onnxruntime=="$VERSION" + + wget https://github.com/microsoft/onnxruntime/releases/download/v"$VERSION"/onnxruntime-linux-x64-"$VERSION".tgz + tar -zxvf onnxruntime-linux-x64-"$VERSION".tgz + ln -sf onnxruntime-linux-x64-"$VERSION" onnxruntime +elif [ "$PLATFORM" == 'cuda' ]; then + pip install onnxruntime-gpu=="$VERSION" + + wget https://github.com/microsoft/onnxruntime/releases/download/v"$VERSION"/onnxruntime-linux-x64-gpu-"$VERSION".tgz + tar -zxvf onnxruntime-linux-x64-gpu-"$VERSION".tgz + ln -sf onnxruntime-linux-x64-gpu-"$VERSION" onnxruntime +else + echo "'$PLATFORM' is not supported" + exit 1 +fi + +export ONNXRUNTIME_DIR=$(pwd)/onnxruntime +echo "export ONNXRUNTIME_DIR=${ONNXRUNTIME_DIR}" >> ~/.bashrc +echo "export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH" >> ~/.bashrc diff --git a/.circleci/scripts/linux/install_python.sh b/.circleci/scripts/linux/install_python.sh new file mode 100644 index 000000000..dda31121e --- /dev/null +++ b/.circleci/scripts/linux/install_python.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ $# -lt 1 ]; then + echo 'use python 3.8.5 as default' + PYTHON_VERSION=3.8.5 +else + PYTHON_VERSION=$1 +fi + +sudo apt-get update +# liblzma-dev need to be installed. Refer to https://github.com/pytorch/vision/issues/2921 +# python3-tk tk-dev is for 'import tkinter' +sudo apt-get install -y liblzma-dev python3-tk tk-dev +# python3+ need to be reinstalled due to https://github.com/pytorch/vision/issues/2921 +pyenv uninstall -f "$PYTHON_VERSION" +pyenv install "$PYTHON_VERSION" +pyenv global "$PYTHON_VERSION" diff --git a/.circleci/scripts/windows/install_onnxruntime.ps1 b/.circleci/scripts/windows/install_onnxruntime.ps1 new file mode 100644 index 000000000..f9ded89c5 --- /dev/null +++ b/.circleci/scripts/windows/install_onnxruntime.ps1 @@ -0,0 +1,19 @@ +if ($args.Count -lt 2) { + Write-Host "wrong command. usage: intall_onnxruntime.ps1 " + Exit 1 +} + +$platform = $args[0] +$version = $args[1] + +if ($platform -eq "cpu") { + python -m pip install onnxruntime==$version + Invoke-WebRequest -Uri https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x64-$version.zip -OutFile onnxruntime.zip + Expand-Archive onnxruntime.zip . + Move-Item onnxruntime-win-x64-$version onnxruntime +} elseif ($platform == "cuda") { + Write-Host "TODO: install onnxruntime-gpu" + Exit +} else { + Write-Host "'$platform' is not supported" +} diff --git a/.circleci/scripts/windows/install_opencv.ps1 b/.circleci/scripts/windows/install_opencv.ps1 new file mode 100644 index 000000000..2e5cae5f7 --- /dev/null +++ b/.circleci/scripts/windows/install_opencv.ps1 @@ -0,0 +1,3 @@ +Invoke-WebRequest -Uri https://download.openmmlab.com/mmdeploy/library/opencv-4.5.5.zip -OutFile opencv.zip +Expand-Archive opencv.zip . +Move-Item opencv-4.5.5 opencv diff --git a/.circleci/test.yml b/.circleci/test.yml new file mode 100644 index 000000000..4e4161410 --- /dev/null +++ b/.circleci/test.yml @@ -0,0 +1,313 @@ +# Use the latest 2.1 version of CircleCI pipeline process engine. +# See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 + +orbs: + win: circleci/windows@4.1 + +# the default pipeline parameters, which will be updated according to +# the results of the path-filtering orb +parameters: + lint_only: + type: boolean + default: true + +executors: + ubuntu-2004-cpu: + machine: + image: ubuntu-2004:202010-01 + resource_class: large + working_directory: ~ + ubuntu-2004-cu114: + machine: + image: ubuntu-2004-cuda-11.4:202110-01 + docker_layer_caching: true + resource_class: gpu.nvidia.medium + working_directory: ~ + +# MMDeploy Rules +# - In the command section, each command is requested to be os platform independent. Any command related to OS platform should be put in `scripts` folder +# - Use `python` instead of `python3` since there is no `python3` on Windows platform +# - DO NOT use `\` to break the line, as it is not identified correctly on Windows platform. So just don't break the line :) +commands: + checkout_full: + description: "Checkout mmdeploy" + steps: + - checkout: + path: mmdeploy # relative to `working_directory` + - run: + name: Checkout submodule + command: | + cd mmdeploy + git submodule sync + git submodule update --init + upgrade_pip: + steps: + - run: + name: Upgrade pip + command: python -m pip install --upgrade pip + install_pytorch: + parameters: + platform: + type: string + default: cpu + torch: + type: string + default: 1.8.0 + torchvision: + type: string + default: 0.9.0 + steps: + - run: + name: Install PyTorch + command: | + python -m pip install torch==<< parameters.torch >>+<< parameters.platform >> torchvision==<< parameters.torchvision >>+<< parameters.platform >> -f https://download.pytorch.org/whl/torch_stable.html + install_mmcv_cpu: + parameters: + version: + type: string + default: 1.5.0 + torch: + type: string + default: 1.8.0 + steps: + - run: + name: Install mmcv-full + command: | + python -m pip install opencv-python==4.5.4.60 + python -m pip install mmcv-full==<< parameters.version >> -f https://download.openmmlab.com/mmcv/dist/cpu/torch<< parameters.torch >>/index.html + install_mmcv_cuda: + parameters: + version: + type: string + default: 1.5.0 + cuda: + type: string + default: cu111 + torch: + type: string + default: 1.8.0 + steps: + - run: + name: Install mmcv-full + command: | + python -m pip install opencv-python==4.5.4.60 + python -m pip install mmcv-full==<< parameters.version >> -f https://download.openmmlab.com/mmcv/dist/<< parameters.cuda >>/torch<< parameters.torch >>/index.html + install_mmdeploy: + description: "Install MMDeploy" + steps: + - run: + name: Install MMDeploy + command: | + cd mmdeploy + python -m pip install -v -e . + install_model_converter_req: + steps: + - run: + name: Install requirements + command: | + cd mmdeploy + python -m pip install -r requirements/codebases.txt + python -m pip install -r requirements/tests.txt + python -m pip install -r requirements/runtime.txt + python -m pip install -U numpy + cd .. + perform_model_converter_ut: + steps: + - run: + name: Perform Model Converter unittests + command: | + cd mmdeploy + coverage run --branch --source mmdeploy -m pytest -rsE tests + coverage xml + coverage report -m + cd .. +jobs: + lint: + # Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub. + # See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor + docker: + - image: cimg/python:3.7.4 + # Add steps to the job + # See: https://circleci.com/docs/2.0/configuration-reference/#steps + steps: + - checkout + - run: + name: Install pre-commit hook + command: | + pip install pre-commit + pre-commit install + - run: + name: Linting + command: pre-commit run --all-files + - run: + name: Check docstring coverage + command: | + pip install interrogate + interrogate -v --ignore-init-method --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmdeploy + + test_linux_tensorrt: + executor: ubuntu-2004-cu114 + steps: + - checkout_full + - run: + name: Build docker + command: | + docker build mmdeploy/.circleci/docker/ -t mmdeploy:gpu + - run: + name: Build MMDeploy + command: | + docker run --gpus all -t -d -v /home/circleci/project/:/project -w /project --name mmdeploy mmdeploy:gpu + docker exec mmdeploy bash mmdeploy/.circleci/scripts/linux/build.sh cuda trt -Dpplcv_DIR=/workspace/ppl.cv/cuda-build/install/lib/cmake/ppl + - run: + name: Install MMDeploy + # https://stackoverflow.com/questions/28037802/docker-exec-failed-cd-executable-file-not-found-in-path + command: | + docker exec -i mmdeploy bash -c "cd mmdeploy && pip install -v -e ." + - run: + name: Install requirements + command: | + docker exec mmdeploy pip install onnxruntime==1.8.1 + docker exec mmdeploy pip install -r mmdeploy/requirements/codebases.txt + docker exec mmdeploy pip install -r mmdeploy/requirements/tests.txt + docker exec mmdeploy pip install -r mmdeploy/requirements/runtime.txt + docker exec mmdeploy pip install -U numpy + - run: + name: Perform Model Converter unittests + command: | + docker exec -i mmdeploy bash -c "cd mmdeploy && coverage run --branch --source mmdeploy -m pytest -rsE tests && coverage xml && coverage report -m" + - run: + name: Run SDK unittests + command: | + docker exec mmdeploy mkdir -p mmdeploy_test_resources/transform + docker exec mmdeploy cp mmdeploy/demo/resources/human-pose.jpg mmdeploy_test_resources/transform + docker exec mmdeploy ./mmdeploy/build/bin/mmdeploy_tests + + test_windows_onnxruntime: + parameters: + version: + type: string + default: 1.8.1 + executor: + name: win/default + steps: + - checkout_full + - upgrade_pip + - install_pytorch + - install_mmcv_cpu + - run: + name: Install ONNX Runtime + command: mmdeploy/.circleci/scripts/windows/install_onnxruntime.ps1 cpu << parameters.version >> + - run: + name: Install OpenCV + command: mmdeploy/.circleci/scripts/windows/install_opencv.ps1 + - run: + name: Build MMDeploy + command: | + $env:path = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;" + $env:path + $env:ONNXRUNTIME_DIR = "$pwd\onnxruntime" + $env:OPENCV_PACKAGE_DIR = "$(pwd)\opencv" + $env:MMDEPLOY_DIR = "$(pwd)\mmdeploy" + cd mmdeploy + mkdir build -ErrorAction SilentlyContinue + cd build + cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` + -DCMAKE_SYSTEM_VERSION="10.0.18362.0" ` + -DMMDEPLOY_BUILD_SDK=ON ` + -DMMDEPLOY_BUILD_TEST=ON ` + -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON ` + -DMMDEPLOY_BUILD_SDK_CXX_API=ON ` + -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON ` + -DMMDEPLOY_TARGET_BACKENDS="ort" ` + -DOpenCV_DIR="$env:OPENCV_PACKAGE_DIR" + cmake --build . --config Release -- /m + cmake --install . --config Release + cd install/example + mkdir build -ErrorAction SilentlyContinue + cd build + cmake .. -G "Visual Studio 16 2019" -A x64 -T v142 ` + -DMMDeploy_DIR="$env:MMDEPLOY_DIR/build/install/lib/cmake/MMDeploy" ` + -DOpenCV_DIR="$env:OPENCV_PACKAGE_DIR" + cmake --build . --config Release -- /m + - install_mmdeploy + - install_model_converter_req + - perform_model_converter_ut + - run: + name: Perform SDK Unittests + command: | + $env:path = "$(pwd)\onnxruntime\lib;" + $env:path + $env:path = "$(pwd)\opencv\x64\vc16\bin;" + $env:path + mkdir mmdeploy_test_resources\transform + cp .\mmdeploy\demo\resources\human-pose.jpg mmdeploy_test_resources\transform + .\mmdeploy\build\bin\Release\mmdeploy_tests.exe + + test_linux_onnxruntime: + parameters: + version: + type: string + default: 1.8.1 + executor: ubuntu-2004-cpu + steps: + - checkout_full + - run: + name: Re-install Python + command: bash mmdeploy/.circleci/scripts/linux/install_python.sh + - upgrade_pip + - install_pytorch + - install_mmcv_cpu + - run: + name: Install ONNX Runtime + command: bash mmdeploy/.circleci/scripts/linux/install_onnxruntime.sh cpu << parameters.version >> + - run: + name: Build MMDeploy + command: | + sudo apt-get update + sudo apt-get install libopencv-dev libpython3.8 python3.8-dev + bash mmdeploy/.circleci/scripts/linux/build.sh cpu ort + - install_mmdeploy + - install_model_converter_req + - perform_model_converter_ut + - run: + name: Perform SDK unittests + command: | + mkdir -p mmdeploy_test_resources/transform + cp -rf ./mmdeploy/demo/resources/human-pose.jpg mmdeploy_test_resources/transform + ./mmdeploy/build/bin/mmdeploy_tests + - run: + name: Convert model + command: | + bash mmdeploy/.circleci/scripts/linux/convert_onnxruntime.sh mmcls mmdeploy-models/mmcls/onnxruntime + - run: + name: Inference model by SDK + command: | + mmdeploy/build/install/example/build/image_classification cpu mmdeploy-models/mmcls/onnxruntime mmclassification/demo/demo.JPEG + + +# See: https://circleci.com/docs/2.0/configuration-reference/#workflows +workflows: + pr_stage_lint: + when: << pipeline.parameters.lint_only >> + jobs: + - lint + pr_stage_test: + when: + not: + << pipeline.parameters.lint_only >> + jobs: + - lint + - test_linux_onnxruntime: + version: 1.8.1 + requires: + - lint + - test_windows_onnxruntime: + version: 1.8.1 + requires: + - lint + - hold: + type: approval + requires: + - test_linux_onnxruntime + - test_windows_onnxruntime + - test_linux_tensorrt: + requires: + - hold diff --git a/requirements/codebases.txt b/requirements/codebases.txt new file mode 100644 index 000000000..a0dfdace6 --- /dev/null +++ b/requirements/codebases.txt @@ -0,0 +1,7 @@ +mmcls>=0.21.0,<=0.22.1 +mmdet>=2.19.0,<=2.20.0 +mmedit +mmocr>=0.3.0,<=0.4.1 +mmpose>=0.24.0,<=0.25.1 +mmrazor>=0.3.0 +mmsegmentation diff --git a/tests/test_csrc/capi/test_classifier.cpp b/tests/test_csrc/capi/test_classifier.cpp index a490bd224..e1d9e748a 100644 --- a/tests/test_csrc/capi/test_classifier.cpp +++ b/tests/test_csrc/capi/test_classifier.cpp @@ -11,7 +11,7 @@ using namespace std; -TEST_CASE("test classifier's c api", "[classifier]") { +TEST_CASE("test classifier's c api", "[.classifier][resource]") { auto test = [](const std::string& device_name, const std::string& model_path, const std::vector& img_list) { mm_handle_t handle{nullptr}; diff --git a/tests/test_csrc/capi/test_detector.cpp b/tests/test_csrc/capi/test_detector.cpp index ae3b8aa46..b451d9881 100644 --- a/tests/test_csrc/capi/test_detector.cpp +++ b/tests/test_csrc/capi/test_detector.cpp @@ -11,7 +11,7 @@ #include "test_resource.h" using namespace std; -TEST_CASE("test detector's c api", "[detector]") { +TEST_CASE("test detector's c api", "[.detector][resource]") { MMDEPLOY_INFO("test detector"); auto test = [](const string &device, const string &model_path, const vector &img_list) { mm_handle_t handle{nullptr}; diff --git a/tests/test_csrc/capi/test_model.cpp b/tests/test_csrc/capi/test_model.cpp index 34d952580..d8c731c7a 100644 --- a/tests/test_csrc/capi/test_model.cpp +++ b/tests/test_csrc/capi/test_model.cpp @@ -7,7 +7,7 @@ #include "mmdeploy/apis/c/model.h" #include "test_resource.h" -TEST_CASE("test model c capi", "[model]") { +TEST_CASE("test model c capi", "[.model][resource]") { auto &gResource = MMDeployTestResources::Get(); std::string model_path; for (auto const &codebase : gResource.codebases()) { diff --git a/tests/test_csrc/capi/test_restorer.cpp b/tests/test_csrc/capi/test_restorer.cpp index 04670c1c6..7cac1f2b3 100644 --- a/tests/test_csrc/capi/test_restorer.cpp +++ b/tests/test_csrc/capi/test_restorer.cpp @@ -10,7 +10,7 @@ using namespace std; -TEST_CASE("test restorer's c api", "[restorer]") { +TEST_CASE("test restorer's c api", "[.restorer][resource]") { auto test = [](const string &device, const string &backend, const string &model_path, const vector &img_list) { mm_handle_t handle{nullptr}; diff --git a/tests/test_csrc/capi/test_segmentor.cpp b/tests/test_csrc/capi/test_segmentor.cpp index cfaaf4a4f..4e52a483e 100644 --- a/tests/test_csrc/capi/test_segmentor.cpp +++ b/tests/test_csrc/capi/test_segmentor.cpp @@ -10,7 +10,7 @@ using namespace std; -TEST_CASE("test segmentor's c api", "[segmentor]") { +TEST_CASE("test segmentor's c api", "[.segmentor][resource]") { auto test = [](const string &device, const string &backend, const string &model_path, const vector &img_list) { mm_handle_t handle{nullptr}; diff --git a/tests/test_csrc/capi/test_text_detector.cpp b/tests/test_csrc/capi/test_text_detector.cpp index a53995432..b2240e8b6 100644 --- a/tests/test_csrc/capi/test_text_detector.cpp +++ b/tests/test_csrc/capi/test_text_detector.cpp @@ -10,7 +10,7 @@ using namespace std; -TEST_CASE("test text detector's c api", "[text-detector]") { +TEST_CASE("test text detector's c api", "[.text-detector][resource]") { auto test = [](const string& device, const string& model_path, const vector& img_list) { mm_handle_t handle{nullptr}; auto ret = diff --git a/tests/test_csrc/capi/test_text_recognizer.cpp b/tests/test_csrc/capi/test_text_recognizer.cpp index 98d07189e..96272d889 100644 --- a/tests/test_csrc/capi/test_text_recognizer.cpp +++ b/tests/test_csrc/capi/test_text_recognizer.cpp @@ -12,7 +12,7 @@ using namespace std; -TEST_CASE("test text recognizer's c api", "[text-recognizer]") { +TEST_CASE("test text recognizer's c api", "[.text-recognizer][resource]") { auto test = [](const string& device, const string& model_path, const vector& img_list) { mm_handle_t handle{nullptr}; auto ret = @@ -59,7 +59,7 @@ TEST_CASE("test text recognizer's c api", "[text-recognizer]") { } } -TEST_CASE("test text detector-recognizer combo", "[text-detector-recognizer]") { +TEST_CASE("test text detector-recognizer combo", "[.text-detector-recognizer]") { auto test = [](const std::string& device, const string& det_model_path, const string& reg_model_path, std::vector& img_list) { mm_handle_t detector{}; diff --git a/tests/test_csrc/model/test_directory_model.cpp b/tests/test_csrc/model/test_directory_model.cpp index aa96836a3..6bb8ea357 100644 --- a/tests/test_csrc/model/test_directory_model.cpp +++ b/tests/test_csrc/model/test_directory_model.cpp @@ -9,7 +9,7 @@ using namespace mmdeploy; -TEST_CASE("test directory model", "[model]") { +TEST_CASE("test directory model", "[.model][resource]") { std::unique_ptr model_impl; for (auto& entry : ModelRegistry::Get().ListEntries()) { if (entry.name == "DirectoryModel") { diff --git a/tests/test_csrc/model/test_zip_model.cpp b/tests/test_csrc/model/test_zip_model.cpp index b92e50c30..03d8fd4d2 100644 --- a/tests/test_csrc/model/test_zip_model.cpp +++ b/tests/test_csrc/model/test_zip_model.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace mmdeploy; +#if MMDEPLOY_ZIP_MODEL TEST_CASE("test zip model", "[zip_model]") { std::unique_ptr model_impl; for (auto& entry : ModelRegistry::Get().ListEntries()) { @@ -50,3 +51,4 @@ TEST_CASE("test zip model", "[zip_model]") { REQUIRE(!model_impl->Init(buffer.data(), buffer.size()).has_error()); } } +#endif diff --git a/tests/test_csrc/net/test_ncnn_net.cpp b/tests/test_csrc/net/test_ncnn_net.cpp index ea04b43cd..ab09e2f0a 100644 --- a/tests/test_csrc/net/test_ncnn_net.cpp +++ b/tests/test_csrc/net/test_ncnn_net.cpp @@ -10,7 +10,7 @@ using namespace mmdeploy; -TEST_CASE("test ncnn net", "[ncnn_net]") { +TEST_CASE("test ncnn net", "[.ncnn_net][resource]") { auto& gResource = MMDeployTestResources::Get(); auto model_list = gResource.LocateModelResources(fs::path{"mmcls"} / "ncnn"); REQUIRE(!model_list.empty()); diff --git a/tests/test_csrc/net/test_openvino_net.cpp b/tests/test_csrc/net/test_openvino_net.cpp index df5c1be03..e965c59be 100644 --- a/tests/test_csrc/net/test_openvino_net.cpp +++ b/tests/test_csrc/net/test_openvino_net.cpp @@ -10,7 +10,7 @@ using namespace mmdeploy; -TEST_CASE("test openvino net", "[openvino_net]") { +TEST_CASE("test openvino net", "[.openvino_net][resource]") { auto& gResource = MMDeployTestResources::Get(); auto model_list = gResource.LocateModelResources(fs::path{"mmcls"} / "openvino"); REQUIRE(!model_list.empty()); diff --git a/tests/test_csrc/net/test_ort_net.cpp b/tests/test_csrc/net/test_ort_net.cpp index 801ecf9e5..f2f863503 100644 --- a/tests/test_csrc/net/test_ort_net.cpp +++ b/tests/test_csrc/net/test_ort_net.cpp @@ -10,7 +10,7 @@ using namespace mmdeploy; -TEST_CASE("test ort net", "[ort_net]") { +TEST_CASE("test ort net", "[.ort_net][resource]") { auto& gResource = MMDeployTestResources::Get(); auto model_list = gResource.LocateModelResources(fs::path{"mmcls"} / "ort"); REQUIRE(!model_list.empty()); diff --git a/tests/test_csrc/net/test_ppl_net.cpp b/tests/test_csrc/net/test_ppl_net.cpp index aa855bf00..6f2b45501 100644 --- a/tests/test_csrc/net/test_ppl_net.cpp +++ b/tests/test_csrc/net/test_ppl_net.cpp @@ -10,7 +10,7 @@ using namespace mmdeploy; -TEST_CASE("test pplnn net", "[ppl_net]") { +TEST_CASE("test pplnn net", "[.ppl_net][resource]") { auto& gResource = MMDeployTestResources::Get(); auto model_list = gResource.LocateModelResources(fs::path{"mmcls"} / "pplnn"); REQUIRE(!model_list.empty()); diff --git a/tests/test_csrc/net/test_trt_net.cpp b/tests/test_csrc/net/test_trt_net.cpp index b6ab080ee..e567c63fc 100644 --- a/tests/test_csrc/net/test_trt_net.cpp +++ b/tests/test_csrc/net/test_trt_net.cpp @@ -10,7 +10,7 @@ using namespace mmdeploy; -TEST_CASE("test trt net", "[trt_net]") { +TEST_CASE("test trt net", "[.trt_net][resource]") { auto& gResource = MMDeployTestResources::Get(); auto model_list = gResource.LocateModelResources(fs::path{"mmcls"} / "trt"); REQUIRE(!model_list.empty()); diff --git a/tests/test_csrc/preprocess/test_default_format_bundle.cpp b/tests/test_csrc/preprocess/test_default_format_bundle.cpp index 489e8a249..b8f744a21 100644 --- a/tests/test_csrc/preprocess/test_default_format_bundle.cpp +++ b/tests/test_csrc/preprocess/test_default_format_bundle.cpp @@ -37,17 +37,18 @@ void TestDefaultFormatBundle(const Value& cfg, const cv::Mat& mat) { // mat's shape is {h, w, c}, while res_tensor's shape is {1, c, h, w} // compare each channel between `res_tensor` and `mat` - auto step = shape[2] * shape[3] * mat.elemSize1(); + // note `data_type` of `res_tensor` is `float` + auto step = shape[2] * shape[3] * sizeof(float); auto data = host_tensor.value().data(); for (auto i = 0; i < mat.channels(); ++i) { - cv::Mat _mat{mat.rows, mat.cols, CV_MAKETYPE(mat.depth(), 1), data}; + cv::Mat _mat{mat.rows, mat.cols, CV_32FC1, data}; REQUIRE(::mmdeploy::cpu::Compare(channel_mats[i], _mat)); data += step; } } } -TEST_CASE("transform DefaultFormatBundle", "[img2tensor]") { +TEST_CASE("transform DefaultFormatBundle", "[bundle]") { auto gResource = MMDeployTestResources::Get(); auto img_list = gResource.LocateImageResources("transform"); REQUIRE(!img_list.empty()); @@ -55,13 +56,10 @@ TEST_CASE("transform DefaultFormatBundle", "[img2tensor]") { auto img_path = img_list.front(); cv::Mat bgr_mat = cv::imread(img_path, cv::IMREAD_COLOR); cv::Mat gray_mat = cv::imread(img_path, cv::IMREAD_GRAYSCALE); - cv::Mat bgr_float_mat; - cv::Mat gray_float_mat; - bgr_mat.convertTo(bgr_float_mat, CV_32FC3); - gray_mat.convertTo(gray_float_mat, CV_32FC1); + Value cfg{{"type", "DefaultFormatBundle"}, {"keys", {"img"}}}; - vector mats{bgr_mat, gray_mat, bgr_float_mat, gray_float_mat}; + vector mats{bgr_mat, gray_mat}; for (auto& mat : mats) { TestDefaultFormatBundle(cfg, mat); } diff --git a/tests/test_csrc/preprocess/test_load.cpp b/tests/test_csrc/preprocess/test_load.cpp index fc825155c..bbb811aed 100644 --- a/tests/test_csrc/preprocess/test_load.cpp +++ b/tests/test_csrc/preprocess/test_load.cpp @@ -46,7 +46,7 @@ void TestLoad(const Value& cfg, const cv::Mat& mat, PixelFormat src_format, } } -TEST_CASE("prepare image, that is LoadImageFromFile transform", "[load]") { +TEST_CASE("prepare image, that is LoadImageFromFile transform", "[.load]") { auto gResource = MMDeployTestResources::Get(); auto img_list = gResource.LocateImageResources("transform"); REQUIRE(!img_list.empty()); diff --git a/tests/test_csrc/test_resource.h b/tests/test_csrc/test_resource.h index f6a3fb826..8d88cce3e 100644 --- a/tests/test_csrc/test_resource.h +++ b/tests/test_csrc/test_resource.h @@ -129,7 +129,11 @@ class MMDeployTestResources { } // Didn't find 'mmdeploy_test_resources' in current directory. // Move to its parent directory and keep looking for it - return LocateResourceRootPath(cur_path.parent_path(), max_depth - 1); + if (cur_path.has_parent_path()) { + return LocateResourceRootPath(cur_path.parent_path(), max_depth - 1); + } else { + return ""; + } } private: