提交 506f8f13 编写于 作者: D Danish Farid

fix, cpp ut's

fix cmakefile

fixed log statments in cpp UT tests
上级 3cc9217f
......@@ -760,10 +760,18 @@ Status UpdateBBoxesForCrop(std::shared_ptr<Tensor> *bboxList, size_t *bboxCount,
correct_ind.push_back(i);
// adjust BBox corners by bringing into new CropBox if beyond
// Also reseting/adjusting for boxes to lie within CropBox instead of Image - subtract CropBox Xmin/YMin
bb_Xmin = bb_Xmin - (std::min(static_cast<float>(0.0), (bb_Xmin - CB_Xmin)) + CB_Xmin);
bb_Xmax = bb_Xmax - (std::max(static_cast<float>(0.0), (bb_Xmax - CB_Xmax)) + CB_Xmin);
bb_Ymin = bb_Ymin - (std::min(static_cast<float>(0.0), (bb_Ymin - CB_Ymin)) + CB_Ymin);
bb_Ymax = bb_Ymax - (std::max(static_cast<float>(0.0), (bb_Ymax - CB_Ymax)) + CB_Ymin);
bb_Xmin = bb_Xmin - std::min(static_cast<float>(0.0), (bb_Xmin - CB_Xmin)) - CB_Xmin;
bb_Xmax = bb_Xmax - std::max(static_cast<float>(0.0), (bb_Xmax - CB_Xmax)) - CB_Xmin;
bb_Ymin = bb_Ymin - std::min(static_cast<float>(0.0), (bb_Ymin - CB_Ymin)) - CB_Ymin;
bb_Ymax = bb_Ymax - std::max(static_cast<float>(0.0), (bb_Ymax - CB_Ymax)) - CB_Ymin;
// bound check for float values
bb_Xmin = std::max(bb_Xmin, static_cast<float>(0));
bb_Ymin = std::max(bb_Ymin, static_cast<float>(0));
bb_Xmax = std::min(bb_Xmax, static_cast<float>(CB_Xmax - CB_Xmin)); // find max value relative to new image
bb_Ymax = std::min(bb_Ymax, static_cast<float>(CB_Ymax - CB_Ymin));
// reset min values and calculate width/height from Box corners
RETURN_IF_NOT_OK((*bboxList)->SetItemAt({i, 0}, bb_Xmin));
RETURN_IF_NOT_OK((*bboxList)->SetItemAt({i, 1}, bb_Ymin));
......
......@@ -36,14 +36,17 @@ SET(DE_UT_SRCS
project_op_test.cc
queue_test.cc
random_crop_op_test.cc
random_crop_with_bbox_op_test.cc
random_crop_decode_resize_op_test.cc
random_crop_and_resize_op_test.cc
random_crop_and_resize_with_bbox_op_test.cc
random_color_adjust_op_test.cc
random_horizontal_flip_op_test.cc
random_horizontal_flip_with_bbox_test.cc
random_resize_op_test.cc
random_rotation_op_test.cc
random_vertical_flip_op_test.cc
random_vertical_flip_with_bbox_op_test.cc
rename_op_test.cc
repeat_op_test.cc
skip_op_test.cc
......
/**
* 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/bboxop_common.h"
#include "dataset/kernels/image/random_crop_and_resize_with_bbox_op.h"
#include "utils/log_adapter.h"
#include "dataset/core/config_manager.h"
#include "dataset/core/global_context.h"
using namespace mindspore::dataset;
using mindspore::LogStream;
using mindspore::ExceptionType::NoExceptionType;
using mindspore::MsLogLevel::INFO;
const bool kSaveExpected = false;
const char kOpName[] = "RandomResizedCropWithBBox_C";
class MindDataTestRandomCropAndResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
protected:
MindDataTestRandomCropAndResizeWithBBoxOp() : BBoxOpCommon() {}
};
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp1.";
// setting seed here
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
TensorRow output_tensor_row_;
TensorTable results;
int h_out = 1024;
int w_out = 2048;
float aspect_lb = 2;
float aspect_ub = 2.5;
float scale_lb = 0.2;
float scale_ub = 2.0;
auto op = std::make_unique<RandomCropAndResizeWithBBoxOp>(h_out, w_out, scale_lb, scale_ub, aspect_lb, aspect_ub);
Status s;
for (auto tensor_row_ : images_and_annotations_) {
s = op->Compute(tensor_row_, &output_tensor_row_);
EXPECT_TRUE(s.IsOk());
results.push_back(output_tensor_row_);
}
if (kSaveExpected) {
SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results);
}
SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results);
if (!kSaveExpected) {
CompareActualAndExpected(std::string(kOpName));
}
GlobalContext::config_manager()->set_seed(current_seed);
}
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp2.";
TensorRow output_tensor_row_;
int h_out = 1024;
int w_out = 2048;
float aspect_lb = 1;
float aspect_ub = 1.5;
float scale_lb = 0.2;
float scale_ub = 2.0;
auto op = std::make_unique<RandomCropAndResizeWithBBoxOp>(h_out, w_out, scale_lb, scale_ub, aspect_lb, aspect_ub);
Status s;
for (auto tensor_row_ : images_and_annotations_) {
s = op->Compute(tensor_row_, &output_tensor_row_);
EXPECT_TRUE(s.IsOk());
}
}
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp3) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp3.";
TensorRow output_tensor_row_;
int h_out = 1024;
int w_out = 2048;
float aspect_lb = 0.2;
float aspect_ub = 3;
float scale_lb = 0.2;
float scale_ub = 2.0;
auto op = std::make_unique<RandomCropAndResizeWithBBoxOp>(h_out, w_out, scale_lb, scale_ub, aspect_lb, aspect_ub);
Status s;
for (auto tensor_row_ : images_and_annotations_) {
s = op->Compute(tensor_row_, &output_tensor_row_);
EXPECT_TRUE(s.IsOk());
}
MS_LOG(INFO) << "testRandomCropAndResizeWithBBoxOp end.";
}
\ No newline at end of file
/**
* 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/bboxop_common.h"
#include "dataset/kernels/image/random_crop_with_bbox_op.h"
#include "utils/log_adapter.h"
#include "dataset/core/config_manager.h"
#include "dataset/core/global_context.h"
using namespace mindspore::dataset;
using mindspore::LogStream;
using mindspore::ExceptionType::NoExceptionType;
using mindspore::MsLogLevel::INFO;
const bool kSaveExpected = false;
const char kOpName[] = "RandomCropWithBBox_C";
class MindDataTestRandomCropWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
protected:
MindDataTestRandomCropWithBBoxOp() : BBoxOpCommon() {}
TensorRow output_tensor_row_;
};
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomCropWithBBoxOp1.";
TensorTable results;
unsigned int crop_height = 128;
unsigned int crop_width = 128;
// setting seed here
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
std::unique_ptr<RandomCropWithBBoxOp> op(
new RandomCropWithBBoxOp(crop_height, crop_width, 0, 0, 0, 0, BorderType::kConstant, false));
for (auto tensor_row_ : images_and_annotations_) {
Status s = op->Compute(tensor_row_, &output_tensor_row_);
size_t actual = 0;
if (s == Status::OK()) {
TensorShape get_shape = output_tensor_row_[0]->shape();
actual = get_shape[0] * get_shape[1] * get_shape[2];
results.push_back(output_tensor_row_);
}
EXPECT_EQ(actual, crop_height * crop_width * 3);
EXPECT_EQ(s, Status::OK());
EXPECT_EQ(4, output_tensor_row_[1]->shape()[1]); // check for existence of 4 columns
// Compare Code
if (kSaveExpected) {
SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results);
}
SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results);
if (!kSaveExpected) {
CompareActualAndExpected(std::string(kOpName));
}
GlobalContext::config_manager()->set_seed(current_seed);
}
}
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCropWithBBoxOp2.";
// Crop params
unsigned int crop_height = 1280;
unsigned int crop_width = 1280;
std::unique_ptr<RandomCropWithBBoxOp> op(
new RandomCropWithBBoxOp(crop_height, crop_width, 513, 513, 513, 513, BorderType::kConstant, false));
for (auto tensor_row_ : images_and_annotations_) {
Status s = op->Compute(tensor_row_, &output_tensor_row_);
size_t actual = 0;
if (s == Status::OK()) {
TensorShape get_shape = output_tensor_row_[0]->shape();
actual = get_shape[0] * get_shape[1] * get_shape[2];
}
EXPECT_EQ(actual, crop_height * crop_width * 3);
EXPECT_EQ(s, Status::OK());
EXPECT_EQ(4, output_tensor_row_[1]->shape()[1]); // check for existence of 4 columns
}
MS_LOG(INFO) << "testRandomCropWithBBoxOp end.";
}
/**
* 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/bboxop_common.h"
#include "dataset/kernels/image/random_vertical_flip_with_bbox_op.h"
#include "utils/log_adapter.h"
using namespace mindspore::dataset;
using mindspore::LogStream;
using mindspore::ExceptionType::NoExceptionType;
using mindspore::MsLogLevel::INFO;
const bool kSaveExpected = false;
const char kOpName[] = "RandomVerticalFlipWithBBox_C";
class MindDataTestRandomVerticalFlipWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
protected:
MindDataTestRandomVerticalFlipWithBBoxOp() : BBoxOpCommon() {}
};
TEST_F(MindDataTestRandomVerticalFlipWithBBoxOp, TestOp) {
MS_LOG(INFO) << "Doing testRandomVerticalFlipWithBBoxOp.";
TensorTable results;
std::unique_ptr<RandomVerticalFlipWithBBoxOp> op(new RandomVerticalFlipWithBBoxOp(1));
for (const auto &tensor_row_ : images_and_annotations_) {
TensorRow output_row;
Status s = op->Compute(tensor_row_, &output_row);
EXPECT_TRUE(s.IsOk());
results.push_back(output_row);
}
if (kSaveExpected) {
SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results);
}
SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results);
if (!kSaveExpected) {
CompareActualAndExpected(std::string(kOpName));
}
MS_LOG(INFO) << "testRandomVerticalFlipWithBBoxOp end.";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册