|
|
|
@@ -19,6 +19,7 @@ |
|
|
|
|
|
|
|
#include <map> |
|
|
|
#include <memory> |
|
|
|
#include <string> |
|
|
|
#include <utility> |
|
|
|
#include <vector> |
|
|
|
#include "minddata/dataset/core/constants.h" |
|
|
|
@@ -31,6 +32,48 @@ 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 kCutMixBatchOperation[] = "CutMixBatch"; |
|
|
|
constexpr char kCutOutOperation[] = "CutOut"; |
|
|
|
constexpr char kCropOperation[] = "Crop"; |
|
|
|
constexpr char kDecodeOperation[] = "Decode"; |
|
|
|
constexpr char kEqualizeOperation[] = "Equalize"; |
|
|
|
constexpr char kHwcToChwOperation[] = "HwcToChw"; |
|
|
|
constexpr char kInvertOperation[] = "Invert"; |
|
|
|
constexpr char kMixUpBatchOperation[] = "MixUpBatch"; |
|
|
|
constexpr char kNormalizeOperation[] = "Normalize"; |
|
|
|
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 kResizeOperation[] = "Resize"; |
|
|
|
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) |
|
|
|
#ifndef ENABLE_ANDROID |
|
|
|
class AutoContrastOperation; |
|
|
|
@@ -501,6 +544,8 @@ class AutoContrastOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kAutoContrastOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float cutoff_; |
|
|
|
std::vector<uint32_t> ignore_; |
|
|
|
@@ -516,6 +561,8 @@ class BoundingBoxAugmentOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kBoundingBoxAugmentOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::shared_ptr<TensorOperation> transform_; |
|
|
|
float ratio_; |
|
|
|
@@ -533,6 +580,8 @@ class CenterCropOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kCenterCropOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
}; |
|
|
|
@@ -547,6 +596,8 @@ class CropOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kCropOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> coordinates_; |
|
|
|
std::vector<int32_t> size_; |
|
|
|
@@ -562,6 +613,8 @@ class CutMixBatchOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kCutMixBatchOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float alpha_; |
|
|
|
float prob_; |
|
|
|
@@ -578,6 +631,8 @@ class CutOutOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kCutOutOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
int32_t length_; |
|
|
|
int32_t num_patches_; |
|
|
|
@@ -595,6 +650,8 @@ class DecodeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kDecodeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
bool rgb_; |
|
|
|
}; |
|
|
|
@@ -607,6 +664,8 @@ class EqualizeOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kEqualizeOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class HwcToChwOperation : public TensorOperation { |
|
|
|
@@ -616,6 +675,8 @@ class HwcToChwOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kHwcToChwOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class InvertOperation : public TensorOperation { |
|
|
|
@@ -625,6 +686,8 @@ class InvertOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kInvertOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class MixUpBatchOperation : public TensorOperation { |
|
|
|
@@ -637,6 +700,8 @@ class MixUpBatchOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kMixUpBatchOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float alpha_; |
|
|
|
}; |
|
|
|
@@ -652,6 +717,8 @@ class NormalizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kNormalizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<float> mean_; |
|
|
|
std::vector<float> std_; |
|
|
|
@@ -669,6 +736,8 @@ class PadOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kPadOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> padding_; |
|
|
|
std::vector<uint8_t> fill_value_; |
|
|
|
@@ -689,6 +758,8 @@ class RandomAffineOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomAffineOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<float_t> degrees_; // min_degree, max_degree |
|
|
|
std::vector<float_t> translate_range_; // maximum x translation percentage, maximum y translation percentage |
|
|
|
@@ -708,6 +779,8 @@ class RandomColorOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomColorOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float t_lb_; |
|
|
|
float t_ub_; |
|
|
|
@@ -724,6 +797,8 @@ class RandomColorAdjustOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomColorAdjustOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<float> brightness_; |
|
|
|
std::vector<float> contrast_; |
|
|
|
@@ -743,6 +818,8 @@ class RandomCropOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomCropOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<int32_t> padding_; |
|
|
|
@@ -762,6 +839,8 @@ class RandomCropDecodeResizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomCropDecodeResizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<float> scale_; |
|
|
|
@@ -782,6 +861,8 @@ class RandomCropWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomCropWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<int32_t> padding_; |
|
|
|
@@ -800,6 +881,8 @@ class RandomHorizontalFlipOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomHorizontalFlipOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float probability_; |
|
|
|
}; |
|
|
|
@@ -814,6 +897,8 @@ class RandomHorizontalFlipWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomHorizontalFlipWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float probability_; |
|
|
|
}; |
|
|
|
@@ -828,6 +913,8 @@ class RandomPosterizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomPosterizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<uint8_t> bit_range_; |
|
|
|
}; |
|
|
|
@@ -842,6 +929,8 @@ class RandomResizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomResizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
}; |
|
|
|
@@ -856,6 +945,8 @@ class RandomResizeWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomResizeWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
}; |
|
|
|
@@ -873,6 +964,8 @@ class RandomResizedCropOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomResizedCropOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<float> scale_; |
|
|
|
@@ -894,6 +987,8 @@ class RandomResizedCropWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomResizedCropWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<float> scale_; |
|
|
|
@@ -913,6 +1008,8 @@ class RandomRotationOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomRotationOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<float> degrees_; |
|
|
|
InterpolationMode interpolation_mode_; |
|
|
|
@@ -932,6 +1029,8 @@ class RandomSelectSubpolicyOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomSelectSubpolicyOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy_; |
|
|
|
}; |
|
|
|
@@ -946,6 +1045,8 @@ class RandomSharpnessOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomSharpnessOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<float> degrees_; |
|
|
|
}; |
|
|
|
@@ -960,6 +1061,8 @@ class RandomSolarizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomSolarizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<uint8_t> threshold_; |
|
|
|
}; |
|
|
|
@@ -974,6 +1077,8 @@ class RandomVerticalFlipOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomVerticalFlipOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float probability_; |
|
|
|
}; |
|
|
|
@@ -988,6 +1093,8 @@ class RandomVerticalFlipWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRandomVerticalFlipWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float probability_; |
|
|
|
}; |
|
|
|
@@ -1002,6 +1109,8 @@ class RescaleOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRescaleOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
float rescale_; |
|
|
|
float shift_; |
|
|
|
@@ -1019,6 +1128,8 @@ class ResizeOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kResizeOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
InterpolationMode interpolation_; |
|
|
|
@@ -1036,6 +1147,8 @@ class ResizeWithBBoxOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kResizeWithBBoxOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
InterpolationMode interpolation_; |
|
|
|
@@ -1050,6 +1163,8 @@ class RgbaToBgrOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRgbaToBgrOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class RgbaToRgbOperation : public TensorOperation { |
|
|
|
@@ -1061,6 +1176,8 @@ class RgbaToRgbOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kRgbaToRgbOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { |
|
|
|
@@ -1074,6 +1191,8 @@ class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kSoftDvppDecodeRandomCropResizeJpegOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
std::vector<float> scale_; |
|
|
|
@@ -1091,6 +1210,8 @@ class SoftDvppDecodeResizeJpegOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kSoftDvppDecodeResizeJpegOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<int32_t> size_; |
|
|
|
}; |
|
|
|
@@ -1104,6 +1225,8 @@ class SwapRedBlueOperation : public TensorOperation { |
|
|
|
std::shared_ptr<TensorOp> Build() override; |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kSwapRedBlueOperation; } |
|
|
|
}; |
|
|
|
|
|
|
|
class UniformAugOperation : public TensorOperation { |
|
|
|
@@ -1116,6 +1239,8 @@ class UniformAugOperation : public TensorOperation { |
|
|
|
|
|
|
|
Status ValidateParams() override; |
|
|
|
|
|
|
|
std::string Name() const override { return kUniformAugOperation; } |
|
|
|
|
|
|
|
private: |
|
|
|
std::vector<std::shared_ptr<TensorOperation>> transforms_; |
|
|
|
int32_t num_ops_; |
|
|
|
|