Browse Source

!7749 Remove open cv from minddata lite build.

Merge pull request !7749 from EricZ/remove_cv_crop
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
674f856bfa
37 changed files with 759 additions and 73 deletions
  1. +0
    -1
      build.sh
  2. +0
    -18
      cmake/package_lite.cmake
  3. +6
    -1
      mindspore/ccsrc/minddata/dataset/api/de_tensor.cc
  4. +5
    -0
      mindspore/ccsrc/minddata/dataset/api/execute.cc
  5. +0
    -1
      mindspore/ccsrc/minddata/dataset/api/transforms.cc
  6. +24
    -4
      mindspore/ccsrc/minddata/dataset/api/vision.cc
  7. +2
    -0
      mindspore/ccsrc/minddata/dataset/core/data_type.cc
  8. +25
    -1
      mindspore/ccsrc/minddata/dataset/core/data_type.h
  9. +4
    -0
      mindspore/ccsrc/minddata/dataset/core/global_context.cc
  10. +4
    -0
      mindspore/ccsrc/minddata/dataset/core/tensor.cc
  11. +2
    -0
      mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc
  12. +4
    -0
      mindspore/ccsrc/minddata/dataset/core/tensor_shape.h
  13. +4
    -0
      mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc
  14. +4
    -0
      mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc
  15. +4
    -0
      mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h
  16. +4
    -0
      mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h
  17. +3
    -2
      mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc
  18. +27
    -4
      mindspore/ccsrc/minddata/dataset/include/vision.h
  19. +2
    -0
      mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc
  20. +2
    -0
      mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h
  21. +4
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc
  22. +4
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h
  23. +4
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc
  24. +1
    -1
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc
  25. +1
    -1
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h
  26. +1
    -1
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc
  27. +368
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc
  28. +100
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h
  29. +4
    -1
      mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc
  30. +0
    -1
      mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h
  31. +4
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc
  32. +4
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h
  33. +0
    -4
      mindspore/lite/CMakeLists.txt
  34. +111
    -15
      mindspore/lite/minddata/CMakeLists.txt
  35. +18
    -12
      mindspore/lite/test/CMakeLists.txt
  36. +7
    -4
      mindspore/lite/test/ut/src/dataset/de_tensor_test.cc
  37. +2
    -1
      mindspore/lite/test/ut/src/dataset/eager_test.cc

+ 0
- 1
build.sh View File

@@ -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
}


+ 0
- 18
cmake/package_lite.cmake View File

@@ -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 ()



+ 6
- 1
mindspore/ccsrc/minddata/dataset/api/de_tensor.cc View File

@@ -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<int> &s
[](int s) -> dataset::dsize_t { return static_cast<dataset::dsize_t>(s); });

(void)dataset::Tensor::CreateFromMemory(dataset::TensorShape(t_shape), dataset::MSTypeToDEType(data_type),
static_cast<uchar *>(data), &t);
static_cast<uint8_t *>(data), &t);
return new DETensor(std::move(t));
}



+ 5
- 0
mindspore/ccsrc/minddata/dataset/api/execute.cc View File

@@ -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 {


+ 0
- 1
mindspore/ccsrc/minddata/dataset/api/transforms.cc View File

@@ -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"


+ 24
- 4
mindspore/ccsrc/minddata/dataset/api/vision.cc View File

@@ -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<CenterCropOperation> CenterCrop(std::vector<int32_t> size) {
}
return op;
}
#endif

// Function to create CropOperation.
std::shared_ptr<CropOperation> Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size) {
@@ -76,7 +88,7 @@ std::shared_ptr<CropOperation> Crop(std::vector<int32_t> coordinates, std::vecto
}
return op;
}
#ifndef ENABLE_ANDROID
// Function to create CutMixBatchOperation.
std::shared_ptr<CutMixBatchOperation> CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob) {
auto op = std::make_shared<CutMixBatchOperation>(image_batch_format, alpha, prob);
@@ -301,6 +313,7 @@ std::shared_ptr<RescaleOperation> Rescale(float rescale, float shift) {
return op;
}

#endif
// Function to create ResizeOperation.
std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> size, InterpolationMode interpolation) {
auto op = std::make_shared<ResizeOperation>(size, interpolation);
@@ -311,6 +324,7 @@ std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> size, Interpolation
return op;
}

