!3850 Implementing RandomAffine C Op and a CPP UT for AutoContrast & Equalize
Merge pull request !3850 from islam_amin/randomaffine_oppull/3850/MERGE
commit
2cab58fdbc
@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 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 <algorithm>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "minddata/dataset/kernels/image/affine_op.h"
|
||||
#include "minddata/dataset/kernels/image/image_utils.h"
|
||||
#include "minddata/dataset/kernels/image/math_utils.h"
|
||||
#include "minddata/dataset/util/random.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
||||
const InterpolationMode AffineOp::kDefInterpolation = InterpolationMode::kNearestNeighbour;
|
||||
const float_t AffineOp::kDegrees = 0.0;
|
||||
const std::vector<float_t> AffineOp::kTranslation = {0.0, 0.0};
|
||||
const float_t AffineOp::kScale = 1.0;
|
||||
const std::vector<float_t> AffineOp::kShear = {0.0, 0.0};
|
||||
const std::vector<uint8_t> AffineOp::kFillValue = {0, 0, 0};
|
||||
|
||||
AffineOp::AffineOp(float_t degrees, const std::vector<float_t> &translation, float_t scale,
|
||||
const std::vector<float_t> &shear, InterpolationMode interpolation,
|
||||
const std::vector<uint8_t> &fill_value)
|
||||
: degrees_(degrees),
|
||||
translation_(translation),
|
||||
scale_(scale),
|
||||
shear_(shear),
|
||||
interpolation_(interpolation),
|
||||
fill_value_(fill_value) {}
|
||||
|
||||
Status AffineOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
|
||||
IO_CHECK(input, output);
|
||||
float_t translation_x = translation_[0];
|
||||
float_t translation_y = translation_[1];
|
||||
float_t degrees = 0.0;
|
||||
DegreesToRadians(degrees_, °rees);
|
||||
float_t shear_x = shear_[0];
|
||||
float_t shear_y = shear_[1];
|
||||
DegreesToRadians(shear_x, &shear_x);
|
||||
DegreesToRadians(-1 * shear_y, &shear_y);
|
||||
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(input);
|
||||
|
||||
// Apply Affine Transformation
|
||||
// T is translation matrix: [1, 0, tx | 0, 1, ty | 0, 0, 1]
|
||||
// C is translation matrix to keep center: [1, 0, cx | 0, 1, cy | 0, 0, 1]
|
||||
// RSS is rotation with scale and shear matrix
|
||||
// RSS(a, s, (sx, sy)) =
|
||||
// = R(a) * S(s) * SHy(sy) * SHx(sx)
|
||||
// = [ s*cos(a - sy)/cos(sy), s*(-cos(a - sy)*tan(x)/cos(y) - sin(a)), 0 ]
|
||||
// [ s*sin(a - sy)/cos(sy), s*(-sin(a - sy)*tan(x)/cos(y) + cos(a)), 0 ]
|
||||
// [ 0 , 0 , 1 ]
|
||||
//
|
||||
// where R is a rotation matrix, S is a scaling matrix, and SHx and SHy are the shears:
|
||||
// SHx(s) = [1, -tan(s)] and SHy(s) = [1 , 0]
|
||||
// [0, 1 ] [-tan(s), 1]
|
||||
//
|
||||
// Thus, the affine matrix is M = T * C * RSS * C^-1
|
||||
|
||||
float_t cx = ((input_cv->mat().cols - 1) / 2.0);
|
||||
float_t cy = ((input_cv->mat().rows - 1) / 2.0);
|
||||
// Calculate RSS
|
||||
std::vector<float_t> matrix{scale_ * cos(degrees + shear_y) / cos(shear_y),
|
||||
scale_ * (-1 * cos(degrees + shear_y) * tan(shear_x) / cos(shear_y) - sin(degrees)),
|
||||
0,
|
||||
scale_ * sin(degrees + shear_y) / cos(shear_y),
|
||||
scale_ * (-1 * sin(degrees + shear_y) * tan(shear_x) / cos(shear_y) + cos(degrees)),
|
||||
0};
|
||||
// Compute T * C * RSS * C^-1
|
||||
matrix[2] = (1 - matrix[0]) * cx - matrix[1] * cy + translation_x;
|
||||
matrix[5] = (1 - matrix[4]) * cy - matrix[3] * cx + translation_y;
|
||||
cv::Mat affine_mat(matrix);
|
||||
affine_mat = affine_mat.reshape(1, {2, 3});
|
||||
|
||||
std::shared_ptr<CVTensor> output_cv;
|
||||
RETURN_IF_NOT_OK(CVTensor::CreateEmpty(input_cv->shape(), input_cv->type(), &output_cv));
|
||||
RETURN_UNEXPECTED_IF_NULL(output_cv);
|
||||
cv::warpAffine(input_cv->mat(), output_cv->mat(), affine_mat, input_cv->mat().size(),
|
||||
GetCVInterpolationMode(interpolation_), cv::BORDER_CONSTANT,
|
||||
cv::Scalar(fill_value_[0], fill_value_[1], fill_value_[2]));
|
||||
(*output) = std::static_pointer_cast<Tensor>(output_cv);
|
||||
return Status::OK();
|
||||
}
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_
|
||||
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
class AffineOp : public TensorOp {
|
||||
public:
|
||||
/// Default values
|
||||
static const float_t kDegrees;
|
||||
static const std::vector<float_t> kTranslation;
|
||||
static const float_t kScale;
|
||||
static const std::vector<float_t> kShear;
|
||||
static const InterpolationMode kDefInterpolation;
|
||||
static const std::vector<uint8_t> kFillValue;
|
||||
|
||||
/// Constructor
|
||||
public:
|
||||
explicit AffineOp(float_t degrees, const std::vector<float_t> &translation = kTranslation, float_t scale = kScale,
|
||||
const std::vector<float_t> &shear = kShear, InterpolationMode interpolation = kDefInterpolation,
|
||||
const std::vector<uint8_t> &fill_value = kFillValue);
|
||||
|
||||
~AffineOp() override = default;
|
||||
|
||||
std::string Name() const override { return kAffineOp; }
|
||||
|
||||
Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
|
||||
|
||||
/// Member variables
|
||||
private:
|
||||
std::string kAffineOp = "AffineOp";
|
||||
|
||||
protected:
|
||||
float_t degrees_;
|
||||
std::vector<float_t> translation_; // translation_x and translation_y
|
||||
float_t scale_;
|
||||
std::vector<float_t> shear_; // shear_x and shear_y
|
||||
InterpolationMode interpolation_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
};
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_
|
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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/math_utils.h"
|
||||
|
||||
#include <opencv2/imgproc/types_c.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
Status ComputeUpperAndLowerPercentiles(std::vector<int32_t> *hist, int32_t hi_p, int32_t low_p, int32_t *hi,
|
||||
int32_t *lo) {
|
||||
try {
|
||||
int32_t n = std::accumulate(hist->begin(), hist->end(), 0);
|
||||
int32_t cut = static_cast<int32_t>((low_p / 100.0) * n);
|
||||
for (int32_t lb = 0; lb < hist->size() + 1 && cut > 0; lb++) {
|
||||
if (cut > (*hist)[lb]) {
|
||||
cut -= (*hist)[lb];
|
||||
(*hist)[lb] = 0;
|
||||
} else {
|
||||
(*hist)[lb] -= cut;
|
||||
cut = 0;
|
||||
}
|
||||
}
|
||||
cut = static_cast<int32_t>((hi_p / 100.0) * n);
|
||||
for (int32_t ub = hist->size() - 1; ub >= 0 && cut > 0; ub--) {
|
||||
if (cut > (*hist)[ub]) {
|
||||
cut -= (*hist)[ub];
|
||||
(*hist)[ub] = 0;
|
||||
} else {
|
||||
(*hist)[ub] -= cut;
|
||||
cut = 0;
|
||||
}
|
||||
}
|
||||
*lo = 0;
|
||||
*hi = hist->size() - 1;
|
||||
for (; (*lo) < (*hi) && !(*hist)[*lo]; (*lo)++) {
|
||||
}
|
||||
for (; (*hi) >= 0 && !(*hist)[*hi]; (*hi)--) {
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
std::string err_message = "Error in ComputeUpperAndLowerPercentiles: ";
|
||||
err_message += err_msg;
|
||||
RETURN_STATUS_UNEXPECTED(err_message);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status DegreesToRadians(float_t degrees, float_t *radians_target) {
|
||||
*radians_target = CV_PI * degrees / 180.0;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status GenerateRealNumber(float_t a, float_t b, std::mt19937 *rnd, float_t *result) {
|
||||
try {
|
||||
std::uniform_real_distribution<float_t> distribution{a, b};
|
||||
*result = distribution(*rnd);
|
||||
} catch (const std::exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
std::string err_message = "Error in GenerateRealNumber: ";
|
||||
err_message += err_msg;
|
||||
RETURN_STATUS_UNEXPECTED(err_message);
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_
|
||||
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include "minddata/dataset/util/status.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
||||
/// \brief Returns lower and upper pth percentiles of the input histogram.
|
||||
/// \param[in] hist: Input histogram (mutates the histogram for computation purposes)
|
||||
/// \param[in] hi_p: Right side percentile
|
||||
/// \param[in] low_p: Left side percentile
|
||||
/// \param[out] hi: Value at high end percentile
|
||||
/// \param[out] lo: Value at low end percentile
|
||||
Status ComputeUpperAndLowerPercentiles(std::vector<int32_t> *hist, int32_t hi_p, int32_t low_p, int32_t *hi,
|
||||
int32_t *lo);
|
||||
|
||||
/// \brief Converts degrees input to radians.
|
||||
/// \param[in] degrees: Input degrees
|
||||
/// \param[out] radians_target: Radians output
|
||||
Status DegreesToRadians(float_t degrees, float_t *radians_target);
|
||||
|
||||
/// \brief Generates a random real number in [a,b).
|
||||
/// \param[in] a: Start of range
|
||||
/// \param[in] b: End of range
|
||||
/// \param[in] rnd: Random device
|
||||
/// \param[out] result: Random number in range [a,b)
|
||||
Status GenerateRealNumber(float_t a, float_t b, std::mt19937 *rnd, float_t *result);
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_
|
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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 <algorithm>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "minddata/dataset/kernels/image/random_affine_op.h"
|
||||
#include "minddata/dataset/kernels/image/image_utils.h"
|
||||
#include "minddata/dataset/kernels/image/math_utils.h"
|
||||
#include "minddata/dataset/util/random.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
||||
const std::vector<float_t> RandomAffineOp::kDegreesRange = {0.0, 0.0};
|
||||
const std::vector<float_t> RandomAffineOp::kTranslationPercentages = {0.0, 0.0};
|
||||
const std::vector<float_t> RandomAffineOp::kScaleRange = {1.0, 1.0};
|
||||
const std::vector<float_t> RandomAffineOp::kShearRanges = {0.0, 0.0, 0.0, 0.0};
|
||||
const InterpolationMode RandomAffineOp::kDefInterpolation = InterpolationMode::kNearestNeighbour;
|
||||
const std::vector<uint8_t> RandomAffineOp::kFillValue = {0, 0, 0};
|
||||
|
||||
RandomAffineOp::RandomAffineOp(std::vector<float_t> degrees, std::vector<float_t> translate_range,
|
||||
std::vector<float_t> scale_range, std::vector<float_t> shear_ranges,
|
||||
InterpolationMode interpolation, std::vector<uint8_t> fill_value)
|
||||
: AffineOp(0.0),
|
||||
degrees_range_(degrees),
|
||||
translate_range_(translate_range),
|
||||
scale_range_(scale_range),
|
||||
shear_ranges_(shear_ranges) {
|
||||
interpolation_ = interpolation;
|
||||
fill_value_ = fill_value;
|
||||
rnd_.seed(GetSeed());
|
||||
}
|
||||
|
||||
Status RandomAffineOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
|
||||
IO_CHECK(input, output);
|
||||
dsize_t height = input->shape()[0];
|
||||
dsize_t width = input->shape()[1];
|
||||
float_t max_dx = translate_range_[0] * height;
|
||||
float_t max_dy = translate_range_[1] * width;
|
||||
float_t degrees = 0.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(degrees_range_[0], degrees_range_[1], &rnd_, °rees));
|
||||
float_t translation_x = 0.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dx, max_dx, &rnd_, &translation_x));
|
||||
float_t translation_y = 0.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dy, max_dy, &rnd_, &translation_y));
|
||||
float_t scale = 1.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(scale_range_[0], scale_range_[1], &rnd_, &scale));
|
||||
float_t shear_x = 0.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(shear_ranges_[0], shear_ranges_[1], &rnd_, &shear_x));
|
||||
float_t shear_y = 0.0;
|
||||
RETURN_IF_NOT_OK(GenerateRealNumber(shear_ranges_[2], shear_ranges_[3], &rnd_, &shear_y));
|
||||
// assign to base class variables
|
||||
degrees_ = degrees;
|
||||
scale_ = scale;
|
||||
translation_[0] = translation_x;
|
||||
translation_[1] = translation_y;
|
||||
shear_[0] = shear_x;
|
||||
shear_[1] = shear_y;
|
||||
return AffineOp::Compute(input, output);
|
||||
}
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
|
||||
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "minddata/dataset/core/cv_tensor.h"
|
||||
#include "minddata/dataset/core/tensor.h"
|
||||
#include "minddata/dataset/kernels/image/affine_op.h"
|
||||
#include "minddata/dataset/util/status.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
class RandomAffineOp : public AffineOp {
|
||||
public:
|
||||
/// Default values, also used by python_bindings.cc
|
||||
static const std::vector<float_t> kDegreesRange;
|
||||
static const std::vector<float_t> kTranslationPercentages;
|
||||
static const std::vector<float_t> kScaleRange;
|
||||
static const std::vector<float_t> kShearRanges;
|
||||
static const InterpolationMode kDefInterpolation;
|
||||
static const std::vector<uint8_t> kFillValue;
|
||||
|
||||
explicit RandomAffineOp(std::vector<float_t> degrees, std::vector<float_t> translate_range = kTranslationPercentages,
|
||||
std::vector<float_t> scale_range = kScaleRange,
|
||||
std::vector<float_t> shear_ranges = kShearRanges,
|
||||
InterpolationMode interpolation = kDefInterpolation,
|
||||
std::vector<uint8_t> fill_value = kFillValue);
|
||||
|
||||
~RandomAffineOp() override = default;
|
||||
|
||||
std::string Name() const override { return kRandomAffineOp; }
|
||||
|
||||
Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
|
||||
|
||||
private:
|
||||
std::string kRandomAffineOp = "RandomAffineOp";
|
||||
std::vector<float_t> degrees_range_; // 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
|
||||
std::mt19937 rnd_; // random device
|
||||
};
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 "common/common.h"
|
||||
#include "common/cvop_common.h"
|
||||
#include "minddata/dataset/kernels/image/auto_contrast_op.h"
|
||||
#include "minddata/dataset/core/cv_tensor.h"
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
using mindspore::LogStream;
|
||||
using mindspore::ExceptionType::NoExceptionType;
|
||||
using mindspore::MsLogLevel::INFO;
|
||||
|
||||
class MindDataTestAutoContrastOp : public UT::CVOP::CVOpCommon {
|
||||
public:
|
||||
MindDataTestAutoContrastOp() : CVOpCommon() {}
|
||||
};
|
||||
|
||||
TEST_F(MindDataTestAutoContrastOp, TestOp1) {
|
||||
MS_LOG(INFO) << "Doing testAutoContrastOp.";
|
||||
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
std::unique_ptr<AutoContrastOp> op(new AutoContrastOp(1.0, {0, 255}));
|
||||
EXPECT_TRUE(op->OneToOne());
|
||||
Status s = op->Compute(input_tensor_, &output_tensor);
|
||||
EXPECT_TRUE(s.IsOk());
|
||||
CheckImageShapeAndData(output_tensor, kAutoContrast);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 "common/common.h"
|
||||
#include "common/cvop_common.h"
|
||||
#include "minddata/dataset/kernels/image/equalize_op.h"
|
||||
#include "minddata/dataset/core/cv_tensor.h"
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
using mindspore::LogStream;
|
||||
using mindspore::ExceptionType::NoExceptionType;
|
||||
using mindspore::MsLogLevel::INFO;
|
||||
|
||||
class MindDataTestEqualizeOp : public UT::CVOP::CVOpCommon {
|
||||
public:
|
||||
MindDataTestEqualizeOp() : CVOpCommon() {}
|
||||
};
|
||||
|
||||
TEST_F(MindDataTestEqualizeOp, TestOp1) {
|
||||
MS_LOG(INFO) << "Doing testEqualizeOp.";
|
||||
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
std::unique_ptr<EqualizeOp> op(new EqualizeOp());
|
||||
EXPECT_TRUE(op->OneToOne());
|
||||
Status s = op->Compute(input_tensor_, &output_tensor);
|
||||
EXPECT_TRUE(s.IsOk());
|
||||
CheckImageShapeAndData(output_tensor, kEqualize);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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 "common/common.h"
|
||||
#include "common/cvop_common.h"
|
||||
#include "minddata/dataset/kernels/image/random_affine_op.h"
|
||||
#include "minddata/dataset/core/cv_tensor.h"
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
using mindspore::LogStream;
|
||||
using mindspore::ExceptionType::NoExceptionType;
|
||||
using mindspore::MsLogLevel::INFO;
|
||||
|
||||
class MindDataTestRandomAffineOp : public UT::CVOP::CVOpCommon {
|
||||
public:
|
||||
MindDataTestRandomAffineOp() : CVOpCommon() {}
|
||||
};
|
||||
|
||||
TEST_F(MindDataTestRandomAffineOp, TestOp1) {
|
||||
MS_LOG(INFO) << "Doing testRandomAffineOp.";
|
||||
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
std::unique_ptr<RandomAffineOp> op(new RandomAffineOp({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0},
|
||||
InterpolationMode::kNearestNeighbour, {255, 0, 0}));
|
||||
EXPECT_TRUE(op->OneToOne());
|
||||
Status s = op->Compute(input_tensor_, &output_tensor);
|
||||
EXPECT_TRUE(s.IsOk());
|
||||
CheckImageShapeAndData(output_tensor, kRandomAffine);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 565 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue