fix asan issue

This commit is contained in:
liyong 2021-03-29 14:14:44 +08:00
parent 006c38e2b8
commit d5b7a67c71
6 changed files with 14 additions and 12 deletions

View File

@ -232,7 +232,8 @@ std::vector<dsize_t> TensorShape::Strides() const { return std::vector<dsize_t>{
Status TensorShape::ToFlatIndex(const std::vector<dsize_t> &index, dsize_t *flat_index) const {
*flat_index = 0;
for (size_t k = 0; k < index.size(); k++) {
*flat_index += index[k] * strides_[k + 1]; // skip the first element of strides_ which is numOfElements
*flat_index +=
(index[k] == 0) ? 0 : index[k] * strides_[k + 1]; // skip the first element of strides_ which is numOfElements
}
CHECK_FAIL_RETURN_UNEXPECTED(*flat_index < NumOfElements(), "Not a valid index");
return Status::OK();

View File

@ -394,8 +394,10 @@ Status Crop(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outpu
}
try {
TensorShape shape{h, w};
if (input_cv->Rank() == 3) {
int num_channels = input_cv->shape()[2];
if (input_cv->Rank() == 3) shape = shape.AppendDim(num_channels);
shape = shape.AppendDim(num_channels);
}
std::shared_ptr<CVTensor> output_cv;
RETURN_IF_NOT_OK(CVTensor::CreateEmpty(shape, input_cv->type(), &output_cv));
cv::Rect roi(x, y, w, h);

View File

@ -1581,13 +1581,11 @@ bool GetPerspectiveTransform(std::vector<Point> src_point, std::vector<Point> ds
n[i + 4] = dst_point[i].y;
}
double x[9] = {0};
LiteMat dst(1, 8, x, LDataType(LDataType::DOUBLE));
M.Init(3, 3, LDataType(LDataType::DOUBLE));
LiteMat dst(1, 8, M.data_ptr_, LDataType(LDataType::DOUBLE));
GetPerspectiveTransformImpl(src1, src2, dst);
dst.ptr<double>(8)[0] = 1;
M.Init(3, 3, dst.data_ptr_, dst.data_type_);
return true;
}

View File

@ -1129,12 +1129,12 @@ Status RandomRotationOperation::ValidateParams() {
MS_LOG(ERROR) << "RandomRotation: degrees must be a vector of one or two values, got: " << degrees_;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if ((degrees_[1] < degrees_[0]) && (degrees_.size() == 2)) {
if ((degrees_.size() == 2) && (degrees_[1] < degrees_[0])) {
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]) + ")";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
} else if ((degrees_[0] < 0) && degrees_.size() == 1) {
} else if ((degrees_.size() == 1) && (degrees_[0] < 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]);

View File

@ -239,8 +239,7 @@ TEST_F(MindDataImageProcess, testNV21ToBGR) {
bool ret = ReadYUV(filename, w, h, &yuv_data);
ASSERT_TRUE(ret == true);
cv::Mat yuvimg(h * 3 / 2, w, CV_8UC1);
memcpy(yuvimg.data, yuv_data, w * h * 3 / 2);
cv::Mat yuvimg(h * 3 / 2, w, CV_8UC1, yuv_data);
cv::Mat rgbimage;
cv::cvtColor(yuvimg, rgbimage, cv::COLOR_YUV2BGR_NV21);
@ -250,6 +249,7 @@ TEST_F(MindDataImageProcess, testNV21ToBGR) {
ret = InitFromPixel(yuv_data, LPixelType::NV212BGR, LDataType::UINT8, w, h, lite_mat_bgr);
ASSERT_TRUE(ret == true);
cv::Mat dst_image(lite_mat_bgr.height_, lite_mat_bgr.width_, CV_8UC3, lite_mat_bgr.data_ptr_);
free(yuv_data);
}
TEST_F(MindDataImageProcess, testNV12ToBGR) {
@ -270,6 +270,7 @@ TEST_F(MindDataImageProcess, testNV12ToBGR) {
ret = InitFromPixel(yuv_data, LPixelType::NV122BGR, LDataType::UINT8, w, h, lite_mat_bgr);
ASSERT_TRUE(ret == true);
cv::Mat dst_image(lite_mat_bgr.height_, lite_mat_bgr.width_, CV_8UC3, lite_mat_bgr.data_ptr_);
free(yuv_data);
}
TEST_F(MindDataImageProcess, testExtractChannel) {

View File

@ -93,7 +93,7 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPassPreBuiltTensorO
// make prebuilt tensor operation
auto decode = std::make_shared<transforms::PreBuiltOperation>(vision::DecodeOperation(true).Build());
auto resize = std::make_shared<transforms::PreBuiltOperation>(
vision::RandomResizedCropOperation({100}, {0.5}, {0.1}, InterpolationMode::kNearestNeighbour, 5).Build());
vision::RandomResizedCropOperation({100, 100}, {0.5, 1.0}, {0.1, 0.2}, InterpolationMode::kNearestNeighbour, 5).Build());
std::vector<std::shared_ptr<TensorOperation>> op_list = {decode, resize};
std::vector<std::string> op_name = {"image"};
std::shared_ptr<DatasetNode> root = ImageFolder(folder_path, false)->IRNode();