#ifndef ENABLE_ANDROID
// Function to create RgbaToBgrOperation.
std::shared_ptr<RgbaToBgrOperation> RGBA2BGR() {
auto op = std::make_shared<RgbaToBgrOperation>();
@@ -352,6 +366,7 @@ std::shared_ptr<UniformAugOperation> UniformAugment(std::vector<std::shared_ptr<
return op;
}

#endif
/* ####################################### Validator Functions ############################################ */
Status ValidateVectorPositive(const std::string &dataset_name, const std::vector<int32_t> &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<int32_t> size) : size_(size) {}

@@ -410,6 +425,7 @@ std::shared_ptr<TensorOp> CenterCropOperation::Build() {
return tensor_op;
}

#endif
// CropOperation.
CropOperation::CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size)
: coordinates_(coordinates), size_(size) {}
@@ -467,6 +483,7 @@ std::shared_ptr<TensorOp> 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<TensorOp> RescaleOperation::Build() {
return tensor_op;
}

#endif
// ResizeOperation
ResizeOperation::ResizeOperation(std::vector<int32_t> size, InterpolationMode interpolation)
: size_(size), interpolation_(interpolation) {}
@@ -1397,6 +1415,7 @@ std::shared_ptr<TensorOp> ResizeOperation::Build() {
return std::make_shared<ResizeOp>(height, width, interpolation_);
}

#ifndef ENABLE_ANDROID
// RgbaToBgrOperation.
RgbaToBgrOperation::RgbaToBgrOperation() {}

@@ -1461,6 +1480,7 @@ std::shared_ptr<TensorOp> UniformAugOperation::Build() {
std::shared_ptr<UniformAugOp> tensor_op = std::make_shared<UniformAugOp>(tensor_ops, num_ops_);
return tensor_op;
}
#endif

} // namespace vision
} // namespace api


+ 2
- 0
mindspore/ccsrc/minddata/dataset/core/data_type.cc View File

@@ -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")


+ 25
- 1
mindspore/ccsrc/minddata/dataset/core/data_type.h View File

@@ -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 <opencv2/core/hal/interface.h>
#endif

#include <string>
#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


+ 4
- 0
mindspore/ccsrc/minddata/dataset/core/global_context.cc View File

@@ -19,7 +19,9 @@
#include <mutex>

#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<Allocator<Tensor>>(mem_pool_);
#ifndef ENABLE_ANDROID
cv_tensor_allocator_ = std::make_unique<Allocator<CVTensor>>(mem_pool_);
#endif
int_allocator_ = std::make_unique<IntAlloc>(mem_pool_);
return Status::OK();
}


+ 4
- 0
mindspore/ccsrc/minddata/dataset/core/tensor.cc View File

@@ -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


+ 2
- 0
mindspore/ccsrc/minddata/dataset/core/tensor_shape.cc View File

@@ -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({});


+ 4
- 0
mindspore/ccsrc/minddata/dataset/core/tensor_shape.h View File

@@ -22,7 +22,9 @@
#include <string>
#include <vector>

#ifndef ENABLE_ANDROID
#include <opencv2/core/mat.hpp>
#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(); }



+ 4
- 0
mindspore/ccsrc/minddata/dataset/engine/datasetops/source/album_op.cc View File

