diff --git a/build.sh b/build.sh index 6dab57a77b..a2b3a5ca92 100755 --- a/build.sh +++ b/build.sh @@ -636,7 +636,6 @@ build_minddata_lite_deps() else CMAKE_MINDDATA_ARGS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" fi - build_opencv build_eigen build_jpeg_turbo } diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 1f6794a525..0605d6fb73 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -31,23 +31,14 @@ if (BUILD_MINDDATA STREQUAL "full") install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR} COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_core.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgcodecs.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgproc.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) elseif (PLATFORM_ARM32) install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR} COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_core.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgcodecs.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgproc.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) else () install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so.62.3.0 DESTINATION ${TURBO_DIR_RUN_X86}/lib RENAME libjpeg.so.62 COMPONENT ${RUN_X86_COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so.0.2.0 DESTINATION ${TURBO_DIR_RUN_X86}/lib RENAME libturbojpeg.so.0 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_core.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_core.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_imgcodecs.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_imgcodecs.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_imgproc.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_imgproc.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) endif () endif () @@ -57,23 +48,14 @@ if (BUILD_MINDDATA STREQUAL "lite") install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR} COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_core.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgcodecs.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgproc.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) elseif (PLATFORM_ARM32) install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR} COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so DESTINATION ${TURBO_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_core.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgcodecs.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgproc.so DESTINATION ${OPENCV_DIR}/lib COMPONENT ${COMPONENT_NAME}) else () install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${MIND_DATA_LIB_DIR_RUN_X86} COMPONENT ${RUN_X86_COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libjpeg.so.62.3.0 DESTINATION ${TURBO_DIR_RUN_X86}/lib RENAME libjpeg.so.62 COMPONENT ${RUN_X86_COMPONENT_NAME}) install(FILES ${TOP_DIR}/third_party/libjpeg-turbo/lib/libturbojpeg.so.0.2.0 DESTINATION ${TURBO_DIR_RUN_X86}/lib RENAME libturbojpeg.so.0 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_core.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_core.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_imgcodecs.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_imgcodecs.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/third_party/opencv/build/lib/libopencv_imgproc.so.4.2.0 DESTINATION ${OPENCV_DIR_RUN_X86}/lib RENAME libopencv_imgproc.so.4.2 COMPONENT ${RUN_X86_COMPONENT_NAME}) endif () endif () diff --git a/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc b/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc index 0db2f1fcec..abd4bf0434 100644 --- a/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc +++ b/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc @@ -21,6 +21,11 @@ #include "mindspore/core/ir/dtype/type_id.h" #include "mindspore/lite/internal/include/ms_tensor.h" #include "utils/hashing.h" +#ifndef ENABLE_ANDROID +#include "utils/log_adapter.h" +#else +#include "mindspore/lite/src/common/log_adapter.h" +#endif namespace mindspore { namespace tensor { @@ -43,7 +48,7 @@ MSTensor *DETensor::CreateFromMemory(TypeId data_type, const std::vector &s [](int s) -> dataset::dsize_t { return static_cast(s); }); (void)dataset::Tensor::CreateFromMemory(dataset::TensorShape(t_shape), dataset::MSTypeToDEType(data_type), - static_cast(data), &t); + static_cast(data), &t); return new DETensor(std::move(t)); } diff --git a/mindspore/ccsrc/minddata/dataset/api/execute.cc b/mindspore/ccsrc/minddata/dataset/api/execute.cc index 548bb8866b..d1db26c5c6 100644 --- a/mindspore/ccsrc/minddata/dataset/api/execute.cc +++ b/mindspore/ccsrc/minddata/dataset/api/execute.cc @@ -18,6 +18,11 @@ #include "minddata/dataset/include/de_tensor.h" #include "minddata/dataset/include/tensor.h" #include "minddata/dataset/kernels/tensor_op.h" +#ifndef ENABLE_ANDROID +#include "utils/log_adapter.h" +#else +#include "mindspore/lite/src/common/log_adapter.h" +#endif namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/api/transforms.cc b/mindspore/ccsrc/minddata/dataset/api/transforms.cc index bde329e107..3274f35725 100644 --- a/mindspore/ccsrc/minddata/dataset/api/transforms.cc +++ b/mindspore/ccsrc/minddata/dataset/api/transforms.cc @@ -15,7 +15,6 @@ */ #include "minddata/dataset/include/transforms.h" -#include "minddata/dataset/kernels/image/image_utils.h" // Kernel data headers (in alphabetical order) #include "minddata/dataset/kernels/data/one_hot_op.h" diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 6a3814ac32..abb2932088 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -16,17 +16,25 @@ #include "minddata/dataset/include/transforms.h" #include "minddata/dataset/include/vision.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" - +#endif // Kernel image headers (in alphabetical order) +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/center_crop_op.h" +#endif #include "minddata/dataset/kernels/image/crop_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/cutmix_batch_op.h" #include "minddata/dataset/kernels/image/cut_out_op.h" +#endif #include "minddata/dataset/kernels/image/decode_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/hwc_to_chw_op.h" #include "minddata/dataset/kernels/image/mixup_batch_op.h" +#endif #include "minddata/dataset/kernels/image/normalize_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/pad_op.h" #include "minddata/dataset/kernels/image/random_affine_op.h" #include "minddata/dataset/kernels/image/random_color_op.h" @@ -41,11 +49,14 @@ #include "minddata/dataset/kernels/image/random_solarize_op.h" #include "minddata/dataset/kernels/image/random_vertical_flip_op.h" #include "minddata/dataset/kernels/image/rescale_op.h" +#endif #include "minddata/dataset/kernels/image/resize_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/rgba_to_bgr_op.h" #include "minddata/dataset/kernels/image/rgba_to_rgb_op.h" #include "minddata/dataset/kernels/image/swap_red_blue_op.h" #include "minddata/dataset/kernels/image/uniform_aug_op.h" +#endif namespace mindspore { namespace dataset { @@ -53,7 +64,7 @@ namespace api { // Transform operations for computer vision. namespace vision { - +#ifndef ENABLE_ANDROID // FUNCTIONS TO CREATE VISION TRANSFORM OPERATIONS // (In alphabetical order) @@ -66,6 +77,7 @@ std::shared_ptr CenterCrop(std::vector size) { } return op; } +#endif // Function to create CropOperation. std::shared_ptr Crop(std::vector coordinates, std::vector size) { @@ -76,7 +88,7 @@ std::shared_ptr Crop(std::vector coordinates, std::vecto } return op; } - +#ifndef ENABLE_ANDROID // Function to create CutMixBatchOperation. std::shared_ptr CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob) { auto op = std::make_shared(image_batch_format, alpha, prob); @@ -301,6 +313,7 @@ std::shared_ptr Rescale(float rescale, float shift) { return op; } +#endif // Function to create ResizeOperation. std::shared_ptr Resize(std::vector size, InterpolationMode interpolation) { auto op = std::make_shared(size, interpolation); @@ -311,6 +324,7 @@ std::shared_ptr Resize(std::vector size, Interpolation return op; } +#ifndef ENABLE_ANDROID // Function to create RgbaToBgrOperation. std::shared_ptr RGBA2BGR() { auto op = std::make_shared(); @@ -352,6 +366,7 @@ std::shared_ptr UniformAugment(std::vector &size) { for (int32_t i = 0; i < size.size(); ++i) { @@ -371,7 +386,7 @@ bool CmpFloat(const float &a, const float &b, float epsilon = 0.0000000001f) { r /* ####################################### Derived TensorOperation classes ################################# */ // (In alphabetical order) - +#ifndef ENABLE_ANDROID // CenterCropOperation CenterCropOperation::CenterCropOperation(std::vector size) : size_(size) {} @@ -410,6 +425,7 @@ std::shared_ptr CenterCropOperation::Build() { return tensor_op; } +#endif // CropOperation. CropOperation::CropOperation(std::vector coordinates, std::vector size) : coordinates_(coordinates), size_(size) {} @@ -467,6 +483,7 @@ std::shared_ptr CropOperation::Build() { return tensor_op; } +#ifndef ENABLE_ANDROID // CutMixBatchOperation CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob) : image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {} @@ -1369,6 +1386,7 @@ std::shared_ptr RescaleOperation::Build() { return tensor_op; } +#endif // ResizeOperation ResizeOperation::ResizeOperation(std::vector size, InterpolationMode interpolation) : size_(size), interpolation_(interpolation) {} @@ -1397,6 +1415,7 @@ std::shared_ptr ResizeOperation::Build() { return std::make_shared(height, width, interpolation_); } +#ifndef ENABLE_ANDROID // RgbaToBgrOperation. RgbaToBgrOperation::RgbaToBgrOperation() {} @@ -1461,6 +1480,7 @@ std::shared_ptr UniformAugOperation::Build() { std::shared_ptr tensor_op = std::make_shared(tensor_ops, num_ops_); return tensor_op; } +#endif } // namespace vision } // namespace api diff --git a/mindspore/ccsrc/minddata/dataset/core/data_type.cc b/mindspore/ccsrc/minddata/dataset/core/data_type.cc index 77cf2f45a5..9608caec25 100644 --- a/mindspore/ccsrc/minddata/dataset/core/data_type.cc +++ b/mindspore/ccsrc/minddata/dataset/core/data_type.cc @@ -43,6 +43,7 @@ py::dtype DataType::AsNumpyType() const { } #endif +#ifndef ENABLE_ANDROID uint8_t DataType::AsCVType() const { uint8_t res = kCVInvalidType; if (type_ < DataType::NUM_OF_TYPES) { @@ -80,6 +81,7 @@ DataType DataType::FromCVType(int cv_type) { return DataType(DataType::DE_UNKNOWN); } } +#endif DataType::DataType(const std::string &type_str) { if (type_str == "bool") diff --git a/mindspore/ccsrc/minddata/dataset/core/data_type.h b/mindspore/ccsrc/minddata/dataset/core/data_type.h index 2e17218d5d..33aa1ab452 100644 --- a/mindspore/ccsrc/minddata/dataset/core/data_type.h +++ b/mindspore/ccsrc/minddata/dataset/core/data_type.h @@ -16,7 +16,9 @@ #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_DATA_TYPE_H_ #define MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_DATA_TYPE_H_ +#ifndef ENABLE_ANDROID #include +#endif #include #ifdef ENABLE_PYTHON @@ -79,6 +81,7 @@ class DataType { {"string", 0, "bytes", "S", kCVInvalidType} // DE_STRING }; #else +#ifndef ENABLE_ANDROID static inline const TypeInfo kTypeInfo[] = { // name, sizeInBytes, pybindTypem formatDescriptor, openCV {"unknown", 0, "object", "", kCVInvalidType}, // DE_UNKNOWN @@ -96,8 +99,27 @@ class DataType { {"float64", 8, "double", "", CV_64F}, // DE_FLOAT64 {"string", 0, "bytes", "", kCVInvalidType} // DE_STRING }; +#else + // android and no python + static inline const TypeInfo kTypeInfo[] = { + // name, sizeInBytes, formatDescriptor + {"unknown", 0, "object", "", kCVInvalidType}, // DE_UNKNOWN + {"bool", 1, "bool", ""}, // DE_BOOL + {"int8", 1, "int8", ""}, // DE_INT8 + {"uint8", 1, "uint8", ""}, // DE_UINT8 + {"int16", 2, "int16", ""}, // DE_INT16 + {"uint16", 2, "uint16", ""}, // DE_UINT16 + {"int32", 4, "int32", ""}, // DE_INT32 + {"uint32", 4, "uint32", "", kCVInvalidType}, // DE_UINT32 + {"int64", 8, "int64", "", kCVInvalidType}, // DE_INT64 + {"uint64", 8, "uint64", "", kCVInvalidType}, // DE_UINT64 + {"float16", 2, "float16", ""}, // DE_FLOAT16 + {"float32", 4, "float32", ""}, // DE_FLOAT32 + {"float64", 8, "double", ""}, // DE_FLOAT64 + {"string", 0, "bytes", "", kCVInvalidType} // DE_STRING + }; +#endif #endif - // No arg constructor to create an unknown shape DataType() : type_(DE_UNKNOWN) {} @@ -132,6 +154,7 @@ class DataType { /// \return uint8_t SizeInBytes() const; +#ifndef ENABLE_ANDROID // Convert from DataType to OpenCV type /// \return uint8_t AsCVType() const; @@ -140,6 +163,7 @@ class DataType { /// \param cv_type /// \return static DataType FromCVType(int cv_type); +#endif // Returns a string representation of the type /// \return diff --git a/mindspore/ccsrc/minddata/dataset/core/global_context.cc b/mindspore/ccsrc/minddata/dataset/core/global_context.cc index eb76382ab2..4920bef0e6 100644 --- a/mindspore/ccsrc/minddata/dataset/core/global_context.cc +++ b/mindspore/ccsrc/minddata/dataset/core/global_context.cc @@ -19,7 +19,9 @@ #include #include "minddata/dataset/core/config_manager.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/core/cv_tensor.h" +#endif #include "minddata/dataset/core/tensor.h" #include "minddata/dataset/util/allocator.h" #include "minddata/dataset/util/circular_pool.h" @@ -56,7 +58,9 @@ Status GlobalContext::Init() { // Create some tensor allocators for the different types and hook them into the pool. tensor_allocator_ = std::make_unique>(mem_pool_); +#ifndef ENABLE_ANDROID cv_tensor_allocator_ = std::make_unique>(mem_pool_); +#endif int_allocator_ = std::make_unique(mem_pool_); return Status::OK(); } diff --git a/mindspore/ccsrc/minddata/dataset/core/tensor.cc b/mindspore/ccsrc/minddata/dataset/core/tensor.cc index f3c7161a9c..dc94ba3e50 100644 --- a/mindspore/ccsrc/minddata/dataset/core/tensor.cc +++ b/mindspore/ccsrc/minddata/dataset/core/tensor.cc @@ -26,7 +26,11 @@ #include "utils/ms_utils.h" #include "minddata/dataset/core/constants.h" + +#ifndef ENABLE_ANDROID #include "minddata/dataset/core/cv_tensor.h" +#endif + #include "minddata/dataset/core/global_context.h" #ifdef ENABLE_PYTHON diff --git a/mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc b/mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc index 6a0fd22c33..d573486ee4 100644 --- a/mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc +++ b/mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc @@ -96,6 +96,7 @@ TensorShape::TensorShape(py::list l) } #endif +#ifndef ENABLE_ANDROID TensorShape::TensorShape(cv::MatSize cv_size, uint32_t type) : raw_shape_(*GlobalContext::Instance()->int_allocator()), strides_(*GlobalContext::Instance()->int_allocator()) { for (int i = 0; i < cv_size.dims(); i++) { @@ -107,6 +108,7 @@ TensorShape::TensorShape(cv::MatSize cv_size, uint32_t type) } known_ = true; } +#endif TensorShape TensorShape::CreateUnknownRankShape() { TensorShape s({}); diff --git a/mindspore/ccsrc/minddata/dataset/core/tensor_shape.h b/mindspore/ccsrc/minddata/dataset/core/tensor_shape.h index 179c922c6c..067641bed4 100644 --- a/mindspore/ccsrc/minddata/dataset/core/tensor_shape.h +++ b/mindspore/ccsrc/minddata/dataset/core/tensor_shape.h @@ -22,7 +22,9 @@ #include #include +#ifndef ENABLE_ANDROID #include +#endif #ifdef ENABLE_PYTHON #include "pybind11/pybind11.h" @@ -105,10 +107,12 @@ class TensorShape { /// \return TensorShape AppendDim(dsize_t dim) const; +#ifndef ENABLE_ANDROID /// \brief Create a shape based on OpenCV shape and type /// \param[in] cv_size /// \param[in] type int that represent the type in OpenCV, example CV_8U, CV_64S TensorShape(cv::MatSize cv_size, uint32_t type); +#endif dsize_t Size() const { return raw_shape_.size(); } diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc index 0aa9c3c932..cb9f1c8348 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc @@ -22,7 +22,11 @@ #include "minddata/dataset/engine/db_connector.h" #include "minddata/dataset/engine/execution_tree.h" #include "minddata/dataset/engine/opt/pass.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc index 7b7d7f94ea..295400b865 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc @@ -24,7 +24,11 @@ #include "minddata/dataset/engine/data_schema.h" #include "minddata/dataset/engine/execution_tree.h" #include "minddata/dataset/engine/opt/pass.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h index 534dab9649..096caa9e63 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h @@ -28,7 +28,11 @@ #include "minddata/dataset/engine/data_schema.h" #include "minddata/dataset/engine/datasetops/parallel_op.h" #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/path.h" #include "minddata/dataset/util/queue.h" #include "minddata/dataset/util/status.h" diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h index 90b813f60b..dac20b7fd1 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h @@ -30,7 +30,11 @@ #include "minddata/dataset/engine/data_schema.h" #include "minddata/dataset/engine/datasetops/parallel_op.h" #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/path.h" #include "minddata/dataset/util/queue.h" #include "minddata/dataset/util/services.h" diff --git a/mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc b/mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc index 42660b4599..6819dce389 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc @@ -26,9 +26,9 @@ #include "minddata/dataset/engine/opt/pre/cache_transform_pass.h" #include "minddata/dataset/engine/opt/post/repeat_pass.h" #include "minddata/dataset/engine/opt/pre/cache_error_pass.h" +#include "mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.h" #endif #include "minddata/dataset/engine/opt/pre/epoch_injection_pass.h" -#include "mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.h" #include "minddata/dataset/engine/perf/profiling.h" #include "minddata/dataset/engine/perf/monitor.h" @@ -222,7 +222,6 @@ Status ExecutionTree::Prepare(int32_t num_epochs) { if (optimize_) { RETURN_IF_NOT_OK(this->Optimize()); } - // Post optimization compulsory transformation RETURN_IF_NOT_OK(this->PrepareTreePostAction()); @@ -276,7 +275,9 @@ Status ExecutionTree::PrepareTreePostAction() { Status ExecutionTree::Optimize() { // Vector of optimizations, currently only 1, add more as necessary std::vector> optimizations; +#ifndef ENABLE_ANDROID optimizations.push_back(std::make_unique()); +#endif // vector of flags for each optimization std::vector modified(optimizations.size(), false); for (auto i = 0; i < optimizations.size(); i++) { diff --git a/mindspore/ccsrc/minddata/dataset/include/vision.h b/mindspore/ccsrc/minddata/dataset/include/vision.h index d71b85e729..f757398734 100644 --- a/mindspore/ccsrc/minddata/dataset/include/vision.h +++ b/mindspore/ccsrc/minddata/dataset/include/vision.h @@ -31,14 +31,21 @@ namespace api { namespace vision { // Transform Op classes (in alphabetical order) +#ifndef ENABLE_ANDROID class CenterCropOperation; +#endif class CropOperation; +#ifndef ENABLE_ANDROID class CutMixBatchOperation; class CutOutOperation; +#endif class DecodeOperation; +#ifndef ENABLE_ANDROID class HwcToChwOperation; class MixUpBatchOperation; +#endif class NormalizeOperation; +#ifndef ENABLE_ANDROID class PadOperation; class RandomAffineOperation; class RandomColorOperation; @@ -53,7 +60,9 @@ class RandomSharpnessOperation; class RandomSolarizeOperation; class RandomVerticalFlipOperation; class RescaleOperation; +#endif class ResizeOperation; +#ifndef ENABLE_ANDROID class RgbaToBgrOperation; class RgbaToRgbOperation; class SwapRedBlueOperation; @@ -66,14 +75,14 @@ class UniformAugOperation; /// If size has 2 values, it should be (height, width). /// \return Shared pointer to the current TensorOperation. std::shared_ptr CenterCrop(std::vector size); - +#endif /// \brief Function to create a Crop TensorOp /// \notes Crop an image based on location and crop size /// \param[in] coordinates Starting location of crop. Must be a vector of two values, in the form of {x_coor, y_coor} /// \param[in] size Size of the cropped area. Must be a vector of two values, in the form of {height, width} /// \return Shared pointer to the current TensorOp std::shared_ptr Crop(std::vector coordinates, std::vector size); - +#ifndef ENABLE_ANDROID /// \brief Function to apply CutMix on a batch of images /// \notes Masks a random section of each image with the corresponding part of another randomly /// selected image in that batch @@ -91,12 +100,14 @@ std::shared_ptr CutMixBatch(ImageBatchFormat image_batch_f /// \return Shared pointer to the current TensorOp std::shared_ptr CutOut(int32_t length, int32_t num_patches = 1); +#endif /// \brief Function to create a Decode TensorOperation. /// \notes Decode the input image in RGB mode. /// \param[in] rgb A boolean of whether to decode in RGB mode or not. /// \return Shared pointer to the current TensorOperation. std::shared_ptr Decode(bool rgb = true); +#ifndef ENABLE_ANDROID /// \brief Function to create a HwcToChw TensorOperation. /// \notes Transpose the input image; shape (H, W, C) to shape (C, H, W). /// \return Shared pointer to the current TensorOperation. @@ -109,6 +120,7 @@ std::shared_ptr HWC2CHW(); /// \return Shared pointer to the current TensorOperation. std::shared_ptr MixUpBatch(float alpha = 1); +#endif /// \brief Function to create a Normalize TensorOperation. /// \notes Normalize the input image with respect to mean and standard deviation. /// \param[in] mean A vector of mean values for each channel, w.r.t channel order. @@ -118,6 +130,7 @@ std::shared_ptr MixUpBatch(float alpha = 1); /// \return Shared pointer to the current TensorOperation. std::shared_ptr Normalize(std::vector mean, std::vector std); +#ifndef ENABLE_ANDROID /// \brief Function to create a Pad TensorOp /// \notes Pads the image according to padding parameters /// \param[in] padding A vector representing the number of pixels to pad the image @@ -287,6 +300,7 @@ std::shared_ptr RandomVerticalFlip(float prob = 0.5 /// \return Shared pointer to the current TensorOperation. std::shared_ptr Rescale(float rescale, float shift); +#endif /// \brief Function to create a Resize TensorOperation. /// \notes Resize the input image to the given size. /// \param[in] size A vector representing the output size of the resized image. @@ -297,6 +311,7 @@ std::shared_ptr Rescale(float rescale, float shift); std::shared_ptr Resize(std::vector size, InterpolationMode interpolation = InterpolationMode::kLinear); +#ifndef ENABLE_ANDROID /// \brief Function to create a RgbaToBgr TensorOperation. /// \notes Changes the input 4 channel RGBA tensor to 3 channel BGR. /// \return Shared pointer to the current TensorOperation. @@ -335,7 +350,7 @@ class CenterCropOperation : public TensorOperation { private: std::vector size_; }; - +#endif class CropOperation : public TensorOperation { public: CropOperation(std::vector coordinates, std::vector size); @@ -350,7 +365,7 @@ class CropOperation : public TensorOperation { std::vector coordinates_; std::vector size_; }; - +#ifndef ENABLE_ANDROID class CutMixBatchOperation : public TensorOperation { public: explicit CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha = 1.0, float prob = 1.0); @@ -383,6 +398,7 @@ class CutOutOperation : public TensorOperation { ImageBatchFormat image_batch_format_; }; +#endif class DecodeOperation : public TensorOperation { public: explicit DecodeOperation(bool rgb = true); @@ -397,6 +413,7 @@ class DecodeOperation : public TensorOperation { bool rgb_; }; +#ifndef ENABLE_ANDROID class HwcToChwOperation : public TensorOperation { public: ~HwcToChwOperation() = default; @@ -420,6 +437,7 @@ class MixUpBatchOperation : public TensorOperation { float alpha_; }; +#endif class NormalizeOperation : public TensorOperation { public: NormalizeOperation(std::vector mean, std::vector std); @@ -435,6 +453,7 @@ class NormalizeOperation : public TensorOperation { std::vector std_; }; +#ifndef ENABLE_ANDROID class PadOperation : public TensorOperation { public: PadOperation(std::vector padding, std::vector fill_value = {0}, @@ -672,6 +691,7 @@ class RescaleOperation : public TensorOperation { float shift_; }; +#endif class ResizeOperation : public TensorOperation { public: explicit ResizeOperation(std::vector size, @@ -688,6 +708,7 @@ class ResizeOperation : public TensorOperation { InterpolationMode interpolation_; }; +#ifndef ENABLE_ANDROID class RgbaToBgrOperation : public TensorOperation { public: RgbaToBgrOperation(); @@ -735,6 +756,8 @@ class UniformAugOperation : public TensorOperation { std::vector> transforms_; int32_t num_ops_; }; +#endif + } // namespace vision } // namespace api } // namespace dataset diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc index 730cb0a39a..adc9d10d52 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc @@ -649,6 +649,7 @@ Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std:: return Status::OK(); } +#ifndef ENABLE_ANDROID Status BatchTensorToCVTensorVector(const std::shared_ptr &input, std::vector> *output) { std::vector tensor_shape = input->shape().AsVector(); @@ -673,6 +674,7 @@ Status BatchTensorToCVTensorVector(const std::shared_ptr &input, } return Status::OK(); } +#endif Status BatchTensorToTensorVector(const std::shared_ptr &input, std::vector> *output) { std::vector tensor_shape = input->shape().AsVector(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h index e46df4bbd1..d875bf6aa5 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h @@ -21,7 +21,9 @@ #include #include #include "minddata/dataset/core/constants.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/core/cv_tensor.h" +#endif #include "minddata/dataset/core/data_type.h" #include "minddata/dataset/core/tensor.h" #include "minddata/dataset/core/tensor_row.h" diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc index 5d1853b78d..62493dcfa7 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc @@ -15,7 +15,11 @@ */ #include "minddata/dataset/kernels/image/crop_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/status.h" namespace mindspore { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h index 35d3ebeda5..a67cc29448 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h @@ -21,7 +21,11 @@ #include #include "minddata/dataset/core/tensor.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/kernels/tensor_op.h" #include "minddata/dataset/util/status.h" diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc index 6e73fde8b7..6ef6f4eed1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc @@ -15,7 +15,11 @@ */ #include "minddata/dataset/kernels/image/decode_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/status.h" namespace mindspore { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc index 9c35345db8..9d59612e98 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "lite_cv/image_process.h" +#include "minddata/dataset/kernels/image/lite_cv/image_process.h" #include #include diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h index 81e78bacf8..65cd8cf935 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h @@ -22,7 +22,7 @@ #include #include -#include "lite_cv/lite_mat.h" +#include "minddata/dataset/kernels/image/lite_cv/lite_mat.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc index 63f9ac5cbb..38fef09aba 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "lite_cv/lite_mat.h" +#include "minddata/dataset/kernels/image/lite_cv/lite_mat.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc new file mode 100644 index 0000000000..67e7379f09 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc @@ -0,0 +1,368 @@ +/** + * Copyright 2020 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 "minddata/dataset/kernels/image/lite_image_utils.h" +#include +#include +#include +#include +#include "utils/ms_utils.h" +#include "minddata/dataset/kernels/image/lite_cv/lite_mat.h" +#include "minddata/dataset/kernels/image/lite_cv/image_process.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/util/random.h" + +#define MAX_INT_PRECISION 16777216 // float int precision is 16777216 +namespace mindspore { +namespace dataset { +bool IsNonEmptyJPEG(const std::shared_ptr &input) { + const unsigned char *kJpegMagic = (unsigned char *)"\xFF\xD8\xFF"; + constexpr size_t kJpegMagicLen = 3; + return input->SizeInBytes() > kJpegMagicLen && memcmp(input->GetBuffer(), kJpegMagic, kJpegMagicLen) == 0; +} + +static void JpegInitSource(j_decompress_ptr cinfo) {} + +static boolean JpegFillInputBuffer(j_decompress_ptr cinfo) { + if (cinfo->src->bytes_in_buffer == 0) { + // Under ARM platform raise runtime_error may cause core problem, + // so we catch runtime_error and just return FALSE. + try { + ERREXIT(cinfo, JERR_INPUT_EMPTY); + } catch (std::runtime_error &e) { + return FALSE; + } + return FALSE; + } + return TRUE; +} + +static void JpegTermSource(j_decompress_ptr cinfo) {} + +static void JpegSkipInputData(j_decompress_ptr cinfo, int64_t jump) { + if (jump < 0) { + return; + } + if (static_cast(jump) > cinfo->src->bytes_in_buffer) { + cinfo->src->bytes_in_buffer = 0; + return; + } else { + cinfo->src->bytes_in_buffer -= jump; + cinfo->src->next_input_byte += jump; + } +} + +void JpegSetSource(j_decompress_ptr cinfo, const void *data, int64_t datasize) { + cinfo->src = static_cast( + (*cinfo->mem->alloc_small)(reinterpret_cast(cinfo), JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr))); + cinfo->src->init_source = JpegInitSource; + cinfo->src->fill_input_buffer = JpegFillInputBuffer; +#if defined(_WIN32) || defined(_WIN64) || defined(ENABLE_ARM32) + // the following line skips CI because it uses underlying C type + cinfo->src->skip_input_data = reinterpret_cast(JpegSkipInputData); // NOLINT. +#else + cinfo->src->skip_input_data = JpegSkipInputData; +#endif + cinfo->src->resync_to_restart = jpeg_resync_to_restart; + cinfo->src->term_source = JpegTermSource; + cinfo->src->bytes_in_buffer = datasize; + cinfo->src->next_input_byte = static_cast(data); +} + +static Status JpegReadScanlines(jpeg_decompress_struct *const cinfo, int max_scanlines_to_read, JSAMPLE *buffer, + int buffer_size, int crop_w, int crop_w_aligned, int offset, int stride) { + // scanlines will be read to this buffer first, must have the number + // of components equal to the number of components in the image + int64_t scanline_size = crop_w_aligned * cinfo->output_components; + std::vector scanline(scanline_size); + JSAMPLE *scanline_ptr = &scanline[0]; + while (cinfo->output_scanline < static_cast(max_scanlines_to_read)) { + int num_lines_read = 0; + try { + num_lines_read = jpeg_read_scanlines(cinfo, &scanline_ptr, 1); + } catch (std::runtime_error &e) { + RETURN_STATUS_UNEXPECTED("jpeg_read_scanlines error."); + } + if (cinfo->out_color_space == JCS_CMYK && num_lines_read > 0) { + for (int i = 0; i < crop_w; ++i) { + int cmyk_pixel = 4 * i + offset; + const int c = scanline_ptr[cmyk_pixel]; + const int m = scanline_ptr[cmyk_pixel + 1]; + const int y = scanline_ptr[cmyk_pixel + 2]; + const int k = scanline_ptr[cmyk_pixel + 3]; + int r, g, b; + if (cinfo->saw_Adobe_marker) { + r = (k * c) / 255; + g = (k * m) / 255; + b = (k * y) / 255; + } else { + r = (255 - c) * (255 - k) / 255; + g = (255 - m) * (255 - k) / 255; + b = (255 - y) * (255 - k) / 255; + } + buffer[3 * i + 0] = r; + buffer[3 * i + 1] = g; + buffer[3 * i + 2] = b; + } + } else if (num_lines_read > 0) { + int copy_status = memcpy_s(buffer, buffer_size, scanline_ptr + offset, stride); + if (copy_status != 0) { + jpeg_destroy_decompress(cinfo); + RETURN_STATUS_UNEXPECTED("memcpy failed"); + } + } else { + jpeg_destroy_decompress(cinfo); + std::string err_msg = "failed to read scanline"; + RETURN_STATUS_UNEXPECTED(err_msg); + } + buffer += stride; + buffer_size = buffer_size - stride; + } + return Status::OK(); +} + +static Status JpegSetColorSpace(jpeg_decompress_struct *cinfo) { + switch (cinfo->num_components) { + case 1: + // we want to output 3 components if it's grayscale + cinfo->out_color_space = JCS_RGB; + return Status::OK(); + case 3: + cinfo->out_color_space = JCS_RGB; + return Status::OK(); + case 4: + // Need to manually convert to RGB + cinfo->out_color_space = JCS_CMYK; + return Status::OK(); + default: + jpeg_destroy_decompress(cinfo); + std::string err_msg = "wrong number of components"; + RETURN_STATUS_UNEXPECTED(err_msg); + } +} + +void JpegErrorExitCustom(j_common_ptr cinfo) { + char jpeg_last_error_msg[JMSG_LENGTH_MAX]; + (*(cinfo->err->format_message))(cinfo, jpeg_last_error_msg); + throw std::runtime_error(jpeg_last_error_msg); +} + +Status JpegCropAndDecode(const std::shared_ptr &input, std::shared_ptr *output, int crop_x, int crop_y, + int crop_w, int crop_h) { + struct jpeg_decompress_struct cinfo; + auto DestroyDecompressAndReturnError = [&cinfo](const std::string &err) { + jpeg_destroy_decompress(&cinfo); + RETURN_STATUS_UNEXPECTED(err); + }; + struct JpegErrorManagerCustom jerr; + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = JpegErrorExitCustom; + try { + jpeg_create_decompress(&cinfo); + JpegSetSource(&cinfo, input->GetBuffer(), input->SizeInBytes()); + (void)jpeg_read_header(&cinfo, TRUE); + RETURN_IF_NOT_OK(JpegSetColorSpace(&cinfo)); + jpeg_calc_output_dimensions(&cinfo); + } catch (std::runtime_error &e) { + return DestroyDecompressAndReturnError(e.what()); + } + if (crop_x == 0 && crop_y == 0 && crop_w == 0 && crop_h == 0) { + crop_w = cinfo.output_width; + crop_h = cinfo.output_height; + } else if (crop_w == 0 || static_cast(crop_w + crop_x) > cinfo.output_width || crop_h == 0 || + static_cast(crop_h + crop_y) > cinfo.output_height) { + return DestroyDecompressAndReturnError("Crop window is not valid"); + } + const int mcu_size = cinfo.min_DCT_scaled_size; + unsigned int crop_x_aligned = (crop_x / mcu_size) * mcu_size; + unsigned int crop_w_aligned = crop_w + crop_x - crop_x_aligned; + try { + (void)jpeg_start_decompress(&cinfo); + jpeg_crop_scanline(&cinfo, &crop_x_aligned, &crop_w_aligned); + } catch (std::runtime_error &e) { + return DestroyDecompressAndReturnError(e.what()); + } + JDIMENSION skipped_scanlines = jpeg_skip_scanlines(&cinfo, crop_y); + // three number of output components, always convert to RGB and output + constexpr int kOutNumComponents = 3; + TensorShape ts = TensorShape({crop_h, crop_w, kOutNumComponents}); + std::shared_ptr output_tensor; + RETURN_IF_NOT_OK(Tensor::CreateEmpty(ts, DataType(DataType::DE_UINT8), &output_tensor)); + const int buffer_size = output_tensor->SizeInBytes(); + JSAMPLE *buffer = reinterpret_cast(&(*output_tensor->begin())); + const int max_scanlines_to_read = skipped_scanlines + crop_h; + // stride refers to output tensor, which has 3 components at most + const int stride = crop_w * kOutNumComponents; + // offset is calculated for scanlines read from the image, therefore + // has the same number of components as the image + const int offset = (crop_x - crop_x_aligned) * cinfo.output_components; + RETURN_IF_NOT_OK( + JpegReadScanlines(&cinfo, max_scanlines_to_read, buffer, buffer_size, crop_w, crop_w_aligned, offset, stride)); + *output = output_tensor; + jpeg_destroy_decompress(&cinfo); + return Status::OK(); +} + +Status Decode(const std::shared_ptr &input, std::shared_ptr *output) { + if (IsNonEmptyJPEG(input)) { + return JpegCropAndDecode(input, output); + } else { + RETURN_STATUS_UNEXPECTED("Decode only supports jpeg for android"); + } +} + +Status Crop(const std::shared_ptr &input, std::shared_ptr *output, int x, int y, int w, int h) { + if (input->Rank() != 3 && input->Rank() != 2) { + RETURN_STATUS_UNEXPECTED("Shape not or "); + } + // account for integer overflow + if (y < 0 || (y + h) > input->shape()[0] || (y + h) < 0) { + RETURN_STATUS_UNEXPECTED("Invalid y coordinate value for crop"); + } + // account for integer overflow + if (x < 0 || (x + w) > input->shape()[1] || (x + w) < 0) { + RETURN_STATUS_UNEXPECTED("Invalid x coordinate value for crop"); + } + // convert to lite Mat + LiteMat lite_mat_rgb; + // rows = height, this constructor takes: cols,rows + bool ret = InitFromPixel(input->GetBuffer(), LPixelType::RGB, LDataType::UINT8, input->shape()[1], input->shape()[0], + lite_mat_rgb); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Creation of lite cv failed"); + try { + TensorShape shape{h, w}; + int num_channels = input->shape()[2]; + if (input->Rank() == 3) shape = shape.AppendDim(num_channels); + LiteMat lite_mat_cut; + ret = Crop(lite_mat_rgb, lite_mat_cut, x, y, x + w, y + h); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Crop failed in lite cv"); + // create output Tensor based off of lite_mat_cut + std::shared_ptr output_tensor; + RETURN_IF_NOT_OK( + Tensor::CreateFromMemory(shape, input->type(), static_cast(lite_mat_cut.data_ptr_), &output_tensor)); + *output = output_tensor; + return Status::OK(); + } catch (std::runtime_error &e) { + RETURN_STATUS_UNEXPECTED("Unexpected error in crop."); + } + return Status::OK(); +} + +Status GetJpegImageInfo(const std::shared_ptr &input, int *img_width, int *img_height) { + struct jpeg_decompress_struct cinfo {}; + struct JpegErrorManagerCustom jerr {}; + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = JpegErrorExitCustom; + try { + jpeg_create_decompress(&cinfo); + JpegSetSource(&cinfo, input->GetBuffer(), input->SizeInBytes()); + (void)jpeg_read_header(&cinfo, TRUE); + jpeg_calc_output_dimensions(&cinfo); + } catch (std::runtime_error &e) { + jpeg_destroy_decompress(&cinfo); + RETURN_STATUS_UNEXPECTED(e.what()); + } + *img_height = cinfo.output_height; + *img_width = cinfo.output_width; + jpeg_destroy_decompress(&cinfo); + return Status::OK(); +} + +Status Normalize(const std::shared_ptr &input, std::shared_ptr *output, + const std::shared_ptr &mean, const std::shared_ptr &std) { + if (input->Rank() != 3) { + RETURN_STATUS_UNEXPECTED("Input tensor rank isn't 3"); + } + LiteMat lite_mat_rgb; + // rows = height, this constructor takes: cols,rows + bool ret = InitFromPixel(input->GetBuffer(), LPixelType::RGB, LDataType::UINT8, input->shape()[1], input->shape()[0], + lite_mat_rgb); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Creation of lite cv failed"); + + mean->Squeeze(); + if (mean->type() != DataType::DE_FLOAT32 || mean->Rank() != 1 || mean->shape()[0] != 3) { + std::string err_msg = "Mean tensor should be of size 3 and type float."; + return Status(StatusCode::kShapeMisMatch, err_msg); + } + std->Squeeze(); + if (std->type() != DataType::DE_FLOAT32 || std->Rank() != 1 || std->shape()[0] != 3) { + std::string err_msg = "Std tensor should be of size 3 and type float."; + return Status(StatusCode::kShapeMisMatch, err_msg); + } + // convert mean, std back to vector + std::vector vec_mean; + std::vector vec_std; + try { + for (uint8_t i = 0; i < 3; i++) { + float mean_c, std_c; + RETURN_IF_NOT_OK(mean->GetItemAt(&mean_c, {i})); + RETURN_IF_NOT_OK(std->GetItemAt(&std_c, {i})); + vec_mean.push_back(mean_c); + vec_std.push_back(std_c); + } + LiteMat lite_mat_norm; + ret = SubStractMeanNormalize(lite_mat_rgb, lite_mat_norm, vec_mean, vec_std); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Normalize in lite cv failed"); + // create output Tensor based off of lite_mat_cut + std::shared_ptr output_tensor; + RETURN_IF_NOT_OK(Tensor::CreateFromMemory(input->shape(), DataType(DataType::DE_FLOAT32), + static_cast(lite_mat_norm.data_ptr_), &output_tensor)); + *output = output_tensor; + } catch (std::runtime_error &e) { + RETURN_STATUS_UNEXPECTED("Unexpected error in normalize."); + } + return Status::OK(); +} + +Status Resize(const std::shared_ptr &input, std::shared_ptr *output, int32_t output_height, + int32_t output_width, double fx, double fy, InterpolationMode mode) { + if (input->Rank() != 3) { + RETURN_STATUS_UNEXPECTED("Input Tensor is not in shape of "); + } + // resize image too large or too small + if (output_height == 0 || output_height > input->shape()[0] * 1000 || output_width == 0 || + output_width > input->shape()[1] * 1000) { + std::string err_msg = + "The resizing width or height 1) is too big, it's up to " + "1000 times the original image; 2) can not be 0."; + return Status(StatusCode::kShapeMisMatch, err_msg); + } + LiteMat lite_mat_rgb; + bool ret = InitFromPixel(input->GetBuffer(), LPixelType::RGB, LDataType::UINT8, input->shape()[1], input->shape()[0], + lite_mat_rgb); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Creation of lite cv failed"); + + try { + TensorShape shape{output_height, output_width}; + int num_channels = input->shape()[2]; + if (input->Rank() == 3) shape = shape.AppendDim(num_channels); + + LiteMat lite_mat_resize; + ret = ResizeBilinear(lite_mat_rgb, lite_mat_resize, output_width, output_height); + CHECK_FAIL_RETURN_UNEXPECTED(ret, "Resize failed in lite cv"); + std::shared_ptr output_tensor; + RETURN_IF_NOT_OK( + Tensor::CreateFromMemory(shape, input->type(), static_cast(lite_mat_resize.data_ptr_), &output_tensor)); + *output = output_tensor; + } catch (std::runtime_error &e) { + RETURN_STATUS_UNEXPECTED("Error in image resize."); + } + return Status::OK(); +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h new file mode 100644 index 0000000000..53ce291220 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h @@ -0,0 +1,100 @@ +/** + * Copyright 2019 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. + */ +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ + +#include + +#include +#include +#include +#include +#if defined(_WIN32) || defined(_WIN64) +#undef HAVE_STDDEF_H +#undef HAVE_STDLIB_H +#endif +#include "./jpeglib.h" +#include "./jerror.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/tensor_op.h" +#include "minddata/dataset/kernels/image/lite_cv/image_process.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +void JpegErrorExitCustom(j_common_ptr cinfo); + +struct JpegErrorManagerCustom { + // "public" fields + struct jpeg_error_mgr pub; + // for return to caller + jmp_buf setjmp_buffer; +}; + +bool IsNonEmptyJPEG(const std::shared_ptr &input); + +void JpegSetSource(j_decompress_ptr c_info, const void *data, int64_t data_size); + +Status JpegCropAndDecode(const std::shared_ptr &input, std::shared_ptr *output, int x = 0, int y = 0, + int w = 0, int h = 0); + +/// \brief Returns cropped ROI of an image +/// \param input: Tensor of shape or and any OpenCv compatible type, see CVTensor. +/// \param x: starting horizontal position of ROI +/// \param y: starting vertical position of ROI +/// \param w: width of the ROI +/// \param h: height of the ROI +/// \param output: Cropped image Tensor of shape or and same input type. +Status Crop(const std::shared_ptr &input, std::shared_ptr *output, int x, int y, int w, int h); + +/// \brief Returns Decoded image +/// Supported images: +/// BMP JPEG JPG PNG TIFF +/// supported by opencv, if user need more image analysis capabilities, please compile opencv particularlly. +/// \param input: CVTensor containing the not decoded image 1D bytes +/// \param output: Decoded image Tensor of shape and type DE_UINT8. Pixel order is RGB +Status Decode(const std::shared_ptr &input, std::shared_ptr *output); + +/// \brief Get jpeg image width and height +/// \param input: CVTensor containing the not decoded image 1D bytes +/// \param img_width: the jpeg image width +/// \param img_height: the jpeg image height +Status GetJpegImageInfo(const std::shared_ptr &input, int *img_width, int *img_height); + +/// \brief Returns Normalized image +/// \param input: Tensor of shape in RGB order and any OpenCv compatible type, see CVTensor. +/// \param mean: Tensor of shape <3> and type DE_FLOAT32 which are mean of each channel in RGB order +/// \param std: Tensor of shape <3> and type DE_FLOAT32 which are std of each channel in RGB order +/// \param output: Normalized image Tensor of same input shape and type DE_FLOAT32 +Status Normalize(const std::shared_ptr &input, std::shared_ptr *output, + const std::shared_ptr &mean, const std::shared_ptr &std); + +/// \brief Returns Resized image. +/// \param input/output: Tensor of shape or and any OpenCv compatible type, see CVTensor. +/// \param output_height: height of output +/// \param output_width: width of output +/// \param fx: horizontal scale +/// \param fy: vertical scale +/// \param InterpolationMode: the interpolation mode +/// \param output: Resized image of shape or +/// and same type as input +Status Resize(const std::shared_ptr &input, std::shared_ptr *output, int32_t output_height, + int32_t output_width, double fx = 0.0, double fy = 0.0, + InterpolationMode mode = InterpolationMode::kLinear); + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc index 56593e33ca..7c98a9343f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc @@ -17,8 +17,11 @@ #include -#include "minddata/dataset/core/cv_tensor.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/status.h" namespace mindspore { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h index 4e4b760abd..0af8d28e18 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h @@ -19,7 +19,6 @@ #include #include -#include "minddata/dataset/core/cv_tensor.h" #include "minddata/dataset/core/tensor.h" #include "minddata/dataset/kernels/tensor_op.h" #include "minddata/dataset/util/status.h" diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc index 7456f50f32..3c11addd19 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc @@ -15,7 +15,11 @@ */ #include "minddata/dataset/kernels/image/resize_op.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/util/status.h" namespace mindspore { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h index 149cab6e85..336c23f6ff 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h @@ -21,7 +21,11 @@ #include #include "minddata/dataset/core/tensor.h" +#ifndef ENABLE_ANDROID #include "minddata/dataset/kernels/image/image_utils.h" +#else +#include "minddata/dataset/kernels/image/lite_image_utils.h" +#endif #include "minddata/dataset/kernels/tensor_op.h" #include "minddata/dataset/util/status.h" diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 4f7a9b2226..a272a5053d 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -193,10 +193,6 @@ endif () if (BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full") # add sentencepiece dependency # include(${TOP_DIR}/cmake/external_libs/sentencepiece.cmake) - # opencv - set(OpenCV_DIR ${TOP_DIR}/third_party/opencv/build) - find_package(OpenCV REQUIRED) - include_directories(${OpenCV_INCLUDE_DIRS}) # json if (NOT ENABLE_CONVERTER) include(${TOP_DIR}/cmake/external_libs/json.cmake) diff --git a/mindspore/lite/minddata/CMakeLists.txt b/mindspore/lite/minddata/CMakeLists.txt index a616811367..617de58b55 100644 --- a/mindspore/lite/minddata/CMakeLists.txt +++ b/mindspore/lite/minddata/CMakeLists.txt @@ -57,7 +57,7 @@ AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/ir/datasetops MINDDATA_ENGINE_IR_DAT AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/ir/datasetops/source MINDDATA_ENGINE_IR_DATASETOPS_SOURCE_SRC_FILES) AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt MINDDATA_ENGINE_OPT_SRC_FILES) -AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt/optional MINDDATA_ENGINE_OPT_OPTIONAL_SRC_FILES) +# AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt/optional MINDDATA_ENGINE_OPT_OPTIONAL_SRC_FILES) AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt/post MINDDATA_ENGINE_OPT_POST_SRC_FILES) AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt/pre MINDDATA_ENGINE_OPT_PRE_SRC_FILES) AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/engine/opt/util MINDDATA_ENGINE_OPT_UTIL_SRC_FILES) @@ -81,14 +81,16 @@ AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/kernels/image/lite_cv MINDDATA_KERNELS_IMA if (BUILD_MINDDATA STREQUAL "full") - list(REMOVE_ITEM MINDDATA_API_SRC_FILES - "${MINDDATA_DIR}/api/text.cc" - "${MINDDATA_DIR}/api/de_tensor.cc" - "${MINDDATA_DIR}/api/execute.cc" + list(REMOVE_ITEM MINDDATA_API_SRC_FILES + "${MINDDATA_DIR}/api/text.cc" ) - list(REMOVE_ITEM MINDDATA_CALLBACK_SRC_FILES - "${MINDDATA_DIR}/callback/py_ds_callback.cc" + list(REMOVE_ITEM MINDDATA_CALLBACK_SRC_FILES + "${MINDDATA_DIR}/callback/py_ds_callback.cc" + ) + + list(REMOVE_ITEM MINDDATA_CORE_SRC_FILES + "${MINDDATA_DIR}/core/cv_tensor.cc" ) list(REMOVE_ITEM MINDDATA_KERNELS_SRC_FILES "${MINDDATA_DIR}/kernels/py_func_op.cc") @@ -136,6 +138,51 @@ if (BUILD_MINDDATA STREQUAL "full") "${MINDDATA_DIR}/engine/ir/datasetops/source/tf_record_node.cc" "${MINDDATA_DIR}/engine/ir/datasetops/source/voc_node.cc" ) + list(REMOVE_ITEM MINDDATA_KERNELS_IMAGE_SRC_FILES + "${MINDDATA_DIR}/kernels/image/affine_op.cc" + "${MINDDATA_DIR}/kernels/image/auto_contrast_op.cc" + "${MINDDATA_DIR}/kernels/image/bounding_box_op.cc" + "${MINDDATA_DIR}/kernels/image/bounding_box_augment_op.cc" + "${MINDDATA_DIR}/kernels/image/center_crop_op.cc" + "${MINDDATA_DIR}/kernels/image/concatenate_op.cc" + "${MINDDATA_DIR}/kernels/image/cut_out_op.cc" + "${MINDDATA_DIR}/kernels/image/cutmix_batch_op.cc" + "${MINDDATA_DIR}/kernels/image/equalize_op.cc" + "${MINDDATA_DIR}/kernels/image/hwc_to_chw_op.cc" + "${MINDDATA_DIR}/kernels/image/image_utils.cc" + "${MINDDATA_DIR}/kernels/image/invert_op.cc" + "${MINDDATA_DIR}/kernels/image/math_utils.cc" + "${MINDDATA_DIR}/kernels/image/mixup_batch_op.cc" + "${MINDDATA_DIR}/kernels/image/pad_op.cc" + "${MINDDATA_DIR}/kernels/image/posterize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_affine_op.cc" + "${MINDDATA_DIR}/kernels/image/random_color_adjust_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_and_resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_decode_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_and_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_horizontal_flip_op.cc" + "${MINDDATA_DIR}/kernels/image/random_horizontal_flip_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_posterize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_rotation_op.cc" + "${MINDDATA_DIR}/kernels/image/random_select_subpolicy_op.cc" + "${MINDDATA_DIR}/kernels/image/random_solarize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_vertical_flip_op.cc" + "${MINDDATA_DIR}/kernels/image/random_vertical_flip_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_sharpness_op.cc" + "${MINDDATA_DIR}/kernels/image/rescale_op.cc" + "${MINDDATA_DIR}/kernels/image/rgba_to_bgr_op.cc" + "${MINDDATA_DIR}/kernels/image/rgba_to_rgb_op.cc" + "${MINDDATA_DIR}/kernels/image/sharpness_op.cc" + "${MINDDATA_DIR}/kernels/image/solarize_op.cc" + "${MINDDATA_DIR}/kernels/image/swap_red_blue_op.cc" + "${MINDDATA_DIR}/kernels/image/uniform_aug_op.cc" + "${MINDDATA_DIR}/kernels/image/resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_color_op.cc" + ) list(REMOVE_ITEM MINDDATA_ENGINE_IR_DATASETOPS_SRC_FILES "${MINDDATA_DIR}/engine/ir/datasetops/bucket_batch_by_length_node.cc" @@ -172,6 +219,7 @@ if (BUILD_MINDDATA STREQUAL "full") ${MINDDATA_ENGINE_OPT_UTIL_SRC_FILES} ${MINDDATA_ENGINE_PERF_SRC_FILES} ${MINDDATA_KERNELS_SRC_FILES} + ${MINDDATA_KERNELS_IMAGE_LITE_CV_FILES} ${MINDDATA_KERNELS_IMAGE_SRC_FILES} ${MINDDATA_KERNELS_DATA_SRC_FILES} ${MINDDATA_UTIL_SRC_FILES} @@ -184,9 +232,9 @@ if (BUILD_MINDDATA STREQUAL "full") securec jpeg-turbo jpeg - opencv_core - opencv_imgcodecs - opencv_imgproc + #opencv_core + #opencv_imgcodecs + #opencv_imgproc mindspore::json ) @@ -215,29 +263,77 @@ elseif (BUILD_MINDDATA STREQUAL "lite") ${MINDDATA_DIR}/api/de_tensor.cc ${MINDDATA_DIR}/api/execute.cc ) + list(REMOVE_ITEM MINDDATA_CORE_SRC_FILES + "${MINDDATA_DIR}/core/cv_tensor.cc" + ) - list(REMOVE_ITEM MINDDATA_KERNELS_IMAGE_SRC_FILES + list(REMOVE_ITEM MINDDATA_KERNELS_IMAGE_SRC_FILES + "${MINDDATA_DIR}/kernels/image/affine_op.cc" + "${MINDDATA_DIR}/kernels/image/auto_contrast_op.cc" + "${MINDDATA_DIR}/kernels/image/bounding_box_op.cc" "${MINDDATA_DIR}/kernels/image/bounding_box_augment_op.cc" + "${MINDDATA_DIR}/kernels/image/center_crop_op.cc" + "${MINDDATA_DIR}/kernels/image/concatenate_op.cc" "${MINDDATA_DIR}/kernels/image/cut_out_op.cc" - ) + "${MINDDATA_DIR}/kernels/image/cutmix_batch_op.cc" + "${MINDDATA_DIR}/kernels/image/equalize_op.cc" + "${MINDDATA_DIR}/kernels/image/hwc_to_chw_op.cc" + "${MINDDATA_DIR}/kernels/image/image_utils.cc" + "${MINDDATA_DIR}/kernels/image/invert_op.cc" + "${MINDDATA_DIR}/kernels/image/math_utils.cc" + "${MINDDATA_DIR}/kernels/image/mixup_batch_op.cc" + "${MINDDATA_DIR}/kernels/image/pad_op.cc" + "${MINDDATA_DIR}/kernels/image/posterize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_affine_op.cc" + "${MINDDATA_DIR}/kernels/image/random_color_adjust_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_and_resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_decode_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_and_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_op.cc" + "${MINDDATA_DIR}/kernels/image/random_crop_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_horizontal_flip_op.cc" + "${MINDDATA_DIR}/kernels/image/random_horizontal_flip_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_posterize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_resize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_rotation_op.cc" + "${MINDDATA_DIR}/kernels/image/random_select_subpolicy_op.cc" + "${MINDDATA_DIR}/kernels/image/random_solarize_op.cc" + "${MINDDATA_DIR}/kernels/image/random_vertical_flip_op.cc" + "${MINDDATA_DIR}/kernels/image/random_vertical_flip_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_sharpness_op.cc" + "${MINDDATA_DIR}/kernels/image/rescale_op.cc" + "${MINDDATA_DIR}/kernels/image/rgba_to_bgr_op.cc" + "${MINDDATA_DIR}/kernels/image/rgba_to_rgb_op.cc" + "${MINDDATA_DIR}/kernels/image/sharpness_op.cc" + "${MINDDATA_DIR}/kernels/image/solarize_op.cc" + "${MINDDATA_DIR}/kernels/image/swap_red_blue_op.cc" + "${MINDDATA_DIR}/kernels/image/uniform_aug_op.cc" + "${MINDDATA_DIR}/kernels/image/resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_resize_with_bbox_op.cc" + "${MINDDATA_DIR}/kernels/image/random_color_op.cc" + ) + add_library(minddata-lite SHARED ${MINDDATA_CORE_SRC_FILES} ${MINDDATA_KERNELS_SRC_FILES} + ${MINDDATA_KERNELS_IMAGE_LITE_CV_FILES} ${MINDDATA_KERNELS_IMAGE_SRC_FILES} ${MINDDATA_KERNELS_DATA_SRC_FILES} ${MINDDATA_DIR}/util/status.cc ${MINDDATA_DIR}/util/memory_pool.cc ${MINDDATA_DIR}/util/path.cc ${MINDDATA_DIR}/api/transforms.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../src/common/log_adapter.cc + ${CORE_DIR}/utils/ms_utils.cc ) target_link_libraries(minddata-lite securec jpeg-turbo jpeg - opencv_core - opencv_imgcodecs - opencv_imgproc + # opencv_core + # opencv_imgcodecs + # opencv_imgproc mindspore::json ) diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 4ca6fdea50..47884a090c 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -90,13 +90,19 @@ if (SUPPORT_GPU) endif() ### minddata lite if (BUILD_MINDDATA STREQUAL "lite") - include_directories(${CCSRC_DIR}/minddata) - set(DATASET_TEST_DIR ${TEST_DIR}/ut/src/dataset) - set(TEST_MINDDATA_SRC - ${DATASET_TEST_DIR}/de_tensor_test.cc - ${DATASET_TEST_DIR}/eager_test.cc - ) +# include_directories(${CCSRC_DIR}/minddata) +# set(DATASET_TEST_DIR ${TEST_DIR}/ut/src/dataset) +# set(TEST_MINDDATA_SRC +# ${DATASET_TEST_DIR}/de_tensor_test.cc +# ${DATASET_TEST_DIR}/eager_test.cc +# ) elseif (BUILD_MINDDATA STREQUAL "full") + #include_directories(${CCSRC_DIR}/minddata) + #set(DATASET_TEST_DIR ${TEST_DIR}/ut/src/dataset) + #set(TEST_MINDDATA_SRC + # ${DATASET_TEST_DIR}/de_tensor_test.cc + # ${DATASET_TEST_DIR}/eager_test.cc + # ) endif() ### runtime framework file(GLOB_RECURSE OPS_SRC ${LITE_DIR}/src/ops/*.cc ${LITE_DIR}/src/ops/populate/*.cc) @@ -278,12 +284,12 @@ if (PLATFORM_ARM) target_link_libraries(lite-test log) endif() -if (BUILD_MINDDATA STREQUAL "lite") - target_link_libraries(lite-test - minddata_eager_mid - minddata-lite - ) -endif() +#if (BUILD_MINDDATA STREQUAL "lite") +# target_link_libraries(lite-test + # minddata_eager_mid + #minddata-lite + # ) + #endif() if (ENABLE_CONVERTER) target_link_libraries(lite-test anf_importer_mid diff --git a/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc b/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc index 343331c682..a6cfa9a91a 100644 --- a/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc +++ b/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc @@ -15,12 +15,15 @@ */ #include #include +#include "./securec.h" #include "common/common_test.h" #include "gtest/gtest.h" -#include "./securec.h" -#include "dataset/core/tensor.h" -#include "dataset/core/cv_tensor.h" -#include "dataset/core/data_type.h" + +#include "mindspore/ccsrc/minddata/dataset/core/data_type.h" +#include "mindspore/ccsrc/minddata/dataset/core/tensor.h" +#include "mindspore/ccsrc/minddata/dataset/core/tensor_shape.h" +#include "mindspore/ccsrc/minddata/dataset/include/de_tensor.h" +#include "mindspore/lite/src/common/log_adapter.h" #include "mindspore/lite/src/tensor.h" using MSTensor = mindspore::tensor::MSTensor; diff --git a/mindspore/lite/test/ut/src/dataset/eager_test.cc b/mindspore/lite/test/ut/src/dataset/eager_test.cc index 04412678f2..612cfddc4d 100644 --- a/mindspore/lite/test/ut/src/dataset/eager_test.cc +++ b/mindspore/lite/test/ut/src/dataset/eager_test.cc @@ -23,6 +23,7 @@ #include "minddata/dataset/include/vision.h" #include "minddata/dataset/include/execute.h" #include "minddata/dataset/util/path.h" +#include "mindspore/lite/src/common/log_adapter.h" using MSTensor = mindspore::tensor::MSTensor; using DETensor = mindspore::tensor::DETensor; @@ -56,7 +57,7 @@ TEST_F(MindDataTestEager, Test1) { auto dir_it = Path::DirIterator::OpenDirectory(&base_dir); while (dir_it->hasNext()) { Path v = dir_it->next(); - MS_LOG(WARNING) << v.toString() << "."; + // MS_LOG(WARNING) << v.toString() << "."; std::shared_ptr image = std::shared_ptr(DETensor::CreateTensor(v.toString())); image = Execute(Decode())(image);