!20308 Fix warnings codeDEX, codecheck, shellcheck

Merge pull request !20308 from Mohammad Motallebi/fix_clean_july_master
This commit is contained in:
i-robot 2021-07-16 19:21:36 +00:00 committed by Gitee
commit 0e025d2210
58 changed files with 329 additions and 401 deletions

View File

@ -269,7 +269,9 @@ uint64_t CacheServerHW::GetAvailableMemory() {
if (title == "MemAvailable") {
std::string::size_type pos1 = line.find_last_of(" ");
std::string::size_type pos2 = line.find_last_of(" ", pos1 - 1);
mem_available_in_kb = std::stol(line.substr(pos2, pos1 - pos2));
if (pos1 != std::string::npos && pos2 != std::string::npos && line.size() > pos1) {
mem_available_in_kb = std::stol(line.substr(pos2, pos1 - pos2));
}
break;
}
}

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
DistributedSamplerObj::DistributedSamplerObj(int64_t num_shards, int64_t shard_id, bool shuffle, int64_t num_samples,
uint32_t seed, int64_t offset, bool even_dist)
@ -116,6 +115,5 @@ std::shared_ptr<SamplerObj> DistributedSamplerObj::SamplerCopy() {
}
int64_t DistributedSamplerObj::ShardId() { return shard_id_; }
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
PKSamplerObj::PKSamplerObj(int64_t num_val, bool shuffle, int64_t num_samples)
: num_val_(num_val), shuffle_(shuffle), num_samples_(num_samples) {}
@ -92,6 +91,5 @@ std::shared_ptr<SamplerObj> PKSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr<SamplerRT> sampler) : sp_(std::move(sampler)) {}
@ -80,6 +79,5 @@ Status PreBuiltSamplerObj::to_json(nlohmann::json *const out_json) {
RETURN_IF_NOT_OK(sp_->to_json(out_json));
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
RandomSamplerObj::RandomSamplerObj(bool replacement, int64_t num_samples, bool reshuffle_each_epoch)
: replacement_(replacement), num_samples_(num_samples), reshuffle_each_epoch_(reshuffle_each_epoch) {}
@ -83,6 +82,5 @@ std::shared_ptr<SamplerObj> RandomSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
SequentialSamplerObj::SequentialSamplerObj(int64_t start_index, int64_t num_samples)
: start_index_(start_index), num_samples_(num_samples) {}
@ -86,6 +85,5 @@ std::shared_ptr<SamplerObj> SequentialSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
SubsetRandomSamplerObj::SubsetRandomSamplerObj(std::vector<int64_t> indices, int64_t num_samples)
: SubsetSamplerObj(std::move(indices), num_samples) {}
@ -72,6 +71,5 @@ std::shared_ptr<SamplerObj> SubsetRandomSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -30,7 +30,6 @@
namespace mindspore {
namespace dataset {
// Constructor
SubsetSamplerObj::SubsetSamplerObj(std::vector<int64_t> indices, int64_t num_samples)
: indices_(std::move(indices)), num_samples_(num_samples) {}
@ -81,6 +80,5 @@ std::shared_ptr<SamplerObj> SubsetSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -21,7 +21,6 @@
namespace mindspore {
namespace dataset {
// Constructor
WeightedRandomSamplerObj::WeightedRandomSamplerObj(std::vector<double> weights, int64_t num_samples, bool replacement)
: weights_(std::move(weights)), num_samples_(num_samples), replacement_(replacement) {}
@ -78,6 +77,5 @@ std::shared_ptr<SamplerObj> WeightedRandomSamplerObj::SamplerCopy() {
}
return sampler;
}
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
AffineOperation::AffineOperation(float_t degrees, const std::vector<float> &translation, float scale,
const std::vector<float> &shear, InterpolationMode interpolation,
const std::vector<uint8_t> &fill_value)
@ -42,7 +40,8 @@ std::string AffineOperation::Name() const { return kAffineOperation; }
Status AffineOperation::ValidateParams() {
// Translate
if (translation_.size() != 2) {
constexpr size_t kExpectedTranslationSize = 2;
if (translation_.size() != kExpectedTranslationSize) {
std::string err_msg =
"Affine: translate expecting size 2, got: translation.size() = " + std::to_string(translation_.size());
MS_LOG(ERROR) << err_msg;
@ -52,7 +51,8 @@ Status AffineOperation::ValidateParams() {
RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[1], {-1, 1}, false, false));
// Shear
if (shear_.size() != 2) {
constexpr size_t kExpectedShearSize = 2;
if (shear_.size() != kExpectedShearSize) {
std::string err_msg = "Affine: shear_ranges expecting size 2, got: shear.size() = " + std::to_string(shear_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
@ -80,7 +80,6 @@ Status AffineOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// AutoContrastOperation
AutoContrastOperation::AutoContrastOperation(float cutoff, std::vector<uint32_t> ignore)
: cutoff_(cutoff), ignore_(ignore) {}
@ -45,8 +42,9 @@ Status AutoContrastOperation::ValidateParams() {
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
constexpr uint32_t kMaxIgnoreSize = 255;
for (uint32_t single_ignore : ignore_) {
if (single_ignore > 255) {
if (single_ignore > kMaxIgnoreSize) {
std::string err_msg =
"AutoContrast: invalid size, ignore has to be between 0 and 255, got: " + std::to_string(single_ignore);
MS_LOG(ERROR) << err_msg;
@ -69,7 +67,6 @@ Status AutoContrastOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
BoundingBoxAugmentOperation::BoundingBoxAugmentOperation(std::shared_ptr<TensorOperation> transform, float ratio)
: transform_(transform), ratio_(ratio) {}
@ -57,7 +54,6 @@ Status BoundingBoxAugmentOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
CenterCropOperation::CenterCropOperation(std::vector<int32_t> size) : size_(size) {}
CenterCropOperation::~CenterCropOperation() = default;
@ -42,7 +40,8 @@ std::shared_ptr<TensorOp> CenterCropOperation::Build() {
int32_t crop_width = size_[0];
// User has specified crop_width.
if (size_.size() == 2) {
constexpr size_t size_two = 2;
if (size_.size() == size_two) {
crop_width = size_[1];
}
@ -54,7 +53,6 @@ Status CenterCropOperation::to_json(nlohmann::json *out_json) {
(*out_json)["size"] = size_;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
CropOperation::CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size)
: coordinates_(coordinates), size_(size) {}
@ -38,7 +36,8 @@ Status CropOperation::ValidateParams() {
// we don't check the coordinates here because we don't have access to image dimensions
RETURN_IF_NOT_OK(ValidateVectorSize("Crop", size_));
if (coordinates_.size() != 2) {
constexpr size_t size_two = 2;
if (coordinates_.size() != size_two) {
std::string err_msg = "Crop: coordinates must be a vector of two values";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
@ -56,14 +55,14 @@ std::shared_ptr<TensorOp> CropOperation::Build() {
height = size_[0];
width = size_[0];
// User has specified crop_width.
if (size_.size() == 2) {
constexpr size_t size_two = 2;
if (size_.size() == size_two) {
width = size_[1];
}
std::shared_ptr<CropOp> tensor_op = std::make_shared<CropOp>(y, x, height, width);
return tensor_op;
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,9 +25,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// CutMixBatchOperation
CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob)
@ -56,9 +54,7 @@ Status CutMixBatchOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
CutOutOperation::CutOutOperation(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
CutOutOperation::~CutOutOperation() = default;
@ -55,7 +52,6 @@ Status CutOutOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
// DecodeOperation
DecodeOperation::DecodeOperation(bool rgb) : rgb_(rgb) {}
@ -41,7 +39,6 @@ Status DecodeOperation::to_json(nlohmann::json *out_json) {
(*out_json)["rgb"] = rgb_;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// EqualizeOperation
EqualizeOperation::~EqualizeOperation() = default;
@ -38,9 +35,7 @@ std::string EqualizeOperation::Name() const { return kEqualizeOperation; }
Status EqualizeOperation::ValidateParams() { return Status::OK(); }
std::shared_ptr<TensorOp> EqualizeOperation::Build() { return std::make_shared<EqualizeOp>(); }
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// HwcToChwOperation
HwcToChwOperation::~HwcToChwOperation() = default;
@ -39,7 +36,6 @@ Status HwcToChwOperation::ValidateParams() { return Status::OK(); }
std::shared_ptr<TensorOp> HwcToChwOperation::Build() { return std::make_shared<HwcToChwOp>(); }
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// InvertOperation
InvertOperation::~InvertOperation() = default;
@ -38,9 +35,7 @@ std::string InvertOperation::Name() const { return kInvertOperation; }
Status InvertOperation::ValidateParams() { return Status::OK(); }
std::shared_ptr<TensorOp> InvertOperation::Build() { return std::make_shared<InvertOp>(); }
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// MixUpOperation
MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {}
@ -48,9 +45,7 @@ Status MixUpBatchOperation::to_json(nlohmann::json *out_json) {
(*out_json)["alpha"] = alpha_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
// NormalizeOperation
NormalizeOperation::NormalizeOperation(std::vector<float> mean, std::vector<float> std) : mean_(mean), std_(std) {}
@ -47,7 +45,6 @@ Status NormalizeOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,9 +25,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// NormalizePadOperation
NormalizePadOperation::NormalizePadOperation(const std::vector<float> &mean, const std::vector<float> &std,
@ -49,7 +47,11 @@ Status NormalizePadOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> NormalizePadOperation::Build() {
return std::make_shared<NormalizePadOp>(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2], dtype_);
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
return std::make_shared<NormalizePadOp>(mean_[dimension_zero], mean_[dimension_one], mean_[dimension_two],
std_[dimension_zero], std_[dimension_one], std_[dimension_two], dtype_);
}
Status NormalizePadOperation::to_json(nlohmann::json *out_json) {
@ -61,7 +63,6 @@ Status NormalizePadOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// PadOperation
PadOperation::PadOperation(std::vector<int32_t> padding, std::vector<uint8_t> fill_value, BorderType padding_mode)
: padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {}
@ -47,36 +44,43 @@ Status PadOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> PadOperation::Build() {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
constexpr size_t dimension_three = 3;
constexpr size_t size_one = 1;
constexpr size_t size_two = 2;
constexpr size_t size_three = 3;
int32_t pad_top, pad_bottom, pad_left, pad_right;
switch (padding_.size()) {
case 1:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[0];
pad_bottom = padding_[0];
case size_one:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_zero];
pad_bottom = padding_[dimension_zero];
break;
case 2:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[1];
pad_bottom = padding_[1];
case size_two:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_one];
pad_bottom = padding_[dimension_one];
break;
default:
pad_left = padding_[0];
pad_top = padding_[1];
pad_right = padding_[2];
pad_bottom = padding_[3];
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_one];
pad_right = padding_[dimension_two];
pad_bottom = padding_[dimension_three];
}
uint8_t fill_r, fill_g, fill_b;
fill_r = fill_value_[0];
fill_g = fill_value_[0];
fill_b = fill_value_[0];
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_zero];
fill_b = fill_value_[dimension_zero];
if (fill_value_.size() == 3) {
fill_r = fill_value_[0];
fill_g = fill_value_[1];
fill_b = fill_value_[2];
if (fill_value_.size() == size_three) {
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_one];
fill_b = fill_value_[dimension_two];
}
std::shared_ptr<PadOp> tensor_op =
@ -93,7 +97,6 @@ Status PadOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,16 @@
namespace mindspore {
namespace dataset {
namespace vision {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
constexpr size_t dimension_three = 3;
constexpr size_t size_two = 2;
constexpr size_t size_three = 3;
constexpr size_t size_four = 4;
// RandomAffineOperation
RandomAffineOperation::RandomAffineOperation(const std::vector<float_t> &degrees,
const std::vector<float_t> &translate_range,
@ -47,62 +54,69 @@ std::string RandomAffineOperation::Name() const { return kRandomAffineOperation;
Status RandomAffineOperation::ValidateParams() {
// Degrees
if (degrees_.size() != 2) {
if (degrees_.size() != size_two) {
std::string err_msg =
"RandomAffine: degrees expecting size 2, got: degrees.size() = " + std::to_string(degrees_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (degrees_[0] > degrees_[1]) {
std::string err_msg =
"RandomAffine: minimum of degrees range is greater than maximum: min = " + std::to_string(degrees_[0]) +
", max = " + std::to_string(degrees_[1]);
if (degrees_[dimension_zero] > degrees_[dimension_one]) {
std::string err_msg = "RandomAffine: minimum of degrees range is greater than maximum: min = " +
std::to_string(degrees_[dimension_zero]) +
", max = " + std::to_string(degrees_[dimension_one]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
// Translate
if (translate_range_.size() != 2 && translate_range_.size() != 4) {
if (translate_range_.size() != size_two && translate_range_.size() != size_four) {
std::string err_msg = "RandomAffine: translate_range expecting size 2 or 4, got: translate_range.size() = " +
std::to_string(translate_range_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (translate_range_[0] > translate_range_[1]) {
if (translate_range_[dimension_zero] > translate_range_[dimension_one]) {
std::string err_msg = "RandomAffine: minimum of translate range on x is greater than maximum: min = " +
std::to_string(translate_range_[0]) + ", max = " + std::to_string(translate_range_[1]);
std::to_string(translate_range_[dimension_zero]) +
", max = " + std::to_string(translate_range_[dimension_one]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[0], {-1, 1}, false, false));
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[1], {-1, 1}, false, false));
if (translate_range_.size() == 4) {
if (translate_range_[2] > translate_range_[3]) {
RETURN_IF_NOT_OK(
ValidateScalar("RandomAffine", "translate", translate_range_[dimension_zero], {-1, 1}, false, false));
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[dimension_one], {-1, 1}, false, false));
if (translate_range_.size() == size_four) {
if (translate_range_[dimension_two] > translate_range_[dimension_three]) {
std::string err_msg = "RandomAffine: minimum of translate range on y is greater than maximum: min = " +
std::to_string(translate_range_[2]) + ", max = " + std::to_string(translate_range_[3]);
std::to_string(translate_range_[dimension_two]) +
", max = " + std::to_string(translate_range_[dimension_three]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[2], {-1, 1}, false, false));
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[3], {-1, 1}, false, false));
RETURN_IF_NOT_OK(
ValidateScalar("RandomAffine", "translate", translate_range_[dimension_two], {-1, 1}, false, false));
RETURN_IF_NOT_OK(
ValidateScalar("RandomAffine", "translate", translate_range_[dimension_three], {-1, 1}, false, false));
}
// Scale
RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_));
// Shear
if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) {
if (shear_ranges_.size() != size_two && shear_ranges_.size() != size_four) {
std::string err_msg = "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " +
std::to_string(shear_ranges_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (shear_ranges_[0] > shear_ranges_[1]) {
if (shear_ranges_[dimension_zero] > shear_ranges_[dimension_one]) {
std::string err_msg = "RandomAffine: minimum of horizontal shear range is greater than maximum: min = " +
std::to_string(shear_ranges_[0]) + ", max = " + std::to_string(shear_ranges_[1]);
std::to_string(shear_ranges_[dimension_zero]) +
", max = " + std::to_string(shear_ranges_[dimension_one]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (shear_ranges_.size() == 4 && shear_ranges_[2] > shear_ranges_[3]) {
if (shear_ranges_.size() == size_four && shear_ranges_[dimension_two] > shear_ranges_[dimension_three]) {
std::string err_msg = "RandomAffine: minimum of vertical shear range is greater than maximum: min = " +
std::to_string(shear_ranges_[2]) + ", max = " + std::to_string(scale_range_[3]);
std::to_string(shear_ranges_[dimension_two]) +
", max = " + std::to_string(scale_range_[dimension_three]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
@ -112,16 +126,17 @@ Status RandomAffineOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomAffineOperation::Build() {
if (shear_ranges_.size() == 2) {
shear_ranges_.resize(4);
if (shear_ranges_.size() == size_two) {
shear_ranges_.resize(size_four);
}
if (translate_range_.size() == 2) {
translate_range_.resize(4);
if (translate_range_.size() == size_two) {
translate_range_.resize(size_four);
}
std::vector<uint8_t> fill_value = {fill_value_[0], fill_value_[0], fill_value_[0]};
if (fill_value_.size() == 3) {
fill_value[1] = fill_value_[1];
fill_value[2] = fill_value_[2];
std::vector<uint8_t> fill_value = {fill_value_[dimension_zero], fill_value_[dimension_zero],
fill_value_[dimension_zero]};
if (fill_value_.size() == size_three) {
fill_value[dimension_one] = fill_value_[dimension_one];
fill_value[dimension_two] = fill_value_[dimension_two];
}
auto tensor_op = std::make_shared<RandomAffineOp>(degrees_, translate_range_, scale_range_, shear_ranges_,
@ -140,7 +155,6 @@ Status RandomAffineOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,13 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
#ifndef ENABLE_ANDROID
// RandomColorAdjustOperation.
RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector<float> brightness, std::vector<float> contrast,
std::vector<float> saturation, std::vector<float> hue)
@ -56,25 +58,25 @@ Status RandomColorAdjustOperation::ValidateParams() {
std::shared_ptr<TensorOp> RandomColorAdjustOperation::Build() {
float brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub;
brightness_lb = brightness_[0];
brightness_ub = brightness_[0];
brightness_lb = brightness_[dimension_zero];
brightness_ub = brightness_[dimension_zero];
if (brightness_.size() == 2) brightness_ub = brightness_[1];
if (brightness_.size() == size_two) brightness_ub = brightness_[dimension_one];
contrast_lb = contrast_[0];
contrast_ub = contrast_[0];
contrast_lb = contrast_[dimension_zero];
contrast_ub = contrast_[dimension_zero];
if (contrast_.size() == 2) contrast_ub = contrast_[1];
if (contrast_.size() == size_two) contrast_ub = contrast_[dimension_one];
saturation_lb = saturation_[0];
saturation_ub = saturation_[0];
saturation_lb = saturation_[dimension_zero];
saturation_ub = saturation_[dimension_zero];
if (saturation_.size() == 2) saturation_ub = saturation_[1];
if (saturation_.size() == size_two) saturation_ub = saturation_[dimension_one];
hue_lb = hue_[0];
hue_ub = hue_[0];
hue_lb = hue_[dimension_zero];
hue_ub = hue_[dimension_zero];
if (hue_.size() == 2) hue_ub = hue_[1];
if (hue_.size() == size_two) hue_ub = hue_[dimension_one];
std::shared_ptr<RandomColorAdjustOp> tensor_op = std::make_shared<RandomColorAdjustOp>(
brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub);
@ -91,7 +93,6 @@ Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -26,9 +26,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomColorOperation.
RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) { random_op_ = true; }
@ -64,9 +62,7 @@ Status RandomColorOperation::to_json(nlohmann::json *out_json) {
(*out_json)["degrees"] = std::vector<float>{t_lb_, t_ub_};
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomCropDecodeResizeOperation
RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(std::vector<int32_t> size, std::vector<float> scale,
std::vector<float> ratio,
@ -40,19 +38,23 @@ RandomCropDecodeResizeOperation::~RandomCropDecodeResizeOperation() = default;
std::string RandomCropDecodeResizeOperation::Name() const { return kRandomCropDecodeResizeOperation; }
std::shared_ptr<TensorOp> RandomCropDecodeResizeOperation::Build() {
int32_t crop_height = size_[0];
int32_t crop_width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
int32_t crop_height = size_[dimension_zero];
int32_t crop_width = size_[dimension_zero];
// User has specified the crop_width value.
if (size_.size() == 2) {
crop_width = size_[1];
if (size_.size() == size_two) {
crop_width = size_[dimension_one];
}
float scale_lower_bound = scale_[0];
float scale_upper_bound = scale_[1];
float scale_lower_bound = scale_[dimension_zero];
float scale_upper_bound = scale_[dimension_one];
float aspect_lower_bound = ratio_[0];
float aspect_upper_bound = ratio_[1];
float aspect_lower_bound = ratio_[dimension_zero];
float aspect_upper_bound = ratio_[dimension_one];
auto tensor_op =
std::make_shared<RandomCropDecodeResizeOp>(crop_height, crop_width, scale_lower_bound, scale_upper_bound,
@ -73,9 +75,7 @@ Status RandomCropDecodeResizeOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomCropOperation
RandomCropOperation::RandomCropOperation(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
std::vector<uint8_t> fill_value, BorderType padding_mode)
@ -56,44 +54,52 @@ Status RandomCropOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomCropOperation::Build() {
int32_t crop_height = size_[0];
int32_t crop_width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
constexpr size_t dimension_three = 3;
constexpr size_t size_one = 1;
constexpr size_t size_two = 2;
constexpr size_t size_three = 3;
int32_t crop_height = size_[dimension_zero];
int32_t crop_width = size_[dimension_zero];
// User has specified the crop_width value.
if (size_.size() == 2) {
crop_width = size_[1];
if (size_.size() == size_two) {
crop_width = size_[dimension_one];
}
int32_t pad_top, pad_bottom, pad_left, pad_right;
switch (padding_.size()) {
case 1:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[0];
pad_bottom = padding_[0];
case size_one:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_zero];
pad_bottom = padding_[dimension_zero];
break;
case 2:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[1];
pad_bottom = padding_[1];
case size_two:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_one];
pad_bottom = padding_[dimension_one];
break;
default:
pad_left = padding_[0];
pad_top = padding_[1];
pad_right = padding_[2];
pad_bottom = padding_[3];
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_one];
pad_right = padding_[dimension_two];
pad_bottom = padding_[dimension_three];
}
uint8_t fill_r, fill_g, fill_b;
fill_r = fill_value_[0];
fill_g = fill_value_[0];
fill_b = fill_value_[0];
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_zero];
fill_b = fill_value_[dimension_zero];
if (fill_value_.size() == 3) {
fill_r = fill_value_[0];
fill_g = fill_value_[1];
fill_b = fill_value_[2];
if (fill_value_.size() == size_three) {
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_one];
fill_b = fill_value_[dimension_two];
}
auto tensor_op = std::make_shared<RandomCropOp>(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right,
@ -111,9 +117,7 @@ Status RandomCropOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomCropWithBBoxOperation
RandomCropWithBBoxOperation::RandomCropWithBBoxOperation(std::vector<int32_t> size, std::vector<int32_t> padding,
bool pad_if_needed, std::vector<uint8_t> fill_value,
@ -56,44 +53,52 @@ Status RandomCropWithBBoxOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomCropWithBBoxOperation::Build() {
int32_t crop_height = size_[0];
int32_t crop_width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
constexpr size_t dimension_three = 3;
constexpr size_t size_one = 1;
constexpr size_t size_two = 2;
constexpr size_t size_three = 3;
int32_t crop_height = size_[dimension_zero];
int32_t crop_width = size_[dimension_zero];
// User has specified the crop_width value.
if (size_.size() == 2) {
crop_width = size_[1];
if (size_.size() == size_two) {
crop_width = size_[dimension_one];
}
int32_t pad_top, pad_bottom, pad_left, pad_right;
switch (padding_.size()) {
case 1:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[0];
pad_bottom = padding_[0];
case size_one:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_zero];
pad_bottom = padding_[dimension_zero];
break;
case 2:
pad_left = padding_[0];
pad_top = padding_[0];
pad_right = padding_[1];
pad_bottom = padding_[1];
case size_two:
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_zero];
pad_right = padding_[dimension_one];
pad_bottom = padding_[dimension_one];
break;
default:
pad_left = padding_[0];
pad_top = padding_[1];
pad_right = padding_[2];
pad_bottom = padding_[3];
pad_left = padding_[dimension_zero];
pad_top = padding_[dimension_one];
pad_right = padding_[dimension_two];
pad_bottom = padding_[dimension_three];
}
uint8_t fill_r, fill_g, fill_b;
fill_r = fill_value_[0];
fill_g = fill_value_[0];
fill_b = fill_value_[0];
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_zero];
fill_b = fill_value_[dimension_zero];
if (fill_value_.size() == 3) {
fill_r = fill_value_[0];
fill_g = fill_value_[1];
fill_b = fill_value_[2];
if (fill_value_.size() == size_three) {
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_one];
fill_b = fill_value_[dimension_two];
}
auto tensor_op =
@ -112,9 +117,7 @@ Status RandomCropWithBBoxOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomHorizontalFlipOperation
RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float prob) : TensorOperation(true), probability_(prob) {}
@ -51,9 +48,7 @@ Status RandomHorizontalFlipOperation::to_json(nlohmann::json *out_json) {
(*out_json)["prob"] = probability_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomHorizontalFlipWithBBoxOperation
RandomHorizontalFlipWithBBoxOperation::RandomHorizontalFlipWithBBoxOperation(float probability)
: TensorOperation(true), probability_(probability) {}
@ -53,9 +50,7 @@ Status RandomHorizontalFlipWithBBoxOperation::to_json(nlohmann::json *out_json)
(*out_json)["prob"] = probability_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomPosterizeOperation
RandomPosterizeOperation::RandomPosterizeOperation(const std::vector<uint8_t> &bit_range)
: TensorOperation(true), bit_range_(bit_range) {}
@ -39,25 +36,34 @@ RandomPosterizeOperation::~RandomPosterizeOperation() = default;
std::string RandomPosterizeOperation::Name() const { return kRandomPosterizeOperation; }
Status RandomPosterizeOperation::ValidateParams() {
if (bit_range_.size() != 2) {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
constexpr uint8_t kMinimumBitValue = 1;
constexpr uint8_t kMaximumBitValue = 8;
if (bit_range_.size() != size_two) {
std::string err_msg =
"RandomPosterize: bit_range needs to be of size 2 but is of size: " + std::to_string(bit_range_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (bit_range_[0] < 1 || bit_range_[0] > 8) {
std::string err_msg = "RandomPosterize: min_bit value is out of range [1-8]: " + std::to_string(bit_range_[0]);
if (bit_range_[dimension_zero] < kMinimumBitValue || bit_range_[dimension_zero] > kMaximumBitValue) {
std::string err_msg =
"RandomPosterize: min_bit value is out of range [1-8]: " + std::to_string(bit_range_[dimension_zero]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (bit_range_[1] < 1 || bit_range_[1] > 8) {
std::string err_msg = "RandomPosterize: max_bit value is out of range [1-8]: " + std::to_string(bit_range_[1]);
if (bit_range_[dimension_one] < kMinimumBitValue || bit_range_[dimension_one] > kMaximumBitValue) {
std::string err_msg =
"RandomPosterize: max_bit value is out of range [1-8]: " + std::to_string(bit_range_[dimension_one]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (bit_range_[1] < bit_range_[0]) {
std::string err_msg = "RandomPosterize: max_bit value is less than min_bit: max =" + std::to_string(bit_range_[1]) +
", min = " + std::to_string(bit_range_[0]);
if (bit_range_[dimension_one] < bit_range_[dimension_zero]) {
std::string err_msg =
"RandomPosterize: max_bit value is less than min_bit: max =" + std::to_string(bit_range_[dimension_one]) +
", min = " + std::to_string(bit_range_[dimension_zero]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
@ -73,9 +79,7 @@ Status RandomPosterizeOperation::to_json(nlohmann::json *out_json) {
(*out_json)["bits"] = bit_range_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomResizeOperation
RandomResizeOperation::RandomResizeOperation(std::vector<int32_t> size) : TensorOperation(true), size_(size) {}
@ -43,14 +40,18 @@ Status RandomResizeOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomResizeOperation::Build() {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
// If size is a single value, the smaller edge of the image will be
// resized to this value with the same image aspect ratio.
int32_t height = size_[0];
int32_t height = size_[dimension_zero];
int32_t width = 0;
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
std::shared_ptr<RandomResizeOp> tensor_op = std::make_shared<RandomResizeOp>(height, width);
@ -61,9 +62,7 @@ Status RandomResizeOperation::to_json(nlohmann::json *out_json) {
(*out_json)["size"] = size_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomResizeWithBBoxOperation
RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(std::vector<int32_t> size)
: TensorOperation(true), size_(size) {}
@ -44,14 +41,18 @@ Status RandomResizeWithBBoxOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomResizeWithBBoxOperation::Build() {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
// If size is a single value, the smaller edge of the image will be
// resized to this value with the same image aspect ratio.
int32_t height = size_[0];
int32_t height = size_[dimension_zero];
int32_t width = 0;
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
std::shared_ptr<RandomResizeWithBBoxOp> tensor_op = std::make_shared<RandomResizeWithBBoxOp>(height, width);
@ -62,9 +63,7 @@ Status RandomResizeWithBBoxOperation::to_json(nlohmann::json *out_json) {
(*out_json)["size"] = size_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,7 +25,6 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
RandomResizedCropOperation::RandomResizedCropOperation(const RandomResizedCropOperation &) = default;
@ -63,14 +62,19 @@ Status RandomResizedCropOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomResizedCropOperation::Build() {
int32_t height = size_[0];
int32_t width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
int32_t height = size_[dimension_zero];
int32_t width = size_[dimension_zero];
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
std::shared_ptr<RandomCropAndResizeOp> tensor_op = std::make_shared<RandomCropAndResizeOp>(
height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_);
height, width, scale_[dimension_zero], scale_[dimension_one], ratio_[dimension_zero], ratio_[dimension_one],
interpolation_, max_attempts_);
return tensor_op;
}
@ -84,9 +88,7 @@ Status RandomResizedCropOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomResizedCropWithBBoxOperation
RandomResizedCropWithBBoxOperation::RandomResizedCropWithBBoxOperation(std::vector<int32_t> size,
std::vector<float> scale,
@ -60,14 +57,19 @@ Status RandomResizedCropWithBBoxOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomResizedCropWithBBoxOperation::Build() {
int32_t height = size_[0];
int32_t width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
int32_t height = size_[dimension_zero];
int32_t width = size_[dimension_zero];
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
std::shared_ptr<RandomCropAndResizeWithBBoxOp> tensor_op = std::make_shared<RandomCropAndResizeWithBBoxOp>(
height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_);
height, width, scale_[dimension_zero], scale_[dimension_one], ratio_[dimension_zero], ratio_[dimension_one],
interpolation_, max_attempts_);
return tensor_op;
}
@ -81,9 +83,7 @@ Status RandomResizedCropWithBBoxOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,9 +25,14 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t dimension_two = 2;
constexpr size_t size_one = 1;
constexpr size_t size_two = 2;
constexpr size_t size_three = 3;
// Function to create RandomRotationOperation.
RandomRotationOperation::RandomRotationOperation(std::vector<float> degrees, InterpolationMode resample, bool expand,
@ -45,26 +50,27 @@ std::string RandomRotationOperation::Name() const { return kRandomRotationOperat
Status RandomRotationOperation::ValidateParams() {
// degrees
if (degrees_.size() != 2 && degrees_.size() != 1) {
if (degrees_.size() != size_two && degrees_.size() != size_one) {
std::string err_msg =
"RandomRotation: degrees must be a vector of one or two values, got: " + std::to_string(degrees_.size());
MS_LOG(ERROR) << "RandomRotation: degrees must be a vector of one or two values, got: " << degrees_;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if ((degrees_.size() == 2) && (degrees_[1] < degrees_[0])) {
if ((degrees_.size() == size_two) && (degrees_[dimension_one] < degrees_[dimension_zero])) {
std::string err_msg = "RandomRotation: degrees must be in the format of (min, max), got: (" +
std::to_string(degrees_[0]) + ", " + std::to_string(degrees_[1]) + ")";
std::to_string(degrees_[dimension_zero]) + ", " + std::to_string(degrees_[dimension_one]) +
")";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
} else if ((degrees_.size() == 1) && (degrees_[0] < 0)) {
} else if ((degrees_.size() == size_one) && (degrees_[dimension_zero] < 0)) {
std::string err_msg =
"RandomRotation: if degrees only has one value, it must be greater than or equal to 0, got: " +
std::to_string(degrees_[0]);
std::to_string(degrees_[dimension_zero]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
// center
if (center_.size() != 0 && center_.size() != 2) {
if (center_.size() != 0 && center_.size() != size_two) {
std::string err_msg =
"RandomRotation: center must be a vector of two values or empty, got: " + std::to_string(center_.size());
MS_LOG(ERROR) << err_msg;
@ -77,23 +83,23 @@ Status RandomRotationOperation::ValidateParams() {
std::shared_ptr<TensorOp> RandomRotationOperation::Build() {
float start_degree, end_degree;
if (degrees_.size() == 1) {
start_degree = -degrees_[0];
end_degree = degrees_[0];
} else if (degrees_.size() == 2) {
start_degree = degrees_[0];
end_degree = degrees_[1];
if (degrees_.size() == size_one) {
start_degree = -degrees_[dimension_zero];
end_degree = degrees_[dimension_zero];
} else if (degrees_.size() == size_two) {
start_degree = degrees_[dimension_zero];
end_degree = degrees_[dimension_one];
}
uint8_t fill_r, fill_g, fill_b;
fill_r = fill_value_[0];
fill_g = fill_value_[0];
fill_b = fill_value_[0];
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_zero];
fill_b = fill_value_[dimension_zero];
if (fill_value_.size() == 3) {
fill_r = fill_value_[0];
fill_g = fill_value_[1];
fill_b = fill_value_[2];
if (fill_value_.size() == size_three) {
fill_r = fill_value_[dimension_zero];
fill_g = fill_value_[dimension_one];
fill_b = fill_value_[dimension_two];
}
std::shared_ptr<RandomRotationOp> tensor_op = std::make_shared<RandomRotationOp>(
@ -111,9 +117,7 @@ Status RandomRotationOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomSelectSubpolicyOperation.
RandomSelectSubpolicyOperation::RandomSelectSubpolicyOperation(
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy)
@ -102,9 +100,7 @@ Status RandomSelectSubpolicyOperation::to_json(nlohmann::json *out_json) {
(*out_json)["policy"] = policy_tensor_ops;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,11 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
// Function to create RandomSharpness.
RandomSharpnessOperation::RandomSharpnessOperation(std::vector<float> degrees)
@ -39,13 +40,13 @@ RandomSharpnessOperation::~RandomSharpnessOperation() = default;
std::string RandomSharpnessOperation::Name() const { return kRandomSharpnessOperation; }
Status RandomSharpnessOperation::ValidateParams() {
if (degrees_.size() != 2 || degrees_[0] < 0 || degrees_[1] < 0) {
if (degrees_.size() != size_two || degrees_[dimension_zero] < 0 || degrees_[dimension_one] < 0) {
std::string err_msg = "RandomSharpness: degrees must be a vector of two values and greater than or equal to 0.";
MS_LOG(ERROR) << "RandomSharpness: degrees must be a vector of two values and greater than or equal to 0, got: "
<< degrees_;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (degrees_[1] < degrees_[0]) {
if (degrees_[dimension_one] < degrees_[dimension_zero]) {
std::string err_msg = "RandomSharpness: degrees must be in the format of (min, max).";
MS_LOG(ERROR) << "RandomSharpness: degrees must be in the format of (min, max), got: " << degrees_;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
@ -54,7 +55,8 @@ Status RandomSharpnessOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> RandomSharpnessOperation::Build() {
std::shared_ptr<RandomSharpnessOp> tensor_op = std::make_shared<RandomSharpnessOp>(degrees_[0], degrees_[1]);
std::shared_ptr<RandomSharpnessOp> tensor_op =
std::make_shared<RandomSharpnessOp>(degrees_[dimension_zero], degrees_[dimension_one]);
return tensor_op;
}
@ -62,9 +64,7 @@ Status RandomSharpnessOperation::to_json(nlohmann::json *out_json) {
(*out_json)["degrees"] = degrees_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomSolarizeOperation.
RandomSolarizeOperation::RandomSolarizeOperation(std::vector<uint8_t> threshold)
: TensorOperation(true), threshold_(threshold) {}
@ -39,21 +36,26 @@ RandomSolarizeOperation::~RandomSolarizeOperation() = default;
std::string RandomSolarizeOperation::Name() const { return kRandomSolarizeOperation; }
Status RandomSolarizeOperation::ValidateParams() {
if (threshold_.size() != 2) {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
constexpr uint8_t kThresholdMax = 255;
if (threshold_.size() != size_two) {
std::string err_msg =
"RandomSolarize: threshold must be a vector of two values, got: " + std::to_string(threshold_.size());
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
for (int32_t i = 0; i < threshold_.size(); ++i) {
if (threshold_[i] < 0 || threshold_[i] > 255) {
if (threshold_[i] < 0 || threshold_[i] > kThresholdMax) {
std::string err_msg =
"RandomSolarize: threshold has to be between 0 and 255, got:" + std::to_string(threshold_[i]);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
}
if (threshold_[0] > threshold_[1]) {
if (threshold_[dimension_zero] > threshold_[dimension_one]) {
std::string err_msg = "RandomSolarize: threshold must be passed in a (min, max) format";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
@ -70,9 +72,7 @@ Status RandomSolarizeOperation::to_json(nlohmann::json *out_json) {
(*out_json)["threshold"] = threshold_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomVerticalFlipOperation
RandomVerticalFlipOperation::RandomVerticalFlipOperation(float prob) : TensorOperation(true), probability_(prob) {}
@ -52,9 +49,7 @@ Status RandomVerticalFlipOperation::to_json(nlohmann::json *out_json) {
(*out_json)["prob"] = probability_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RandomVerticalFlipWithBBoxOperation
RandomVerticalFlipWithBBoxOperation::RandomVerticalFlipWithBBoxOperation(float prob)
: TensorOperation(true), probability_(prob) {}
@ -54,9 +51,7 @@ Status RandomVerticalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) {
(*out_json)["prob"] = probability_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RescaleOperation
RescaleOperation::RescaleOperation(float rescale, float shift) : rescale_(rescale), shift_(shift) {}
@ -58,9 +55,7 @@ Status RescaleOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
// ResizeOperation
ResizeOperation::ResizeOperation(std::vector<int32_t> size, InterpolationMode interpolation)
: size_(size), interpolation_(interpolation) {}
@ -40,14 +38,18 @@ Status ResizeOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> ResizeOperation::Build() {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
// If size is a single value, the smaller edge of the image will be
// resized to this value with the same image aspect ratio.
int32_t height = size_[0];
int32_t height = size_[dimension_zero];
int32_t width = 0;
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
return std::make_shared<ResizeOp>(height, width, interpolation_);
@ -60,7 +62,6 @@ Status ResizeOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
// ResizePreserveAROperation
ResizePreserveAROperation::ResizePreserveAROperation(int32_t height, int32_t width, int32_t img_orientation)
: height_(height), width_(width), img_orientation_(img_orientation) {}
@ -48,7 +46,6 @@ Status ResizePreserveAROperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,9 +25,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// ResizeWithBBoxOperation
ResizeWithBBoxOperation::ResizeWithBBoxOperation(std::vector<int32_t> size, InterpolationMode interpolation)
@ -43,12 +41,16 @@ Status ResizeWithBBoxOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> ResizeWithBBoxOperation::Build() {
int32_t height = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
int32_t height = size_[dimension_zero];
int32_t width = 0;
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
return std::make_shared<ResizeWithBBoxOp>(height, width, interpolation_);
@ -61,9 +63,7 @@ Status ResizeWithBBoxOperation::to_json(nlohmann::json *out_json) {
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -23,9 +23,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
RgbToGrayOperation::RgbToGrayOperation() = default;
// RGB2GRAYOperation
@ -36,7 +34,6 @@ std::string RgbToGrayOperation::Name() const { return kRgbToGrayOperation; }
Status RgbToGrayOperation::ValidateParams() { return Status::OK(); }
std::shared_ptr<TensorOp> RgbToGrayOperation::Build() { return std::make_shared<RgbToGrayOp>(); }
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -27,9 +27,7 @@ namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RgbaToBgrOperation.
RgbaToBgrOperation::RgbaToBgrOperation() {}
@ -44,7 +42,6 @@ std::shared_ptr<TensorOp> RgbaToBgrOperation::Build() {
return tensor_op;
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// RgbaToRgbOperation.
RgbaToRgbOperation::RgbaToRgbOperation() {}
@ -43,9 +40,7 @@ std::shared_ptr<TensorOp> RgbaToRgbOperation::Build() {
std::shared_ptr<RgbaToRgbOp> tensor_op = std::make_shared<RgbaToRgbOp>();
return tensor_op;
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -20,9 +20,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
// RotateOperation
RotateOperation::RotateOperation() { rotate_op_ = std::make_shared<RotateOp>(0); }

View File

@ -25,11 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// SoftDvppDecodeRandomCropResizeJpegOperation
SoftDvppDecodeRandomCropResizeJpegOperation::SoftDvppDecodeRandomCropResizeJpegOperation(std::vector<int32_t> size,
std::vector<float> scale,
@ -46,8 +43,10 @@ std::string SoftDvppDecodeRandomCropResizeJpegOperation::Name() const {
Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() {
// size
RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeRandomCropResizeJpeg", size_));
constexpr int32_t value_one = 1;
constexpr int32_t value_two = 2;
for (int32_t i = 0; i < size_.size(); i++) {
if (size_[i] % 2 == 1) {
if (size_[i] % value_two == value_one) {
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: size[" + std::to_string(i) +
"] must be even values, got: " + std::to_string(size_[i]);
MS_LOG(ERROR) << err_msg;
@ -69,15 +68,20 @@ Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> SoftDvppDecodeRandomCropResizeJpegOperation::Build() {
int32_t height = size_[0];
int32_t width = size_[0];
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
int32_t height = size_[dimension_zero];
int32_t width = size_[dimension_zero];
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
auto tensor_op = std::make_shared<SoftDvppDecodeRandomCropResizeJpegOp>(height, width, scale_[0], scale_[1],
ratio_[0], ratio_[1], max_attempts_);
auto tensor_op = std::make_shared<SoftDvppDecodeRandomCropResizeJpegOp>(height, width, scale_[dimension_zero],
scale_[dimension_one], ratio_[dimension_zero],
ratio_[dimension_one], max_attempts_);
return tensor_op;
}
@ -90,9 +94,7 @@ Status SoftDvppDecodeRandomCropResizeJpegOperation::to_json(nlohmann::json *out_
*out_json = args;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// SoftDvppDecodeResizeJpegOperation
SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector<int32_t> size) : size_(size) {}
@ -38,8 +36,10 @@ std::string SoftDvppDecodeResizeJpegOperation::Name() const { return kSoftDvppDe
Status SoftDvppDecodeResizeJpegOperation::ValidateParams() {
RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeResizeJpeg", size_));
constexpr int32_t value_one = 1;
constexpr int32_t value_two = 2;
for (int32_t i = 0; i < size_.size(); i++) {
if (size_[i] % 2 == 1) {
if (size_[i] % value_two == value_one) {
std::string err_msg = "SoftDvppDecodeResizeJpeg: size[" + std::to_string(i) +
"] must be even values, got: " + std::to_string(size_[i]);
MS_LOG(ERROR) << err_msg;
@ -50,14 +50,18 @@ Status SoftDvppDecodeResizeJpegOperation::ValidateParams() {
}
std::shared_ptr<TensorOp> SoftDvppDecodeResizeJpegOperation::Build() {
constexpr size_t dimension_zero = 0;
constexpr size_t dimension_one = 1;
constexpr size_t size_two = 2;
// If size is a single value, the smaller edge of the image will be
// resized to this value with the same image aspect ratio.
int32_t height = size_[0];
int32_t height = size_[dimension_zero];
int32_t width = 0;
// User specified the width value.
if (size_.size() == 2) {
width = size_[1];
if (size_.size() == size_two) {
width = size_[dimension_one];
}
std::shared_ptr<SoftDvppDecodeResizeJpegOp> tensor_op = std::make_shared<SoftDvppDecodeResizeJpegOp>(height, width);
return tensor_op;
@ -67,9 +71,7 @@ Status SoftDvppDecodeResizeJpegOperation::to_json(nlohmann::json *out_json) {
(*out_json)["size"] = size_;
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,10 +25,8 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// SwapRedBlueOperation.
SwapRedBlueOperation::SwapRedBlueOperation() {}
@ -42,9 +40,7 @@ std::shared_ptr<TensorOp> SwapRedBlueOperation::Build() {
std::shared_ptr<SwapRedBlueOp> tensor_op = std::make_shared<SwapRedBlueOp>();
return tensor_op;
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -25,9 +25,7 @@
namespace mindspore {
namespace dataset {
namespace vision {
#ifndef ENABLE_ANDROID
// UniformAugOperation
UniformAugOperation::UniformAugOperation(std::vector<std::shared_ptr<TensorOperation>> transforms, int32_t num_ops)
@ -75,7 +73,6 @@ Status UniformAugOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
#endif
} // namespace vision
} // namespace dataset
} // namespace mindspore

View File

@ -111,7 +111,7 @@ def main():
associations_dict = load_associations()
# get all objects filename
all_object_files = [x[x.rfind('/') + 1:] for x in glob.glob('{}*.o'.format(OBJECTS_DIR))]
all_object_files = [os.path.basename(x) for x in glob.glob('{}*.o'.format(OBJECTS_DIR))]
print("All Obj files: {}".format(len(all_object_files)))
# find ops in user code

View File

@ -68,7 +68,7 @@ echo "CWD: $ORIGINAL_PATH"
echo "File PATH: $FILE_PATH"
cd $FILE_PATH
cd $FILE_PATH || exit
MD_LIB_FILENAME="libminddata-lite.a"
@ -76,7 +76,7 @@ MD_LIB_FILENAME="libminddata-lite.a"
MD_LIB_PATH=`find $MINDSPORE_PATH -name "${MD_LIB_FILENAME}" | head -n 1`
if [ -z "${MD_LIB_PATH}" ]; then
echo -e "\e[31mMindData lite static library could not be found.\e[0m"
cd $ORIGINAL_PATH
cd $ORIGINAL_PATH || exit
exit 1
fi
@ -84,7 +84,7 @@ fi
# extract all objects of static lib to tmp/
mkdir -p tmp
cp $MD_LIB_PATH tmp
cd tmp
cd tmp || exit
# extract objects with identical names by prepending (one or more) '_' to their names
# (this scruipt supports more than 2 duplicate filenames)
DUPLICATES=`ar t "${MD_LIB_FILENAME}" | sort | uniq -d`
@ -115,7 +115,7 @@ cd ..
python build_lib.py ${USER_CODES}
retVal=$?
if [ $retVal -ne 0 ]; then
cd $ORIGINAL_PATH
cd $ORIGINAL_PATH || exit
exit 1
fi
@ -144,13 +144,13 @@ echo "Architecture: $TARGET_ARCHITECTURE"
if [ "$TARGET_ARCHITECTURE" == "ARM64" ]; then
if [ -z "${ANDROID_NDK}" ]; then
echo -e "\e[31mPlease set ANDROID_NDK environment variable.\e[0m"
cd $ORIGINAL_PATH
cd $ORIGINAL_PATH || exit
exit 1
fi
elif [ "$TARGET_ARCHITECTURE" == "ARM32" ]; then
if [ -z "${ANDROID_NDK}" ]; then
echo -e "\e[31mPlease set ANDROID_NDK environment variable.\e[0m"
cd $ORIGINAL_PATH
cd $ORIGINAL_PATH || exit
exit 1
fi
# add LIBCLANG_RT_LIB for ARM32
@ -184,4 +184,4 @@ fi
rm -rf tmp/
cd $ORIGINAL_PATH
cd $ORIGINAL_PATH || exit

View File

@ -20,6 +20,7 @@ import json
import os
import queue
import re
import shlex
import subprocess
from mindspore import log as logger
@ -186,7 +187,9 @@ def get_dependencies_of_file(headers_flag, filename):
:return: a list of file names [file0.cc, file1.h, file2.h, file3.h] and error string
"""
command = 'gcc -MM -MG {0} {1} {2}'.format(filename, DEFINE_STR, headers_flag)
stdout, stderr = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
command_split = shlex.split(command)
stdout, stderr = subprocess.Popen(command_split, shell=False, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
deps = re.split(r'[\s\\]+', stdout.decode('utf-8').strip(), flags=re.MULTILINE)[1:]
return deps, stderr.decode('utf-8')
@ -272,7 +275,7 @@ def get_all_dependencies_of_file(headers_flag, filename):
if needs_processing(dep_cc, processed_cc, queue_cc_set):
queue_cc.put(dep_cc)
queue_cc_set.add(dep_cc)
logger.debug('file: {} | deps: {}'.format(filename[filename.rfind('/') + 1:], len(processed_cc)))
logger.debug('file: {} | deps: {}'.format(os.path.basename(filename), len(processed_cc)))
return list(processed_cc), "".join(errors)