diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 6cc80a3daa9..eed49a5911e 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -23,7 +23,9 @@ set(MINDSPORE_LITE_TRAIN_LIB_NAME libmindspore-lite-train) set(BENCHMARK_TRAIN_NAME benchmark_train) set(BENCHMARK_TRAIN_ROOT_DIR ${RUNTIME_PKG_NAME}/tools/benchmark_train) +# full mode will also package the files of lite_cv mode. if(BUILD_MINDDATA STREQUAL "full") + # full header files install(FILES ${TOP_DIR}/mindspore/ccsrc/minddata/dataset/include/dataset/constants.h ${TOP_DIR}/mindspore/ccsrc/minddata/dataset/include/dataset/data_helper.h @@ -65,6 +67,10 @@ if(BUILD_MINDDATA STREQUAL "full") install(FILES ${TOP_DIR}/mindspore/lite/build/securec/src/libsecurec.a DESTINATION ${SECUREC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() + + # lite_cv header files + install(DIRECTORY ${TOP_DIR}/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv + DESTINATION ${MIND_DATA_INC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h") endif() if(BUILD_MINDDATA STREQUAL "wrapper") diff --git a/mindspore/lite/minddata/example/CMakeLists.txt b/mindspore/lite/minddata/example/CMakeLists.txt index c6c753ff5f7..70b9129e45b 100644 --- a/mindspore/lite/minddata/example/CMakeLists.txt +++ b/mindspore/lite/minddata/example/CMakeLists.txt @@ -5,8 +5,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -fPIC -std=c++17") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") set(MS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mindspore-lite-1.2.0-linux-x64/runtime") +set(LITECV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mindspore-lite-1.2.0-linux-x64/runtime/include/dataset") -include_directories(${MS_DIR}) +include_directories(${MS_DIR} ${LITECV_DIR}) add_executable(testlenet @@ -29,4 +30,14 @@ target_link_libraries(testresize ${MS_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so.62 ${MS_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so.0 ${MS_DIR}/lib/libmindspore-lite.so + pthread) + +add_executable(testlitecv + ${CMAKE_CURRENT_SOURCE_DIR}/testlitecv.cpp + ) + +target_link_libraries(testlitecv + ${MS_DIR}/lib/libminddata-lite.so + ${MS_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so.62 + ${MS_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so.0 pthread) \ No newline at end of file diff --git a/mindspore/lite/minddata/example/testlitecv.cpp b/mindspore/lite/minddata/example/testlitecv.cpp new file mode 100644 index 00000000000..bb67161485a --- /dev/null +++ b/mindspore/lite/minddata/example/testlitecv.cpp @@ -0,0 +1,73 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/api/types.h" +#include "include/dataset/lite_cv/lite_mat.h" +#include "include/dataset/lite_cv/image_process.h" +#include "include/dataset/vision_lite.h" +#include "include/dataset/execute.h" + +using mindspore::dataset::Execute; +using mindspore::dataset::LDataType; +using mindspore::dataset::LiteMat; +using mindspore::dataset::PaddBorderType; +using mindspore::dataset::vision::Decode; + +int main(int argc, char **argv) { + std::ifstream ifs("test_image.jpg"); + + if (!ifs.is_open() || !ifs.good()) { + std::cout << "fail to load image, check image path" << std::endl; + return -1; + } + + ifs.seekg(0, std::ios::end); + size_t size = ifs.tellg(); + mindspore::MSTensor image("file", mindspore::DataType::kNumberTypeUInt8, {static_cast(size)}, nullptr, size); + + ifs.seekg(0, std::ios::beg); + ifs.read(reinterpret_cast(image.MutableData()), size); + ifs.close(); + + auto decode = Decode(); + auto executor = Execute(decode); + executor(image, &image); + + LiteMat lite_mat_rgb(image.Shape()[1], image.Shape()[0], image.Shape()[2], const_cast(image.Data().get()), + LDataType::UINT8); + std::cout << "lite_mat_rgb: height=" << lite_mat_rgb.height_ << ", width=" << lite_mat_rgb.width_ << std::endl; + LiteMat lite_mat_resize; + + ResizeBilinear(lite_mat_rgb, lite_mat_resize, 256, 256); + std::cout << "lite_mat_resize: height=" << lite_mat_resize.height_ << ", width=" << lite_mat_resize.width_ + << std::endl; + + LiteMat lite_mat_pad; + Pad(lite_mat_resize, lite_mat_pad, 30, 30, 10, 10, PaddBorderType::PADD_BORDER_CONSTANT, 255, 255, 255); + std::cout << "lite_mat_pad: height=" << lite_mat_pad.height_ << ", width=" << lite_mat_pad.width_ << std::endl; +}