Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Windows Compatibility (#39) #43

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
1 change: 0 additions & 1 deletion build/lite.ai.toolkit/lib/liblite.ai.toolkit.dylib

This file was deleted.

47 changes: 8 additions & 39 deletions cmake/lite.ai.toolkit-cmd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function(add_lite_ai_toolkit_shared_library version soversion)
if (ENABLE_MNN)
include(cmake/lite.ai.toolkit-mnn.cmake)
set(LITE_SRCS ${LITE_SRCS} ${MNN_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} mnn)
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} MNN)
endif()

if (ENABLE_NCNN)
Expand All @@ -33,7 +33,7 @@ function(add_lite_ai_toolkit_shared_library version soversion)
if (ENABLE_TNN)
include(cmake/lite.ai.toolkit-tnn.cmake)
set(LITE_SRCS ${LITE_SRCS} ${TNN_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} tnn)
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} TNN)
endif()

# 4. shared library
Expand All @@ -51,7 +51,7 @@ function(add_lite_ai_toolkit_shared_library version soversion)
endfunction()

# add custom command for lite.ai shared lib.
function(add_lite_ai_toolkit_custom_command)
function(add_lite_ai_toolkit_pre_custom_command)
if (LITE_AI_BUILD_TEST)
add_custom_command(TARGET lite.ai.toolkit
PRE_BUILD
Expand All @@ -60,6 +60,11 @@ function(add_lite_ai_toolkit_custom_command)
COMMAND ${CMAKE_COMMAND} -E echo "create ${LIBRARY_OUTPUT_PATH} done!"
COMMAND ${CMAKE_COMMAND} -E echo "create ${EXECUTABLE_OUTPUT_PATH} done!"
)
endif()
endfunction()

