Browse Source

fix warnings for master

tags/v1.3.0
mohammad 4 years ago
parent
commit
37d970898e
5 changed files with 30 additions and 20 deletions
  1. +9
    -4
      mindspore/ccsrc/minddata/dataset/core/tensor.cc
  2. +6
    -5
      mindspore/ccsrc/minddata/dataset/core/tensor_helpers.cc
  3. +6
    -4
      mindspore/ccsrc/minddata/dataset/kernels/image/cutmix_batch_op.cc
  4. +4
    -4
      mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc
  5. +5
    -3
      mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.cc

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

@@ -934,23 +934,28 @@ Status Tensor::GetSliceOption(const SliceOption &slice_option, const int32_t &sl
Status Tensor::Slice(std::shared_ptr<Tensor> *out, const std::vector<SliceOption> slice_options_) {
std::vector<SliceOption> converted_slice_objects;

for (int k = 0; k < slice_options_.size(); k++) {
CHECK_FAIL_RETURN_UNEXPECTED(slice_options_.size() <= static_cast<size_t>(std::numeric_limits<dsize_t>::max()),
"The size of slice_options_ must not be more than \"INT64_MAX\".");
for (size_t k = 0; k < slice_options_.size(); k++) {
SliceOption slice_option = slice_options_[k];

if (slice_option.all_) {
mindspore::dataset::Slice slice = mindspore::dataset::Slice(shape_[k]);
mindspore::dataset::Slice slice = mindspore::dataset::Slice(shape_[static_cast<dsize_t>(k)]);
converted_slice_objects.push_back(SliceOption(slice));
continue;
}

CHECK_FAIL_RETURN_UNEXPECTED(k <= static_cast<size_t>(std::numeric_limits<int32_t>::max()),
"GetSliceOption() can't function properly if there are "
"more than \"INT32_MAX\" slice options");
SliceOption slice_option_item(false);
RETURN_IF_NOT_OK(GetSliceOption(slice_option, k, &slice_option_item));
RETURN_IF_NOT_OK(GetSliceOption(slice_option, static_cast<int32_t>(k), &slice_option_item));
converted_slice_objects.emplace_back(slice_option_item);
}

// partial slices, pass in the rest
if (slice_options_.size() != Rank()) {
for (int j = slice_options_.size(); j < Rank(); j++) {
for (dsize_t j = static_cast<dsize_t>(slice_options_.size()); j < Rank(); j++) {
mindspore::dataset::Slice slice = mindspore::dataset::Slice(0, shape_[j]);
converted_slice_objects.emplace_back(SliceOption(slice));
}


+ 6
- 5
mindspore/ccsrc/minddata/dataset/core/tensor_helpers.cc View File

@@ -25,27 +25,28 @@ void IndexGeneratorHelper(int8_t depth, std::vector<dsize_t> *numbers,
std::vector<std::vector<dsize_t>> *matrix) {
// for loop changes if its an index instead of a slice object
if (depth > 0) {
dsize_t new_depth = depth - 1;
dsize_t curr_ind = numbers->size() - depth;
int8_t new_depth = depth - 1;
// depth is always less than or equal to numbers->size() (based on the caller functions)
size_t curr_ind = static_cast<size_t>(numbers->size() - static_cast<size_t>(depth));

if (slice_list[curr_ind].slice_.valid()) {
dsize_t increment = slice_list[curr_ind].slice_.step_;

if (increment > 0) {
for (int i = slice_list[curr_ind].slice_.start_; i < slice_list[curr_ind].slice_.stop_;
for (dsize_t i = slice_list[curr_ind].slice_.start_; i < slice_list[curr_ind].slice_.stop_;
i = i + slice_list[curr_ind].slice_.step_) {
(*numbers)[curr_ind] = i;
IndexGeneratorHelper(new_depth, numbers, slice_list, matrix);
}
} else {
for (int j = slice_list[curr_ind].slice_.start_; j > slice_list[curr_ind].slice_.stop_;
for (dsize_t j = slice_list[curr_ind].slice_.start_; j > slice_list[curr_ind].slice_.stop_;
j = j + slice_list[curr_ind].slice_.step_) {
(*numbers)[curr_ind] = j;
IndexGeneratorHelper(new_depth, numbers, slice_list, matrix);
}
}
} else {
for (int k = 0; k < slice_list[curr_ind].indices_.size(); k++) {
for (size_t k = 0; k < slice_list[curr_ind].indices_.size(); k++) {
(*numbers)[curr_ind] = slice_list[curr_ind].indices_[k];
IndexGeneratorHelper(new_depth, numbers, slice_list, matrix);
}


+ 6
- 4
mindspore/ccsrc/minddata/dataset/kernels/image/cutmix_batch_op.cc View File

@@ -178,7 +178,9 @@ Status CutMixBatchOp::Compute(const TensorRow &input, TensorRow *output) {

// Calculate random labels
std::vector<int64_t> rand_indx;
for (int64_t i = 0; i < images.size(); i++) rand_indx.push_back(i);
CHECK_FAIL_RETURN_UNEXPECTED(images.size() <= static_cast<size_t>(std::numeric_limits<int64_t>::max()),
"The size of \"images\" must not be more than \"INT64_MAX\".");
for (int64_t idx = 0; idx < static_cast<int64_t>(images.size()); idx++) rand_indx.push_back(idx);
std::shuffle(rand_indx.begin(), rand_indx.end(), rnd_);
std::gamma_distribution<float> gamma_distribution(alpha_, 1);
std::uniform_real_distribution<double> uniform_distribution(0.0, 1.0);
@@ -190,7 +192,7 @@ Status CutMixBatchOp::Compute(const TensorRow &input, TensorRow *output) {
int64_t num_classes = label_shape.size() == value_three ? label_shape[dimension_two] : label_shape[1];

// Compute labels and images
for (int64_t i = 0; i < image_shape[0]; i++) {
for (size_t i = 0; i < static_cast<size_t>(image_shape[0]); i++) {
// Calculating lambda
// If x1 is a random variable from Gamma(a1, 1) and x2 is a random variable from Gamma(a2, 1)
// then x = x1 / (x1+x2) is a random variable from Beta(a1, a2)
@@ -203,8 +205,8 @@ Status CutMixBatchOp::Compute(const TensorRow &input, TensorRow *output) {
// Compute image
RETURN_IF_NOT_OK(ComputeImage(input, rand_indx[i], lam, &label_lam, &images[i]));
// Compute labels
RETURN_IF_NOT_OK(
ComputeLabel(input, rand_indx[i], i, row_labels, num_classes, label_shape.size(), label_lam, &out_labels));
RETURN_IF_NOT_OK(ComputeLabel(input, rand_indx[i], static_cast<int64_t>(i), row_labels, num_classes,
label_shape.size(), label_lam, &out_labels));
}
}



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

@@ -442,8 +442,8 @@ Status HwcToChw(std::shared_ptr<Tensor> input, std::shared_ptr<Tensor> *output)
return Status::OK();
}
int num_channels = input_cv->shape()[CHANNEL_INDEX];
if (input_cv->shape().Size() < 2 || input_cv->shape().Size() > 3 ||
(input_cv->shape().Size() == 3 && num_channels != DEFAULT_IMAGE_CHANNELS &&
if (input_cv->shape().Size() < MIN_IMAGE_DIMENSION || input_cv->shape().Size() > DEFAULT_IMAGE_CHANNELS ||
(input_cv->shape().Size() == DEFAULT_IMAGE_CHANNELS && num_channels != DEFAULT_IMAGE_CHANNELS &&
num_channels != MIN_IMAGE_CHANNELS)) {
RETURN_STATUS_UNEXPECTED("HWC2CHW: image shape is not <H,W,C>.");
}
@@ -507,12 +507,12 @@ Status MaskWithTensor(const std::shared_ptr<Tensor> &sub_mat, std::shared_ptr<Te
}
}
} else if (image_format == ImageFormat::HW) {
if ((*input)->Rank() != 2) {
if ((*input)->Rank() != MIN_IMAGE_DIMENSION) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"input shape doesn't match <H,W> format.");
}
if (sub_mat->Rank() != 2) {
if (sub_mat->Rank() != MIN_IMAGE_DIMENSION) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"sub_mat shape doesn't match <H,W> format.");


+ 5
- 3
mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.cc View File

@@ -39,7 +39,9 @@ MixUpBatchOp::MixUpBatchOp(float alpha) : alpha_(alpha) { rnd_.seed(GetSeed());
Status MixUpBatchOp::ComputeLabels(const TensorRow &input, std::shared_ptr<Tensor> *out_labels,
std::vector<int64_t> *rand_indx, const std::vector<int64_t> &label_shape,
const float lam, const size_t images_size) {
for (int64_t i = 0; i < images_size; i++) rand_indx->push_back(i);
CHECK_FAIL_RETURN_UNEXPECTED(images_size <= static_cast<size_t>(std::numeric_limits<int64_t>::max()),
"The \"images_size\" must not be more than \"INT64_MAX\".");
for (int64_t i = 0; i < static_cast<int64_t>(images_size); i++) rand_indx->push_back(i);
std::shuffle(rand_indx->begin(), rand_indx->end(), rnd_);

RETURN_IF_NOT_OK(TypeCast(std::move(input.at(1)), out_labels, DataType(DataType::DE_FLOAT32)));
@@ -53,8 +55,8 @@ Status MixUpBatchOp::ComputeLabels(const TensorRow &input, std::shared_ptr<Tenso
std::vector<int64_t> first_index =
label_shape.size() == kMaxLabelShapeSize ? std::vector{i, j, k} : std::vector{i, k};
std::vector<int64_t> second_index = label_shape.size() == kMaxLabelShapeSize
? std::vector{(*rand_indx)[i], j, k}
: std::vector{(*rand_indx)[i], k};
? std::vector{(*rand_indx)[static_cast<size_t>(i)], j, k}
: std::vector{(*rand_indx)[static_cast<size_t>(i)], k};
if (input.at(1)->type().IsSignedInt()) {
int64_t first_value, second_value;
RETURN_IF_NOT_OK(input.at(1)->GetItemAt(&first_value, first_index));


Loading…
Cancel
Save