parent
3cc9217f06
commit
506f8f134e
@ -0,0 +1,99 @@
|
|||||||
|
/**
|
||||||
|
* 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.";
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* 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.";
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* 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.";
|
||||||
|
}
|
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 230 KiB |
After Width: | Height: | Size: 80 KiB |
Loading…
Reference in new issue