function(add_lite_ai_toolkit_post_custom_command)
if (LITE_AI_BUILD_TEST)
# copy opencv & lite.ai libs.
add_custom_command(TARGET lite.ai.toolkit
POST_BUILD
Expand Down Expand Up @@ -111,39 +116,3 @@ function(add_lite_executable executable_name field)
target_link_libraries(${executable_name} lite.ai.toolkit) # link lite.ai.toolkit
message(">>>> Added Lite Executable: ${executable_name} !")
endfunction ()

function(add_ort_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/cmake/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai.toolkit) # link lite.ai.toolkit
message(">>>> Added Ort Executable: ${executable_name} !")
endfunction ()

function(add_mnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/cmake/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai.toolkit) # link lite.ai.toolkit
message(">>>> Added MNN Executable: ${executable_name} !")
endfunction ()

function(add_ncnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/cmake/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai.toolkit) # link lite.ai.toolkit
message(">>>> Added NCNN Executable: ${executable_name} !")
endfunction ()

function(add_tnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/cmake/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai.toolkit) # link lite.ai.toolkit
message(">>>> Added TNN Executable: ${executable_name} !")
endfunction ()
5 changes: 4 additions & 1 deletion cmake/lite.ai.toolkit.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
add_lite_ai_toolkit_shared_library(${VERSION_STRING} ${SOVERSION_STRING})
add_lite_ai_toolkit_custom_command()
add_lite_ai_toolkit_pre_custom_command()
if(${PLATFORM_NAME} MATCHES macos OR ${PLATFORM_NAME} MATCHES linux)
add_lite_ai_toolkit_post_custom_command()
endif()



Expand Down
2 changes: 1 addition & 1 deletion mnn/core/mnn_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ template<typename T>
std::vector<T> mnncv::utils::math::softmax(const T *logits, unsigned int _size, unsigned int &max_id)
{
types::__assert_type<T>();
if (_size == 0 or logits == nullptr) return {};
if (_size == 0 || logits == nullptr) return {};
T max_prob = static_cast<T>(0), total_exp = static_cast<T>(0);
std::vector<float> softmax_probs(_size);
for (unsigned int i = 0; i < _size; ++i)
Expand Down
12 changes: 10 additions & 2 deletions mnn/cv/mnn_nanodet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MNNNanoDet::MNNNanoDet(const std::string _mnn_path, unsigned int _num_threads) :
initialize_pretreat();
}

void MNNNanoDet::initialize_pretreat()
inline void MNNNanoDet::initialize_pretreat()
{
pretreat = std::shared_ptr<MNN::CV::ImageProcess>(
MNN::CV::ImageProcess::create(
Expand All @@ -25,7 +25,7 @@ void MNNNanoDet::initialize_pretreat()
);
}

void MNNNanoDet::transform(const cv::Mat &mat_rs)
inline void MNNNanoDet::transform(const cv::Mat &mat_rs)
{
pretreat->convert(mat_rs.data, input_width, input_height, mat_rs.step[0], input_tensor);
}
Expand Down Expand Up @@ -109,7 +109,15 @@ void MNNNanoDet::generate_points(unsigned int target_height, unsigned int target
{
float grid0 = (float) g0 + 0.5f;
float grid1 = (float) g1 + 0.5f;
#ifdef LITE_WIN32
NanoCenterPoint point;
point.grid0 = grid0;
point.grid1 = grid1;
point.stride = (float) stride;
points.push_back(point);
#else
points.push_back((NanoCenterPoint) {grid0, grid1, (float) stride});
#endif
}
}
center_points[stride] = points;
Expand Down
8 changes: 8 additions & 0 deletions mnn/cv/mnn_nanodet_efficientnet_lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ void MNNNanoDetEfficientNetLite::generate_points(unsigned int target_height, uns
{
float grid0 = (float) g0 + 0.5f;
float grid1 = (float) g1 + 0.5f;
#ifdef LITE_WIN32
NanoLiteCenterPoint point;
point.grid0 = grid0;
point.grid1 = grid1;
point.stride = (float) stride;
points.push_back(point);
#else
points.push_back((NanoLiteCenterPoint) {grid0, grid1, (float) stride});
#endif
}
}
center_points[stride] = points;
Expand Down
2 changes: 1 addition & 1 deletion ort/core/ort_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ template<typename T>
std::vector<T> ortcv::utils::math::softmax(const T *logits, unsigned int _size, unsigned int &max_id)
{
types::__assert_type<T>();
if (_size == 0 or logits == nullptr) return {};
if (_size == 0 || logits == nullptr) return {};
T max_prob = static_cast<T>(0), total_exp = static_cast<T>(0);
std::vector<float> softmax_probs(_size);
for (unsigned int i = 0; i < _size; ++i)
Expand Down
10 changes: 9 additions & 1 deletion ort/cv/efficientdet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ void EfficientDet::generate_anchors(const float target_height, const float targe
float x1 = xv - anchor_size_x_2; // cx - aw/2
float y2 = yv + anchor_size_y_2; // cy + ah/2
float x2 = xv + anchor_size_x_2; // cx + aw/2

#ifdef LITE_WIN32
EfficientDetAnchor anchor;
anchor.y1 = y1;
anchor.x1 = x1;
anchor.y2 = y2;
anchor.x2 = x2;
anchors_buffer.push_back(anchor);
#else
anchors_buffer.push_back((EfficientDetAnchor) {y1, x1, y2, x2});
#endif
} // end ratios 3
} // end scale 3
}
Expand Down
10 changes: 9 additions & 1 deletion ort/cv/efficientdet_d7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ void EfficientDetD7::generate_anchors(const float target_height, const float tar
float x1 = xv - anchor_size_x_2; // cx - aw/2
float y2 = yv + anchor_size_y_2; // cy + ah/2
float x2 = xv + anchor_size_x_2; // cx + aw/2

#ifdef LITE_WIN32
EfficientDetD7Anchor anchor;
anchor.y1 = y1;
anchor.x1 = x1;
anchor.y2 = y2;
anchor.x2 = x2;
anchors_buffer.push_back(anchor);
#else
anchors_buffer.push_back((EfficientDetD7Anchor) {y1, x1, y2, x2});
#endif
} // end ratios 3
} // end scale 3
}
Expand Down
10 changes: 9 additions & 1 deletion ort/cv/efficientdet_d8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ void EfficientDetD8::generate_anchors(const float target_height, const float tar
float x1 = xv - anchor_size_x_2; // cx - aw/2
float y2 = yv + anchor_size_y_2; // cy + ah/2
float x2 = xv + anchor_size_x_2; // cx + aw/2

#ifdef LITE_WIN32
EfficientDetD8Anchor anchor;
anchor.y1 = y1;
anchor.x1 = x1;
anchor.y2 = y2;
anchor.x2 = x2;
anchors_buffer.push_back(anchor);
#else
anchors_buffer.push_back((EfficientDetD8Anchor) {y1, x1, y2, x2});
#endif
} // end ratios 3
} // end scale 3
}
Expand Down
8 changes: 8 additions & 0 deletions ort/cv/nanodet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ void NanoDet::generate_points(unsigned int target_height, unsigned int target_wi
{
float grid0 = (float) g0 + 0.5f;
float grid1 = (float) g1 + 0.5f;
#ifdef LITE_WIN32
NanoCenterPoint point;
point.grid0 = grid0;
point.grid1 = grid1;
point.stride = (float) stride;
points.push_back(point);
#else
points.push_back((NanoCenterPoint) {grid0, grid1, (float) stride});
#endif
}
}
center_points[stride] = points;
Expand Down
8 changes: 8 additions & 0 deletions ort/cv/nanodet_efficientnet_lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ void NanoDetEfficientNetLite::generate_points(unsigned int target_height, unsign
{
float grid0 = (float) g0 + 0.5f;
float grid1 = (float) g1 + 0.5f;
#ifdef LITE_WIN32
NanoLiteCenterPoint point;
point.grid0 = grid0;
point.grid1 = grid1;
point.stride = (float) stride;
points.push_back(point);
#else
points.push_back((NanoLiteCenterPoint) {grid0, grid1, (float) stride});
#endif
}
}
center_points[stride] = points;
Expand Down
8 changes: 8 additions & 0 deletions ort/cv/yolox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ void YoloX::generate_anchors(const int target_height,
{
for (int g0 = 0; g0 < num_grid_w; ++g0)
{
#ifdef LITE_WIN32
YoloXAnchor anchor;
anchor.grid0 = g0;
anchor.grid1 = g1;
anchor.stride = stride;
anchors.push_back(anchor);
#else
anchors.push_back((YoloXAnchor) {g0, g1, stride});
#endif
}
}
}
Expand Down