@@ -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 {


+ 4
- 0
mindspore/ccsrc/minddata/dataset/engine/datasetops/source/celeba_op.cc View File

@@ -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 {


+ 4
- 0
mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.h View File

@@ -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"


+ 4
- 0
mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h View File

@@ -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"


+ 3
- 2
mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc View File

@@ -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<std::unique_ptr<NodePass>> optimizations;
#ifndef ENABLE_ANDROID
optimizations.push_back(std::make_unique<TensorOpFusionPass>());
#endif
// vector of flags for each optimization
std::vector<bool> modified(optimizations.size(), false);
for (auto i = 0; i < optimizations.size(); i++) {


+ 27
- 4
mindspore/ccsrc/minddata/dataset/include/vision.h View File

@@ -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<CenterCropOperation> CenterCrop(std::vector<int32_t> 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<CropOperation> Crop(std::vector<int32_t> coordinates, std::vector<int32_t> 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<CutMixBatchOperation> CutMixBatch(ImageBatchFormat image_batch_f
/// \return Shared pointer to the current TensorOp
std::shared_ptr<CutOutOperation> 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<DecodeOperation> 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<HwcToChwOperation> HWC2CHW();
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<MixUpBatchOperation> 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<MixUpBatchOperation> MixUpBatch(float alpha = 1);
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<NormalizeOperation> Normalize(std::vector<float> mean, std::vector<float> 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<RandomVerticalFlipOperation> RandomVerticalFlip(float prob = 0.5
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<RescaleOperation> 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<RescaleOperation> Rescale(float rescale, float shift);
std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> 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<int32_t> size_;
};
#endif
class CropOperation : public TensorOperation {
public:
CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size);
@@ -350,7 +365,7 @@ class CropOperation : public TensorOperation {
std::vector<int32_t> coordinates_;
std::vector<int32_t> 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<float> mean, std::vector<float> std);
@@ -435,6 +453,7 @@ class NormalizeOperation : public TensorOperation {
std::vector<float> std_;
};

#ifndef ENABLE_ANDROID
class PadOperation : public TensorOperation {
public:
PadOperation(std::vector<int32_t> padding, std::vector<uint8_t> fill_value = {0},
@@ -672,6 +691,7 @@ class RescaleOperation : public TensorOperation {
float shift_;
};

#endif
class ResizeOperation : public TensorOperation {
public:
explicit ResizeOperation(std::vector<int32_t> 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<std::shared_ptr<TensorOperation>> transforms_;
int32_t num_ops_;
};
#endif

} // namespace vision
} // namespace api
} // namespace dataset


+ 2
- 0
mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc View File

@@ -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<Tensor> &input,
std::vector<std::shared_ptr<CVTensor>> *output) {
std::vector<int64_t> tensor_shape = input->shape().AsVector();
@@ -673,6 +674,7 @@ Status BatchTensorToCVTensorVector(const std::shared_ptr<Tensor> &input,
}
return Status::OK();
}
#endif

Status BatchTensorToTensorVector(const std::shared_ptr<Tensor> &input, std::vector<std::shared_ptr<Tensor>> *output) {
std::vector<int64_t> tensor_shape = input->shape().AsVector();


+ 2
- 0
mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h View File

@@ -21,7 +21,9 @@
#include <vector>
#include <unordered_map>
#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"


+ 4
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.cc View File

@@ -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 {


+ 4
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/crop_op.h View File

@@ -21,7 +21,11 @@
#include <string>

#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"



+ 4
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/decode_op.cc View File

@@ -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 {


+ 1
- 1
mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc View File

@@ -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 <string.h>
#include <cmath>


+ 1
- 1
mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h View File

@@ -22,7 +22,7 @@
#include <algorithm>
#include <iostream>

#include "lite_cv/lite_mat.h"
#include "minddata/dataset/kernels/image/lite_cv/lite_mat.h"

namespace mindspore {
namespace dataset {


+ 1
- 1
mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.cc View File

@@ -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 {


+ 368
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc View File

@@ -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 <algorithm>
#include <vector>
#include <stdexcept>
#include <utility>
#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<Tensor> &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<size_t>(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<struct jpeg_source_mgr *>(
(*cinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(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<void (*)(j_decompress_ptr, long)>(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<const JOCTET *>(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<JSAMPLE> scanline(scanline_size);
JSAMPLE *scanline_ptr = &scanline[0];
while (cinfo->output_scanline < static_cast<unsigned int>(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<Tensor> &input, std::shared_ptr<Tensor> *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<unsigned int>(crop_w + crop_x) > cinfo.output_width || crop_h == 0 ||
static_cast<unsigned int>(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<Tensor> 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<JSAMPLE *>(&(*output_tensor->begin<uint8_t>()));
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<Tensor> &input, std::shared_ptr<Tensor> *output) {
if (IsNonEmptyJPEG(input)) {
return JpegCropAndDecode(input, output);
} else {
RETURN_STATUS_UNEXPECTED("Decode only supports jpeg for android");
}
}

Status Crop(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output, int x, int y, int w, int h) {
if (input->Rank() != 3 && input->Rank() != 2) {
RETURN_STATUS_UNEXPECTED("Shape not <H,W,C> or <H,W>");
}
// 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<Tensor> output_tensor;
RETURN_IF_NOT_OK(
Tensor::CreateFromMemory(shape, input->type(), static_cast<uchar *>(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<Tensor> &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<Tensor> &input, std::shared_ptr<Tensor> *output,
const std::shared_ptr<Tensor> &mean, const std::shared_ptr<Tensor> &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<float> vec_mean;
std::vector<float> vec_std;
try {
for (uint8_t i = 0; i < 3; i++) {
float mean_c, std_c;
RETURN_IF_NOT_OK(mean->GetItemAt<float>(&mean_c, {i}));
RETURN_IF_NOT_OK(std->GetItemAt<float>(&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<Tensor> output_tensor;
RETURN_IF_NOT_OK(Tensor::CreateFromMemory(input->shape(), DataType(DataType::DE_FLOAT32),
static_cast<uchar *>(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<Tensor> &input, std::shared_ptr<Tensor> *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 <H,W,C>");
}
// 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<Tensor> output_tensor;
RETURN_IF_NOT_OK(
Tensor::CreateFromMemory(shape, input->type(), static_cast<uchar *>(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

+ 100
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h View File

@@ -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 <setjmp.h>

#include <memory>
#include <random>
#include <string>
#include <vector>
#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<Tensor> &input);

void JpegSetSource(j_decompress_ptr c_info, const void *data, int64_t data_size);

Status JpegCropAndDecode(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *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 <H,W,C> or <H,W> 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 <h,w,C> or <h,w> and same input type.
Status Crop(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *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 <H,W,C> and type DE_UINT8. Pixel order is RGB
Status Decode(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *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<Tensor> &input, int *img_width, int *img_height);

/// \brief Returns Normalized image
/// \param input: Tensor of shape <H,W,C> 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<Tensor> &input, std::shared_ptr<Tensor> *output,
const std::shared_ptr<Tensor> &mean, const std::shared_ptr<Tensor> &std);

/// \brief Returns Resized image.
/// \param input/output: Tensor of shape <H,W,C> or <H,W> 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 <outputHeight,outputWidth,C> or <outputHeight,outputWidth>
/// and same type as input
Status Resize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *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_

+ 4
- 1
mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.cc View File

@@ -17,8 +17,11 @@

#include <random>

#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 {


+ 0
- 1
mindspore/ccsrc/minddata/dataset/kernels/image/normalize_op.h View File

@@ -19,7 +19,6 @@
#include <memory>
#include <string>

#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"


+ 4
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.cc View File

@@ -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 {


+ 4
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/resize_op.h View File

@@ -21,7 +21,11 @@
#include <string>

#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"



+ 0
- 4
mindspore/lite/CMakeLists.txt View File

@@ -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)


+ 111
- 15
mindspore/lite/minddata/CMakeLists.txt View File

@@ -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
)



+ 18
- 12
mindspore/lite/test/CMakeLists.txt View File

@@ -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


+ 7
- 4
mindspore/lite/test/ut/src/dataset/de_tensor_test.cc View File

@@ -15,12 +15,15 @@
*/
#include <memory>
#include <string>
#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;


+ 2
- 1
mindspore/lite/test/ut/src/dataset/eager_test.cc View File

@@ -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<MSTensor> image = std::shared_ptr<MSTensor>(DETensor::CreateTensor(v.toString()));

image = Execute(Decode())(image);


Loading…
Cancel
Save