Browse Source

!6123 [MD] fix bug in normalize op

Merge pull request !6123 from liyong126/fix_bug_normalize
tags/v1.0.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
2b9a8422ba
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc

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

@@ -592,15 +592,18 @@ Status Normalize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *
try {
// NOTE: We are assuming the input image is in RGB and the mean
// and std are in RGB
cv::Mat rgb[3];
std::vector<cv::Mat> rgb;
cv::split(in_image, rgb);
if (rgb.size() != 3) {
RETURN_STATUS_UNEXPECTED("Input image is not in RGB.");
}
for (uint8_t i = 0; i < 3; i++) {
float mean_c, std_c;
RETURN_IF_NOT_OK(mean->GetItemAt<float>(&mean_c, {i}));
RETURN_IF_NOT_OK(std->GetItemAt<float>(&std_c, {i}));
rgb[i].convertTo(rgb[i], CV_32F, 1.0 / std_c, (-mean_c / std_c));
}
cv::merge(rgb, 3, output_cv->mat());
cv::merge(rgb, output_cv->mat());
*output = std::static_pointer_cast<Tensor>(output_cv);
return Status::OK();
} catch (const cv::Exception &e) {


Loading…
Cancel
Save