Skip to content

Commit

Permalink
Fix Windows (openvinotoolkit#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wovchena authored Mar 21, 2023
1 parent 4dbb282 commit c7157d9
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 63 deletions.
59 changes: 51 additions & 8 deletions .github/workflows/test_precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -50,9 +49,8 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -89,9 +87,8 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
Expand All @@ -117,7 +114,53 @@ jobs:
run: |
mkdir build && cd build
cmake ../tests/cpp/precommit/
make -j
cmake --build . -j $((`nproc`*2+2))
- name: Run test
run: |
build/test_sanity -d data -p tests/cpp/precommit/public_scope.json
CPP-Windows-Precommit:
strategy:
fail-fast: false
matrix:
python-version: [3.8]

runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Create and start a virtual environment
shell: bash
run: |
python -m venv venv
source venv/Scripts/activate
- name: Install dependencies
shell: bash
run: |
source venv/Scripts/activate
python -m pip install --upgrade pip
pip install model_api/python/[tests]
curl https://storage.openvinotoolkit.org/repositories/openvino/packages/2022.3/windows/w_openvino_toolkit_windows_2022.3.0.9052.9752fafe8eb_x86_64.zip --output w_openvino_toolkit_windows.zip
unzip w_openvino_toolkit_windows.zip
rm w_openvino_toolkit_windows.zip
curl -L https://github.com/opencv/opencv/releases/download/4.7.0/opencv-4.7.0-windows.exe --output opencv-4.7.0-windows.exe
./opencv-4.7.0-windows.exe -oopencv -y
- name: Prepare test data
shell: bash
run: |
source venv/Scripts/activate
python tests/cpp/precommit/prepare_data.py -d data -p tests/cpp/precommit/public_scope.json
- name: Build
shell: bash
run: |
mkdir build && cd build
cmake ../tests/cpp/precommit/ -DOpenVINO_DIR=$GITHUB_WORKSPACE/w_openvino_toolkit_windows_2022.3.0.9052.9752fafe8eb_x86_64/runtime/cmake -DOpenCV_DIR=$GITHUB_WORKSPACE/opencv/opencv/build
cmake --build . --config Release -j $((`nproc`*2+2))
- name: Run test
shell: cmd
# .\w_openvino_toolkit_windows_2022.3.0.9052.9752fafe8eb_x86_64\setupvars.bat exits with 0 code without moving to a next command. Set PATH manually
run: |
build/test_sanity -d data -p tests/cpp/precommit/public_scope.json
set PATH=opencv\opencv\build\x64\vc16\bin;w_openvino_toolkit_windows_2022.3.0.9052.9752fafe8eb_x86_64\runtime\bin\intel64\Release;w_openvino_toolkit_windows_2022.3.0.9052.9752fafe8eb_x86_64\runtime\3rdparty\tbb\bin;%PATH%
.\build\Release\test_sanity.exe -d data -p tests\cpp\precommit\public_scope.json
5 changes: 1 addition & 4 deletions model_api/cpp/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ echo "deb https://apt.repos.intel.com/openvino/2022 focal main" | sudo tee /etc/
apt update

#Install OpenCV
apt-get install libopencv-dev
apt-get install libopencv-dev

# Install OpenVINO
apt install openvino

# Install GTest for CPP tests
apt-get install libgtest-dev
2 changes: 1 addition & 1 deletion model_api/cpp/models/include/models/results.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct ClassificationResult : public ResultBase {
};

struct DetectedObject : public cv::Rect2f {
unsigned int labelID;
size_t labelID;
std::string label;
float confidence;

Expand Down
12 changes: 6 additions & 6 deletions model_api/cpp/models/src/detection_model_ssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct InputData;
std::shared_ptr<InternalModelData> ModelSSD::preprocess(const InputData& inputData, InferenceInput& input) {
if (inputNames.size() > 1) {
cv::Mat info(cv::Size(1, 3), CV_32SC1);
info.at<int>(0, 0) = static_cast<float>(netInputHeight);
info.at<int>(0, 1) = static_cast<float>(netInputWidth);
info.at<int>(0, 0) = netInputHeight;
info.at<int>(0, 1) = netInputWidth;
info.at<int>(0, 2) = 1;
auto allocator = std::make_shared<SharedTensorAllocator>(info);
ov::Tensor infoInput = ov::Tensor(ov::element::i32, ov::Shape({1, 3}), ov::Allocator(allocator));
Expand All @@ -60,16 +60,16 @@ std::unique_ptr<ResultBase> ModelSSD::postprocessSingleOutput(InferenceResult& i
auto retVal = std::unique_ptr<ResultBase>(result);

const auto& internalData = infResult.internalModelData->asRef<InternalImageModelData>();
float floatInputImgWidth = internalData.inputImgWidth,
floatInputImgHeight = internalData.inputImgHeight;
float floatInputImgWidth = float(internalData.inputImgWidth),
floatInputImgHeight = float(internalData.inputImgHeight);
float invertedScaleX = floatInputImgWidth / netInputWidth,
invertedScaleY = floatInputImgHeight / netInputHeight;
int padLeft = 0, padTop = 0;
if (RESIZE_KEEP_ASPECT == resizeMode || RESIZE_KEEP_ASPECT_LETTERBOX == resizeMode) {
invertedScaleX = invertedScaleY = std::max(invertedScaleX, invertedScaleY);
if (RESIZE_KEEP_ASPECT_LETTERBOX == resizeMode) {
padLeft = (netInputWidth - floatInputImgWidth / invertedScaleX) / 2;
padTop = (netInputHeight - floatInputImgHeight / invertedScaleY) / 2;
padLeft = (netInputWidth - int(floatInputImgWidth / invertedScaleX)) / 2;
padTop = (netInputHeight - int(floatInputImgHeight / invertedScaleY)) / 2;
}
}

Expand Down
2 changes: 1 addition & 1 deletion model_api/cpp/models/src/detection_model_yolov3_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ std::unique_ptr<ResultBase> ModelYoloV3ONNX::postprocess(InferenceResult& infRes
// Generate detection results
DetectionResult* result = new DetectionResult(infResult.frameId, infResult.metaData);
size_t numberOfBoxes = indicesShape.size() == 3 ? indicesShape[1] : indicesShape[0];
int indicesStride = indicesShape.size() == 3 ? indicesShape[2] : indicesShape[1];
size_t indicesStride = indicesShape.size() == 3 ? indicesShape[2] : indicesShape[1];

for (size_t i = 0; i < numberOfBoxes; ++i) {
int batchInd = indicesData[i * indicesStride];
Expand Down
21 changes: 0 additions & 21 deletions model_api/cpp/utils/include/utils/default_flags.hpp

This file was deleted.

14 changes: 1 addition & 13 deletions model_api/cpp/utils/src/args_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,9 @@
//

#include "utils/args_helper.hpp"
#include "utils/slog.hpp"

#ifdef _WIN32
#include "w_dirent.hpp"
#else
#include <dirent.h>
#endif

#include <gflags/gflags.h>

#include <sys/stat.h>
#include <map>

#include <algorithm>
#include <cctype>
#include <map>
#include <sstream>

std::vector<std::string> split(const std::string& s, char delim) {
Expand Down
7 changes: 3 additions & 4 deletions tests/cpp/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ macro(add_test)
target_include_directories(${TEST_NAME} PRIVATE ${TEST_INCLUDE_DIRECTORIES})
endif()

target_link_libraries(${TEST_NAME} PRIVATE ${OpenCV_LIBRARIES} openvino::runtime
${TEST_DEPENDENCIES} gflags)
target_link_libraries(${TEST_NAME} PRIVATE ${OpenCV_LIBRARIES} openvino::runtime ${TEST_DEPENDENCIES})

if(UNIX)
target_link_libraries(${TEST_NAME} PRIVATE pthread)
endif()

target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main pthread)
target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main)
target_link_libraries(${TEST_NAME} PRIVATE nlohmann_json::nlohmann_json)

endmacro()
endmacro()
14 changes: 11 additions & 3 deletions tests/cpp/precommit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,27 @@ endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Something: OpenCV or OpenVINO links gflags with /MT instead of default flag.
# Set the same to avoid linkage conflicts
if(WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
endif()

include(CMakeParseArguments)
include(FetchContent)

FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_MakeAvailable(json)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 471087fbfcbc3c66071189a67c313eb1d525ee51 # latest main
)
FetchContent_MakeAvailable(json googletest)

include(../cmake/common.cmake)

find_package(OpenCV REQUIRED COMPONENTS core highgui videoio imgproc imgcodecs)
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
find_package(GTest REQUIRED)

add_subdirectory(../../../model_api/cpp ${tests_BINARY_DIR}/model_api/cpp)

add_test(NAME test_sanity SOURCES test_sanity.cpp DEPENDENCIES model_api)
add_test(NAME test_sanity SOURCES test_sanity.cpp DEPENDENCIES model_api)
2 changes: 0 additions & 2 deletions tests/python/accuracy/prepare_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import argparse
import json
from pathlib import Path


def prepare_data(data_dir="./data"):
Expand Down

0 comments on commit c7157d9

Please sign in to comment.