| @@ -97,6 +97,7 @@ add_dependencies(engine-ir-datasetops core) | |||
| add_dependencies(engine-ir-datasetops-source core) | |||
| add_dependencies(engine-ir-cache core) | |||
| add_dependencies(kernels-ir core) | |||
| add_dependencies(kernels-ir-vision core) | |||
| if(ENABLE_ACL) | |||
| add_dependencies(kernels-dvpp-image core dvpp-utils) | |||
| @@ -146,6 +147,7 @@ set(submodules | |||
| $<TARGET_OBJECTS:text> | |||
| $<TARGET_OBJECTS:text-kernels> | |||
| $<TARGET_OBJECTS:kernels-ir> | |||
| $<TARGET_OBJECTS:kernels-ir-vision> | |||
| ) | |||
| if(ENABLE_ACL) | |||
| @@ -17,10 +17,10 @@ | |||
| #include "minddata/dataset/api/python/pybind_register.h" | |||
| #include "minddata/dataset/core/global_context.h" | |||
| #include "minddata/dataset/include/vision.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| #include "minddata/dataset/kernels/py_func_op.h" | |||
| #include "minddata/dataset/kernels/ir/vision/vision_ir.h" | |||
| namespace mindspore { | |||
| namespace dataset { | |||
| @@ -20,8 +20,7 @@ | |||
| #include "minddata/dataset/api/python/pybind_conversion.h" | |||
| #include "minddata/dataset/api/python/pybind_register.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| #include "minddata/dataset/include/vision.h" | |||
| #include "minddata/dataset/include/vision_lite.h" | |||
| #include "minddata/dataset/kernels/ir/vision/vision_ir.h" | |||
| namespace mindspore { | |||
| namespace dataset { | |||
| @@ -18,13 +18,13 @@ | |||
| #include <string> | |||
| #include <vector> | |||
| #include "minddata/dataset/engine/ir/datasetops/map_node.h" | |||
| #include "minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.h" | |||
| #include "minddata/dataset/engine/ir/datasetops/map_node.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| #include "minddata/dataset/include/vision.h" | |||
| #include "minddata/dataset/include/vision_lite.h" | |||
| #include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" | |||
| #include "minddata/dataset/kernels/image/random_crop_decode_resize_op.h" | |||
| #include "minddata/dataset/kernels/ir/vision/vision_ir.h" | |||
| namespace mindspore { | |||
| namespace dataset { | |||
| @@ -34,45 +34,6 @@ namespace dataset { | |||
| // Transform operations for performing computer vision. | |||
| namespace vision { | |||
| // Char arrays storing name of corresponding classes (in alphabetical order) | |||
| constexpr char kAutoContrastOperation[] = "AutoContrast"; | |||
| constexpr char kBoundingBoxAugmentOperation[] = "BoundingBoxAugment"; | |||
| constexpr char kCutMixBatchOperation[] = "CutMixBatch"; | |||
| constexpr char kCutOutOperation[] = "CutOut"; | |||
| constexpr char kDvppDecodeResizeCropOperation[] = "DvppDecodeResizeCrop"; | |||
| constexpr char kEqualizeOperation[] = "Equalize"; | |||
| constexpr char kHwcToChwOperation[] = "HwcToChw"; | |||
| constexpr char kInvertOperation[] = "Invert"; | |||
| constexpr char kMixUpBatchOperation[] = "MixUpBatch"; | |||
| constexpr char kNormalizePadOperation[] = "NormalizePad"; | |||
| constexpr char kPadOperation[] = "Pad"; | |||
| constexpr char kRandomAffineOperation[] = "RandomAffine"; | |||
| constexpr char kRandomColorAdjustOperation[] = "RandomColorAdjust"; | |||
| constexpr char kRandomColorOperation[] = "RandomColor"; | |||
| constexpr char kRandomCropDecodeResizeOperation[] = "RandomCropDecodeResize"; | |||
| constexpr char kRandomCropOperation[] = "RandomCrop"; | |||
| constexpr char kRandomCropWithBBoxOperation[] = "RandomCropWithBBox"; | |||
| constexpr char kRandomHorizontalFlipWithBBoxOperation[] = "RandomHorizontalFlipWithBBox"; | |||
| constexpr char kRandomHorizontalFlipOperation[] = "RandomHorizontalFlip"; | |||
| constexpr char kRandomPosterizeOperation[] = "RandomPosterize"; | |||
| constexpr char kRandomResizedCropOperation[] = "RandomResizedCrop"; | |||
| constexpr char kRandomResizedCropWithBBoxOperation[] = "RandomResizedCropWithBBox"; | |||
| constexpr char kRandomResizeOperation[] = "RandomResize"; | |||
| constexpr char kRandomResizeWithBBoxOperation[] = "RandomResizeWithBBox"; | |||
| constexpr char kRandomRotationOperation[] = "RandomRotation"; | |||
| constexpr char kRandomSolarizeOperation[] = "RandomSolarize"; | |||
| constexpr char kRandomSharpnessOperation[] = "RandomSharpness"; | |||
| constexpr char kRandomVerticalFlipOperation[] = "RandomVerticalFlip"; | |||
| constexpr char kRandomVerticalFlipWithBBoxOperation[] = "RandomVerticalFlipWithBBox"; | |||
| constexpr char kRescaleOperation[] = "Rescale"; | |||
| constexpr char kResizeWithBBoxOperation[] = "ResizeWithBBox"; | |||
| constexpr char kRgbaToBgrOperation[] = "RgbaToBgr"; | |||
| constexpr char kRgbaToRgbOperation[] = "RgbaToRgb"; | |||
| constexpr char kSoftDvppDecodeRandomCropResizeJpegOperation[] = "SoftDvppDecodeRandomCropResizeJpeg"; | |||
| constexpr char kSoftDvppDecodeResizeJpegOperation[] = "SoftDvppDecodeResizeJpeg"; | |||
| constexpr char kSwapRedBlueOperation[] = "SwapRedBlue"; | |||
| constexpr char kUniformAugOperation[] = "UniformAug"; | |||
| // Transform Op classes (in alphabetical order) | |||
| class AutoContrastOperation; | |||
| class BoundingBoxAugmentOperation; | |||
| @@ -513,721 +474,6 @@ std::shared_ptr<SwapRedBlueOperation> SwapRedBlue(); | |||
| std::shared_ptr<UniformAugOperation> UniformAugment(std::vector<std::shared_ptr<TensorOperation>> transforms, | |||
| int32_t num_ops = 2); | |||
| /* ####################################### Derived TensorOperation classes ################################# */ | |||
| class AutoContrastOperation : public TensorOperation { | |||
| public: | |||
| explicit AutoContrastOperation(float cutoff = 0.0, std::vector<uint32_t> ignore = {}); | |||
| ~AutoContrastOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kAutoContrastOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float cutoff_; | |||
| std::vector<uint32_t> ignore_; | |||
| }; | |||
| class BoundingBoxAugmentOperation : public TensorOperation { | |||
| public: | |||
| explicit BoundingBoxAugmentOperation(std::shared_ptr<TensorOperation> transform, float ratio = 0.3); | |||
| ~BoundingBoxAugmentOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kBoundingBoxAugmentOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::shared_ptr<TensorOperation> transform_; | |||
| float ratio_; | |||
| }; | |||
| class CutMixBatchOperation : public TensorOperation { | |||
| public: | |||
| explicit CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha = 1.0, float prob = 1.0); | |||
| ~CutMixBatchOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCutMixBatchOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float alpha_; | |||
| float prob_; | |||
| ImageBatchFormat image_batch_format_; | |||
| }; | |||
| class CutOutOperation : public TensorOperation { | |||
| public: | |||
| explicit CutOutOperation(int32_t length, int32_t num_patches = 1); | |||
| ~CutOutOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCutOutOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| int32_t length_; | |||
| int32_t num_patches_; | |||
| }; | |||
| class DvppDecodeResizeCropOperation : public TensorOperation { | |||
| public: | |||
| explicit DvppDecodeResizeCropOperation(const std::vector<uint32_t> &crop, const std::vector<uint32_t> &resize); | |||
| ~DvppDecodeResizeCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kDvppDecodeResizeCropOperation; } | |||
| private: | |||
| std::vector<uint32_t> crop_; | |||
| std::vector<uint32_t> resize_; | |||
| }; | |||
| class EqualizeOperation : public TensorOperation { | |||
| public: | |||
| ~EqualizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kEqualizeOperation; } | |||
| }; | |||
| class HwcToChwOperation : public TensorOperation { | |||
| public: | |||
| ~HwcToChwOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kHwcToChwOperation; } | |||
| }; | |||
| class InvertOperation : public TensorOperation { | |||
| public: | |||
| ~InvertOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kInvertOperation; } | |||
| }; | |||
| class MixUpBatchOperation : public TensorOperation { | |||
| public: | |||
| explicit MixUpBatchOperation(float alpha = 1); | |||
| ~MixUpBatchOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kMixUpBatchOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float alpha_; | |||
| }; | |||
| class NormalizePadOperation : public TensorOperation { | |||
| public: | |||
| NormalizePadOperation(const std::vector<float> &mean, const std::vector<float> &std, | |||
| const std::string &dtype = "float32"); | |||
| ~NormalizePadOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kNormalizePadOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> mean_; | |||
| std::vector<float> std_; | |||
| std::string dtype_; | |||
| }; | |||
| class PadOperation : public TensorOperation { | |||
| public: | |||
| PadOperation(std::vector<int32_t> padding, std::vector<uint8_t> fill_value = {0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~PadOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kPadOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> padding_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomAffineOperation : public TensorOperation { | |||
| public: | |||
| RandomAffineOperation(const std::vector<float_t> °rees, const std::vector<float_t> &translate_range = {0.0, 0.0}, | |||
| const std::vector<float_t> &scale_range = {1.0, 1.0}, | |||
| const std::vector<float_t> &shear_ranges = {0.0, 0.0, 0.0, 0.0}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| const std::vector<uint8_t> &fill_value = {0, 0, 0}); | |||
| ~RandomAffineOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomAffineOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float_t> degrees_; // min_degree, max_degree | |||
| std::vector<float_t> translate_range_; // maximum x translation percentage, maximum y translation percentage | |||
| std::vector<float_t> scale_range_; // min_scale, max_scale | |||
| std::vector<float_t> shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear | |||
| InterpolationMode interpolation_; | |||
| std::vector<uint8_t> fill_value_; | |||
| }; | |||
| class RandomColorOperation : public TensorOperation { | |||
| public: | |||
| RandomColorOperation(float t_lb, float t_ub); | |||
| ~RandomColorOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomColorOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float t_lb_; | |||
| float t_ub_; | |||
| }; | |||
| class RandomColorAdjustOperation : public TensorOperation { | |||
| public: | |||
| RandomColorAdjustOperation(std::vector<float> brightness = {1.0, 1.0}, std::vector<float> contrast = {1.0, 1.0}, | |||
| std::vector<float> saturation = {1.0, 1.0}, std::vector<float> hue = {0.0, 0.0}); | |||
| ~RandomColorAdjustOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomColorAdjustOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> brightness_; | |||
| std::vector<float> contrast_; | |||
| std::vector<float> saturation_; | |||
| std::vector<float> hue_; | |||
| }; | |||
| class RandomCropOperation : public TensorOperation { | |||
| public: | |||
| RandomCropOperation(std::vector<int32_t> size, std::vector<int32_t> padding = {0, 0, 0, 0}, | |||
| bool pad_if_needed = false, std::vector<uint8_t> fill_value = {0, 0, 0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~RandomCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<int32_t> padding_; | |||
| bool pad_if_needed_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomResizedCropOperation : public TensorOperation { | |||
| public: | |||
| RandomResizedCropOperation(std::vector<int32_t> size, std::vector<float> scale = {0.08, 1.0}, | |||
| std::vector<float> ratio = {3. / 4., 4. / 3.}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| int32_t max_attempts = 10); | |||
| /// \brief default copy constructor | |||
| explicit RandomResizedCropOperation(const RandomResizedCropOperation &) = default; | |||
| ~RandomResizedCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizedCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| protected: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| InterpolationMode interpolation_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class RandomCropDecodeResizeOperation : public RandomResizedCropOperation { | |||
| public: | |||
| RandomCropDecodeResizeOperation(std::vector<int32_t> size, std::vector<float> scale, std::vector<float> ratio, | |||
| InterpolationMode interpolation, int32_t max_attempts); | |||
| explicit RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base); | |||
| ~RandomCropDecodeResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| std::string Name() const override { return kRandomCropDecodeResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| }; | |||
| class RandomCropWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| RandomCropWithBBoxOperation(std::vector<int32_t> size, std::vector<int32_t> padding = {0, 0, 0, 0}, | |||
| bool pad_if_needed = false, std::vector<uint8_t> fill_value = {0, 0, 0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~RandomCropWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomCropWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<int32_t> padding_; | |||
| bool pad_if_needed_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomHorizontalFlipOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomHorizontalFlipOperation(float probability = 0.5); | |||
| ~RandomHorizontalFlipOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomHorizontalFlipOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomHorizontalFlipWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomHorizontalFlipWithBBoxOperation(float probability = 0.5); | |||
| ~RandomHorizontalFlipWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomHorizontalFlipWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomPosterizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomPosterizeOperation(const std::vector<uint8_t> &bit_range = {4, 8}); | |||
| ~RandomPosterizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomPosterizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<uint8_t> bit_range_; | |||
| }; | |||
| class RandomResizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizeOperation(std::vector<int32_t> size); | |||
| ~RandomResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class RandomResizeWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizeWithBBoxOperation(std::vector<int32_t> size); | |||
| ~RandomResizeWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizeWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class RandomResizedCropWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizedCropWithBBoxOperation(std::vector<int32_t> size, std::vector<float> scale = {0.08, 1.0}, | |||
| std::vector<float> ratio = {3. / 4., 4. / 3.}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| int32_t max_attempts = 10); | |||
| ~RandomResizedCropWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizedCropWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| InterpolationMode interpolation_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class RandomRotationOperation : public TensorOperation { | |||
| public: | |||
| RandomRotationOperation(std::vector<float> degrees, InterpolationMode interpolation_mode, bool expand, | |||
| std::vector<float> center, std::vector<uint8_t> fill_value); | |||
| ~RandomRotationOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomRotationOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> degrees_; | |||
| InterpolationMode interpolation_mode_; | |||
| std::vector<float> center_; | |||
| bool expand_; | |||
| std::vector<uint8_t> fill_value_; | |||
| }; | |||
| class RandomSelectSubpolicyOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSelectSubpolicyOperation( | |||
| std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy); | |||
| ~RandomSelectSubpolicyOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSelectSubpolicyOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy_; | |||
| }; | |||
| class RandomSharpnessOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSharpnessOperation(std::vector<float> degrees = {0.1, 1.9}); | |||
| ~RandomSharpnessOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSharpnessOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> degrees_; | |||
| }; | |||
| class RandomSolarizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSolarizeOperation(std::vector<uint8_t> threshold); | |||
| ~RandomSolarizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSolarizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<uint8_t> threshold_; | |||
| }; | |||
| class RandomVerticalFlipOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomVerticalFlipOperation(float probability = 0.5); | |||
| ~RandomVerticalFlipOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomVerticalFlipOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomVerticalFlipWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomVerticalFlipWithBBoxOperation(float probability = 0.5); | |||
| ~RandomVerticalFlipWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomVerticalFlipWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RescaleOperation : public TensorOperation { | |||
| public: | |||
| explicit RescaleOperation(float rescale, float shift); | |||
| ~RescaleOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRescaleOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float rescale_; | |||
| float shift_; | |||
| }; | |||
| class ResizeWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit ResizeWithBBoxOperation(std::vector<int32_t> size, | |||
| InterpolationMode interpolation_mode = InterpolationMode::kLinear); | |||
| ~ResizeWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kResizeWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| InterpolationMode interpolation_; | |||
| }; | |||
| class RgbaToBgrOperation : public TensorOperation { | |||
| public: | |||
| RgbaToBgrOperation(); | |||
| ~RgbaToBgrOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRgbaToBgrOperation; } | |||
| }; | |||
| class RgbaToRgbOperation : public TensorOperation { | |||
| public: | |||
| RgbaToRgbOperation(); | |||
| ~RgbaToRgbOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRgbaToRgbOperation; } | |||
| }; | |||
| class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { | |||
| public: | |||
| explicit SoftDvppDecodeRandomCropResizeJpegOperation(std::vector<int32_t> size, std::vector<float> scale, | |||
| std::vector<float> ratio, int32_t max_attempts); | |||
| ~SoftDvppDecodeRandomCropResizeJpegOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSoftDvppDecodeRandomCropResizeJpegOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class SoftDvppDecodeResizeJpegOperation : public TensorOperation { | |||
| public: | |||
| explicit SoftDvppDecodeResizeJpegOperation(std::vector<int32_t> size); | |||
| ~SoftDvppDecodeResizeJpegOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSoftDvppDecodeResizeJpegOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class SwapRedBlueOperation : public TensorOperation { | |||
| public: | |||
| SwapRedBlueOperation(); | |||
| ~SwapRedBlueOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSwapRedBlueOperation; } | |||
| }; | |||
| class UniformAugOperation : public TensorOperation { | |||
| public: | |||
| explicit UniformAugOperation(std::vector<std::shared_ptr<TensorOperation>> transforms, int32_t num_ops = 2); | |||
| ~UniformAugOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kUniformAugOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<std::shared_ptr<TensorOperation>> transforms_; | |||
| int32_t num_ops_; | |||
| }; | |||
| } // namespace vision | |||
| } // namespace dataset | |||
| } // namespace mindspore | |||
| @@ -26,19 +26,15 @@ | |||
| #include "minddata/dataset/include/constants.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| // FIXME - This internal IR header will be removed when external API classes are provided | |||
| #include "minddata/dataset/kernels/ir/vision/vision_ir.h" | |||
| namespace mindspore { | |||
| namespace dataset { | |||
| // Transform operations for performing computer vision. | |||
| namespace vision { | |||
| // Char arrays storing name of corresponding classes (in alphabetical order) | |||
| constexpr char kCenterCropOperation[] = "CenterCrop"; | |||
| constexpr char kCropOperation[] = "Crop"; | |||
| constexpr char kDecodeOperation[] = "Decode"; | |||
| constexpr char kNormalizeOperation[] = "Normalize"; | |||
| constexpr char kResizeOperation[] = "Resize"; | |||
| constexpr char kRotateOperation[] = "Rotate"; | |||
| // Transform Op classes (in alphabetical order) | |||
| class CenterCropOperation; | |||
| class CropOperation; | |||
| @@ -88,119 +84,12 @@ std::shared_ptr<NormalizeOperation> Normalize(std::vector<float> mean, std::vect | |||
| /// \return Shared pointer to the current TensorOperation. | |||
| std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> size, | |||
| InterpolationMode interpolation = InterpolationMode::kLinear); | |||
| /// \brief Applies an rotate transformation to an image. | |||
| /// \notes Rotate the input image using a specified angle id. | |||
| /// \return Shared pointer to the current TensorOperation. | |||
| std::shared_ptr<RotateOperation> Rotate(); | |||
| class CenterCropOperation : public TensorOperation { | |||
| public: | |||
| explicit CenterCropOperation(std::vector<int32_t> size); | |||
| ~CenterCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCenterCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class CropOperation : public TensorOperation { | |||
| public: | |||
| CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size); | |||
| ~CropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCropOperation; } | |||
| private: | |||
| std::vector<int32_t> coordinates_; | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class DecodeOperation : public TensorOperation { | |||
| public: | |||
| explicit DecodeOperation(bool rgb = true); | |||
| ~DecodeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kDecodeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| bool rgb_; | |||
| }; | |||
| class NormalizeOperation : public TensorOperation { | |||
| public: | |||
| NormalizeOperation(std::vector<float> mean, std::vector<float> std); | |||
| ~NormalizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kNormalizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> mean_; | |||
| std::vector<float> std_; | |||
| }; | |||
| class ResizeOperation : public TensorOperation { | |||
| public: | |||
| explicit ResizeOperation(std::vector<int32_t> size, | |||
| InterpolationMode interpolation_mode = InterpolationMode::kLinear); | |||
| ~ResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| InterpolationMode interpolation_; | |||
| }; | |||
| class RotateOperation : public TensorOperation { | |||
| public: | |||
| RotateOperation(); | |||
| ~RotateOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRotateOperation; } | |||
| void setAngle(uint64_t angle_id); | |||
| private: | |||
| std::shared_ptr<TensorOp> rotate_op; | |||
| }; | |||
| } // namespace vision | |||
| } // namespace dataset | |||
| } // namespace mindspore | |||
| @@ -1,3 +1,4 @@ | |||
| add_subdirectory(vision) | |||
| file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") | |||
| set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) | |||
| @@ -5,4 +6,4 @@ set(DATASET_KERNELS_IR_SRC_FILES | |||
| validators.cc | |||
| ) | |||
| add_library(kernels-ir OBJECT ${DATASET_KERNELS_IR_SRC_FILES}) | |||
| add_library(kernels-ir OBJECT ${DATASET_KERNELS_IR_SRC_FILES}) | |||
| @@ -0,0 +1,8 @@ | |||
| file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") | |||
| set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) | |||
| set(DATASET_KERNELS_IR_VISION_SRC_FILES | |||
| vision_ir.cc | |||
| ) | |||
| add_library(kernels-ir-vision OBJECT ${DATASET_KERNELS_IR_VISION_SRC_FILES}) | |||
| @@ -0,0 +1,957 @@ | |||
| /** | |||
| * Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ | |||
| #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ | |||
| #include <map> | |||
| #include <memory> | |||
| #include <string> | |||
| #include <utility> | |||
| #include <vector> | |||
| #include "include/api/status.h" | |||
| #include "minddata/dataset/include/constants.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| #include "minddata/dataset/kernels/ir/tensor_operation.h" | |||
| namespace mindspore { | |||
| namespace dataset { | |||
| // Transform operations for performing computer vision. | |||
| namespace vision { | |||
| // Char arrays storing name of corresponding classes (in alphabetical order) | |||
| constexpr char kAutoContrastOperation[] = "AutoContrast"; | |||
| constexpr char kBoundingBoxAugmentOperation[] = "BoundingBoxAugment"; | |||
| constexpr char kCenterCropOperation[] = "CenterCrop"; | |||
| constexpr char kCropOperation[] = "Crop"; | |||
| constexpr char kCutMixBatchOperation[] = "CutMixBatch"; | |||
| constexpr char kCutOutOperation[] = "CutOut"; | |||
| constexpr char kDecodeOperation[] = "Decode"; | |||
| constexpr char kDvppDecodeResizeCropOperation[] = "DvppDecodeResizeCrop"; | |||
| constexpr char kEqualizeOperation[] = "Equalize"; | |||
| constexpr char kHwcToChwOperation[] = "HwcToChw"; | |||
| constexpr char kInvertOperation[] = "Invert"; | |||
| constexpr char kMixUpBatchOperation[] = "MixUpBatch"; | |||
| constexpr char kNormalizeOperation[] = "Normalize"; | |||
| constexpr char kNormalizePadOperation[] = "NormalizePad"; | |||
| constexpr char kPadOperation[] = "Pad"; | |||
| constexpr char kRandomAffineOperation[] = "RandomAffine"; | |||
| constexpr char kRandomColorAdjustOperation[] = "RandomColorAdjust"; | |||
| constexpr char kRandomColorOperation[] = "RandomColor"; | |||
| constexpr char kRandomCropDecodeResizeOperation[] = "RandomCropDecodeResize"; | |||
| constexpr char kRandomCropOperation[] = "RandomCrop"; | |||
| constexpr char kRandomCropWithBBoxOperation[] = "RandomCropWithBBox"; | |||
| constexpr char kRandomHorizontalFlipOperation[] = "RandomHorizontalFlip"; | |||
| constexpr char kRandomHorizontalFlipWithBBoxOperation[] = "RandomHorizontalFlipWithBBox"; | |||
| constexpr char kRandomPosterizeOperation[] = "RandomPosterize"; | |||
| constexpr char kRandomResizedCropOperation[] = "RandomResizedCrop"; | |||
| constexpr char kRandomResizedCropWithBBoxOperation[] = "RandomResizedCropWithBBox"; | |||
| constexpr char kRandomResizeOperation[] = "RandomResize"; | |||
| constexpr char kRandomResizeWithBBoxOperation[] = "RandomResizeWithBBox"; | |||
| constexpr char kRandomRotationOperation[] = "RandomRotation"; | |||
| constexpr char kRandomSelectSubpolicyOperation[] = "RandomSelectSubpolicy"; | |||
| constexpr char kRandomSharpnessOperation[] = "RandomSharpness"; | |||
| constexpr char kRandomSolarizeOperation[] = "RandomSolarize"; | |||
| constexpr char kRandomVerticalFlipOperation[] = "RandomVerticalFlip"; | |||
| constexpr char kRandomVerticalFlipWithBBoxOperation[] = "RandomVerticalFlipWithBBox"; | |||
| constexpr char kRescaleOperation[] = "Rescale"; | |||
| constexpr char kResizeOperation[] = "Resize"; | |||
| constexpr char kResizeWithBBoxOperation[] = "ResizeWithBBox"; | |||
| constexpr char kRgbaToBgrOperation[] = "RgbaToBgr"; | |||
| constexpr char kRgbaToRgbOperation[] = "RgbaToRgb"; | |||
| constexpr char kRotateOperation[] = "Rotate"; | |||
| constexpr char kSoftDvppDecodeRandomCropResizeJpegOperation[] = "SoftDvppDecodeRandomCropResizeJpeg"; | |||
| constexpr char kSoftDvppDecodeResizeJpegOperation[] = "SoftDvppDecodeResizeJpeg"; | |||
| constexpr char kSwapRedBlueOperation[] = "SwapRedBlue"; | |||
| constexpr char kUniformAugOperation[] = "UniformAug"; | |||
| // Transform Op classes (in alphabetical order) | |||
| class AutoContrastOperation; | |||
| class BoundingBoxAugmentOperation; | |||
| class CenterCropOperation; | |||
| class CropOperation; | |||
| class CutMixBatchOperation; | |||
| class CutOutOperation; | |||
| class DecodeOperation; | |||
| class DvppDecodeResizeCropOperation; | |||
| class EqualizeOperation; | |||
| class HwcToChwOperation; | |||
| class InvertOperation; | |||
| class MixUpBatchOperation; | |||
| class NormalizeOperation; | |||
| class NormalizePadOperation; | |||
| class PadOperation; | |||
| class RandomAffineOperation; | |||
| class RandomColorAdjustOperation; | |||
| class RandomColorOperation; | |||
| class RandomCropDecodeResizeOperation; | |||
| class RandomCropOperation; | |||
| class RandomCropWithBBoxOperation; | |||
| class RandomHorizontalFlipOperation; | |||
| class RandomHorizontalFlipWithBBoxOperation; | |||
| class RandomPosterizeOperation; | |||
| class RandomResizedCropOperation; | |||
| class RandomResizedCropWithBBoxOperation; | |||
| class RandomResizeOperation; | |||
| class RandomResizeWithBBoxOperation; | |||
| class RandomRotationOperation; | |||
| class RandomSelectSubpolicyOperation; | |||
| class RandomSharpnessOperation; | |||
| class RandomSolarizeOperation; | |||
| class RandomVerticalFlipOperation; | |||
| class RandomVerticalFlipWithBBoxOperation; | |||
| class RescaleOperation; | |||
| class ResizeOperation; | |||
| class ResizeWithBBoxOperation; | |||
| class RgbaToBgrOperation; | |||
| class RgbaToRgbOperation; | |||
| class RotateOperation; | |||
| class SoftDvppDecodeRandomCropResizeJpegOperation; | |||
| class SoftDvppDecodeResizeJpegOperation; | |||
| class SwapRedBlueOperation; | |||
| class UniformAugOperation; | |||
| /* ####################################### Derived TensorOperation classes ################################# */ | |||
| class AutoContrastOperation : public TensorOperation { | |||
| public: | |||
| explicit AutoContrastOperation(float cutoff = 0.0, std::vector<uint32_t> ignore = {}); | |||
| ~AutoContrastOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kAutoContrastOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float cutoff_; | |||
| std::vector<uint32_t> ignore_; | |||
| }; | |||
| class BoundingBoxAugmentOperation : public TensorOperation { | |||
| public: | |||
| explicit BoundingBoxAugmentOperation(std::shared_ptr<TensorOperation> transform, float ratio = 0.3); | |||
| ~BoundingBoxAugmentOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kBoundingBoxAugmentOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::shared_ptr<TensorOperation> transform_; | |||
| float ratio_; | |||
| }; | |||
| class CenterCropOperation : public TensorOperation { | |||
| public: | |||
| explicit CenterCropOperation(std::vector<int32_t> size); | |||
| ~CenterCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCenterCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class CropOperation : public TensorOperation { | |||
| public: | |||
| CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size); | |||
| ~CropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCropOperation; } | |||
| private: | |||
| std::vector<int32_t> coordinates_; | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class CutMixBatchOperation : public TensorOperation { | |||
| public: | |||
| explicit CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha = 1.0, float prob = 1.0); | |||
| ~CutMixBatchOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCutMixBatchOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float alpha_; | |||
| float prob_; | |||
| ImageBatchFormat image_batch_format_; | |||
| }; | |||
| class CutOutOperation : public TensorOperation { | |||
| public: | |||
| explicit CutOutOperation(int32_t length, int32_t num_patches = 1); | |||
| ~CutOutOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kCutOutOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| int32_t length_; | |||
| int32_t num_patches_; | |||
| }; | |||
| class DecodeOperation : public TensorOperation { | |||
| public: | |||
| explicit DecodeOperation(bool rgb = true); | |||
| ~DecodeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kDecodeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| bool rgb_; | |||
| }; | |||
| class DvppDecodeResizeCropOperation : public TensorOperation { | |||
| public: | |||
| explicit DvppDecodeResizeCropOperation(const std::vector<uint32_t> &crop, const std::vector<uint32_t> &resize); | |||
| ~DvppDecodeResizeCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kDvppDecodeResizeCropOperation; } | |||
| private: | |||
| std::vector<uint32_t> crop_; | |||
| std::vector<uint32_t> resize_; | |||
| }; | |||
| class EqualizeOperation : public TensorOperation { | |||
| public: | |||
| ~EqualizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kEqualizeOperation; } | |||
| }; | |||
| class HwcToChwOperation : public TensorOperation { | |||
| public: | |||
| ~HwcToChwOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kHwcToChwOperation; } | |||
| }; | |||
| class InvertOperation : public TensorOperation { | |||
| public: | |||
| ~InvertOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kInvertOperation; } | |||
| }; | |||
| class MixUpBatchOperation : public TensorOperation { | |||
| public: | |||
| explicit MixUpBatchOperation(float alpha = 1); | |||
| ~MixUpBatchOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kMixUpBatchOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float alpha_; | |||
| }; | |||
| class NormalizeOperation : public TensorOperation { | |||
| public: | |||
| NormalizeOperation(std::vector<float> mean, std::vector<float> std); | |||
| ~NormalizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kNormalizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> mean_; | |||
| std::vector<float> std_; | |||
| }; | |||
| class NormalizePadOperation : public TensorOperation { | |||
| public: | |||
| NormalizePadOperation(const std::vector<float> &mean, const std::vector<float> &std, | |||
| const std::string &dtype = "float32"); | |||
| ~NormalizePadOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kNormalizePadOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> mean_; | |||
| std::vector<float> std_; | |||
| std::string dtype_; | |||
| }; | |||
| class PadOperation : public TensorOperation { | |||
| public: | |||
| PadOperation(std::vector<int32_t> padding, std::vector<uint8_t> fill_value = {0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~PadOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kPadOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> padding_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomAffineOperation : public TensorOperation { | |||
| public: | |||
| RandomAffineOperation(const std::vector<float_t> °rees, const std::vector<float_t> &translate_range = {0.0, 0.0}, | |||
| const std::vector<float_t> &scale_range = {1.0, 1.0}, | |||
| const std::vector<float_t> &shear_ranges = {0.0, 0.0, 0.0, 0.0}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| const std::vector<uint8_t> &fill_value = {0, 0, 0}); | |||
| ~RandomAffineOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomAffineOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float_t> degrees_; // min_degree, max_degree | |||
| std::vector<float_t> translate_range_; // maximum x translation percentage, maximum y translation percentage | |||
| std::vector<float_t> scale_range_; // min_scale, max_scale | |||
| std::vector<float_t> shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear | |||
| InterpolationMode interpolation_; | |||
| std::vector<uint8_t> fill_value_; | |||
| }; | |||
| class RandomColorOperation : public TensorOperation { | |||
| public: | |||
| RandomColorOperation(float t_lb, float t_ub); | |||
| ~RandomColorOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomColorOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float t_lb_; | |||
| float t_ub_; | |||
| }; | |||
| class RandomColorAdjustOperation : public TensorOperation { | |||
| public: | |||
| RandomColorAdjustOperation(std::vector<float> brightness = {1.0, 1.0}, std::vector<float> contrast = {1.0, 1.0}, | |||
| std::vector<float> saturation = {1.0, 1.0}, std::vector<float> hue = {0.0, 0.0}); | |||
| ~RandomColorAdjustOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomColorAdjustOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> brightness_; | |||
| std::vector<float> contrast_; | |||
| std::vector<float> saturation_; | |||
| std::vector<float> hue_; | |||
| }; | |||
| class RandomCropOperation : public TensorOperation { | |||
| public: | |||
| RandomCropOperation(std::vector<int32_t> size, std::vector<int32_t> padding = {0, 0, 0, 0}, | |||
| bool pad_if_needed = false, std::vector<uint8_t> fill_value = {0, 0, 0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~RandomCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<int32_t> padding_; | |||
| bool pad_if_needed_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomResizedCropOperation : public TensorOperation { | |||
| public: | |||
| RandomResizedCropOperation(std::vector<int32_t> size, std::vector<float> scale = {0.08, 1.0}, | |||
| std::vector<float> ratio = {3. / 4., 4. / 3.}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| int32_t max_attempts = 10); | |||
| /// \brief default copy constructor | |||
| explicit RandomResizedCropOperation(const RandomResizedCropOperation &) = default; | |||
| ~RandomResizedCropOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizedCropOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| protected: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| InterpolationMode interpolation_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class RandomCropDecodeResizeOperation : public RandomResizedCropOperation { | |||
| public: | |||
| RandomCropDecodeResizeOperation(std::vector<int32_t> size, std::vector<float> scale, std::vector<float> ratio, | |||
| InterpolationMode interpolation, int32_t max_attempts); | |||
| explicit RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base); | |||
| ~RandomCropDecodeResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| std::string Name() const override { return kRandomCropDecodeResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| }; | |||
| class RandomCropWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| RandomCropWithBBoxOperation(std::vector<int32_t> size, std::vector<int32_t> padding = {0, 0, 0, 0}, | |||
| bool pad_if_needed = false, std::vector<uint8_t> fill_value = {0, 0, 0}, | |||
| BorderType padding_mode = BorderType::kConstant); | |||
| ~RandomCropWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomCropWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<int32_t> padding_; | |||
| bool pad_if_needed_; | |||
| std::vector<uint8_t> fill_value_; | |||
| BorderType padding_mode_; | |||
| }; | |||
| class RandomHorizontalFlipOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomHorizontalFlipOperation(float probability = 0.5); | |||
| ~RandomHorizontalFlipOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomHorizontalFlipOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomHorizontalFlipWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomHorizontalFlipWithBBoxOperation(float probability = 0.5); | |||
| ~RandomHorizontalFlipWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomHorizontalFlipWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomPosterizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomPosterizeOperation(const std::vector<uint8_t> &bit_range = {4, 8}); | |||
| ~RandomPosterizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomPosterizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<uint8_t> bit_range_; | |||
| }; | |||
| class RandomResizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizeOperation(std::vector<int32_t> size); | |||
| ~RandomResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class RandomResizeWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizeWithBBoxOperation(std::vector<int32_t> size); | |||
| ~RandomResizeWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizeWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class RandomResizedCropWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomResizedCropWithBBoxOperation(std::vector<int32_t> size, std::vector<float> scale = {0.08, 1.0}, | |||
| std::vector<float> ratio = {3. / 4., 4. / 3.}, | |||
| InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, | |||
| int32_t max_attempts = 10); | |||
| ~RandomResizedCropWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomResizedCropWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| InterpolationMode interpolation_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class RandomRotationOperation : public TensorOperation { | |||
| public: | |||
| RandomRotationOperation(std::vector<float> degrees, InterpolationMode interpolation_mode, bool expand, | |||
| std::vector<float> center, std::vector<uint8_t> fill_value); | |||
| ~RandomRotationOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomRotationOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> degrees_; | |||
| InterpolationMode interpolation_mode_; | |||
| std::vector<float> center_; | |||
| bool expand_; | |||
| std::vector<uint8_t> fill_value_; | |||
| }; | |||
| class RandomSelectSubpolicyOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSelectSubpolicyOperation( | |||
| std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy); | |||
| ~RandomSelectSubpolicyOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSelectSubpolicyOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy_; | |||
| }; | |||
| class RandomSharpnessOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSharpnessOperation(std::vector<float> degrees = {0.1, 1.9}); | |||
| ~RandomSharpnessOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSharpnessOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<float> degrees_; | |||
| }; | |||
| class RandomSolarizeOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomSolarizeOperation(std::vector<uint8_t> threshold); | |||
| ~RandomSolarizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomSolarizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<uint8_t> threshold_; | |||
| }; | |||
| class RandomVerticalFlipOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomVerticalFlipOperation(float probability = 0.5); | |||
| ~RandomVerticalFlipOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomVerticalFlipOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RandomVerticalFlipWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit RandomVerticalFlipWithBBoxOperation(float probability = 0.5); | |||
| ~RandomVerticalFlipWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRandomVerticalFlipWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float probability_; | |||
| }; | |||
| class RescaleOperation : public TensorOperation { | |||
| public: | |||
| explicit RescaleOperation(float rescale, float shift); | |||
| ~RescaleOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRescaleOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| float rescale_; | |||
| float shift_; | |||
| }; | |||
| class ResizeOperation : public TensorOperation { | |||
| public: | |||
| explicit ResizeOperation(std::vector<int32_t> size, | |||
| InterpolationMode interpolation_mode = InterpolationMode::kLinear); | |||
| ~ResizeOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kResizeOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| InterpolationMode interpolation_; | |||
| }; | |||
| class ResizeWithBBoxOperation : public TensorOperation { | |||
| public: | |||
| explicit ResizeWithBBoxOperation(std::vector<int32_t> size, | |||
| InterpolationMode interpolation_mode = InterpolationMode::kLinear); | |||
| ~ResizeWithBBoxOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kResizeWithBBoxOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| InterpolationMode interpolation_; | |||
| }; | |||
| class RgbaToBgrOperation : public TensorOperation { | |||
| public: | |||
| RgbaToBgrOperation(); | |||
| ~RgbaToBgrOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRgbaToBgrOperation; } | |||
| }; | |||
| class RgbaToRgbOperation : public TensorOperation { | |||
| public: | |||
| RgbaToRgbOperation(); | |||
| ~RgbaToRgbOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRgbaToRgbOperation; } | |||
| }; | |||
| class RotateOperation : public TensorOperation { | |||
| public: | |||
| RotateOperation(); | |||
| ~RotateOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kRotateOperation; } | |||
| void setAngle(uint64_t angle_id); | |||
| private: | |||
| std::shared_ptr<TensorOp> rotate_op; | |||
| }; | |||
| class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { | |||
| public: | |||
| explicit SoftDvppDecodeRandomCropResizeJpegOperation(std::vector<int32_t> size, std::vector<float> scale, | |||
| std::vector<float> ratio, int32_t max_attempts); | |||
| ~SoftDvppDecodeRandomCropResizeJpegOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSoftDvppDecodeRandomCropResizeJpegOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| std::vector<float> scale_; | |||
| std::vector<float> ratio_; | |||
| int32_t max_attempts_; | |||
| }; | |||
| class SoftDvppDecodeResizeJpegOperation : public TensorOperation { | |||
| public: | |||
| explicit SoftDvppDecodeResizeJpegOperation(std::vector<int32_t> size); | |||
| ~SoftDvppDecodeResizeJpegOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSoftDvppDecodeResizeJpegOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<int32_t> size_; | |||
| }; | |||
| class SwapRedBlueOperation : public TensorOperation { | |||
| public: | |||
| SwapRedBlueOperation(); | |||
| ~SwapRedBlueOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kSwapRedBlueOperation; } | |||
| }; | |||
| class UniformAugOperation : public TensorOperation { | |||
| public: | |||
| explicit UniformAugOperation(std::vector<std::shared_ptr<TensorOperation>> transforms, int32_t num_ops = 2); | |||
| ~UniformAugOperation() = default; | |||
| std::shared_ptr<TensorOp> Build() override; | |||
| Status ValidateParams() override; | |||
| std::string Name() const override { return kUniformAugOperation; } | |||
| Status to_json(nlohmann::json *out_json) override; | |||
| private: | |||
| std::vector<std::shared_ptr<TensorOperation>> transforms_; | |||
| int32_t num_ops_; | |||
| }; | |||
| } // namespace vision | |||
| } // namespace dataset | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ | |||
| @@ -202,6 +202,7 @@ if(BUILD_MINDDATA STREQUAL "full") | |||
| ${MINDDATA_DIR}/kernels/data/type_cast_op.cc | |||
| ${MINDDATA_DIR}/kernels/image/exif_utils.cc | |||
| ${MINDDATA_DIR}/kernels/ir/validators.cc | |||
| ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc | |||
| ${MINDDATA_DIR}/callback/callback_manager.cc | |||
| ${MINDDATA_DIR}/util/task_manager.cc | |||
| ${MINDDATA_DIR}/util/services.cc | |||
| @@ -279,6 +280,8 @@ elseif(BUILD_MINDDATA STREQUAL "wrapper") | |||
| ${MINDDATA_DIR}/kernels/data/type_cast_op.cc | |||
| ${MINDDATA_DIR}/kernels/data/data_utils.cc | |||
| ${MINDDATA_DIR}/kernels/image/exif_utils.cc | |||
| ${MINDDATA_DIR}/kernels/ir/validators.cc | |||
| ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MDToDApi.cc | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/album_op_android.cc | |||
| ) | |||
| @@ -296,7 +299,6 @@ elseif(BUILD_MINDDATA STREQUAL "wrapper") | |||
| ${CORE_DIR}/utils/ms_utils.cc | |||
| ${MINDDATA_TODAPI_SRC} | |||
| ${MINDSPORE_LITE_CXXAPI_SRC} | |||
| ${MINDDATA_DIR}/kernels/ir/validators.cc | |||
| ) | |||
| find_package(Threads REQUIRED) | |||
| @@ -391,6 +393,7 @@ elseif(BUILD_MINDDATA STREQUAL "lite") | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/../src/common/log_adapter.cc | |||
| ${CORE_DIR}/utils/ms_utils.cc | |||
| ${MINDDATA_DIR}/kernels/ir/validators.cc | |||
| ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc | |||
| ) | |||
| target_link_libraries(minddata-lite | |||