!13571 Added seed to prevent random failures in ut

From: @ezphlow
Reviewed-by: 
Signed-off-by:
pull/13571/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 0451a800bc

@ -275,8 +275,10 @@ int64_t Dataset::GetDatasetSize(bool estimate) {
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), -1);
std::shared_ptr<DatasetSizeGetter> size_getter = std::make_shared<DatasetSizeGetter>();
RETURN_SECOND_IF_ERROR(size_getter->Init(this->IRNode()), -1);
RETURN_SECOND_IF_ERROR(size_getter->GetDatasetSize(&dataset_size, estimate), -1);
DatasetSizeGetter *consumer = size_getter.get();
runtime_context->AssignConsumer(size_getter);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), -1);
RETURN_SECOND_IF_ERROR(consumer->GetDatasetSize(&dataset_size, estimate), -1);
return dataset_size;
}
@ -284,8 +286,10 @@ std::vector<mindspore::DataType> Dataset::GetOutputTypes() {
std::vector<DataType> types;
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), {});
RETURN_SECOND_IF_ERROR(tree_getters_->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(tree_getters_->GetOutputTypes(&types), {});
TreeGetters *consumer = tree_getters_.get();
runtime_context->AssignConsumer(tree_getters_);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(consumer->GetOutputTypes(&types), {});
std::vector<mindspore::DataType> ret_types;
std::transform(
types.begin(), types.end(), std::back_inserter(ret_types),
@ -297,8 +301,10 @@ std::vector<std::vector<int64_t>> Dataset::GetOutputShapes() {
std::vector<TensorShape> shapes;
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), {});
RETURN_SECOND_IF_ERROR(tree_getters_->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(tree_getters_->GetOutputShapes(&shapes), {});
TreeGetters *consumer = tree_getters_.get();
runtime_context->AssignConsumer(tree_getters_);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(consumer->GetOutputShapes(&shapes), {});
std::vector<std::vector<int64_t>> ret_shapes;
std::transform(shapes.begin(), shapes.end(), std::back_inserter(ret_shapes),
[](const TensorShape &s) -> std::vector<int64_t> { return s.AsVector(); });
@ -309,8 +315,10 @@ int64_t Dataset::GetNumClasses() {
int64_t num_classes;
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), -1);
RETURN_SECOND_IF_ERROR(tree_getters_->Init(this->IRNode()), -1);
RETURN_SECOND_IF_ERROR(tree_getters_->GetNumClasses(&num_classes), -1);
TreeGetters *consumer = tree_getters_.get();
runtime_context->AssignConsumer(tree_getters_);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), -1);
RETURN_SECOND_IF_ERROR(consumer->GetNumClasses(&num_classes), -1);
return num_classes;
}
@ -318,8 +326,10 @@ std::vector<std::vector<char>> Dataset::GetColumnNamesCharIF() {
std::vector<std::string> col_names;
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), {});
RETURN_SECOND_IF_ERROR(tree_getters_->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(tree_getters_->GetColumnNames(&col_names), {});
TreeGetters *consumer = tree_getters_.get();
runtime_context->AssignConsumer(tree_getters_);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(consumer->GetColumnNames(&col_names), {});
return VectorStringToChar(col_names);
}
@ -327,8 +337,10 @@ std::vector<std::pair<std::vector<char>, std::vector<int32_t>>> Dataset::GetClas
std::vector<std::pair<std::string, std::vector<int32_t>>> output_class_indexing;
std::unique_ptr<NativeRuntimeContext> runtime_context = std::make_unique<NativeRuntimeContext>();
RETURN_SECOND_IF_ERROR(runtime_context->Init(), {});
RETURN_SECOND_IF_ERROR(tree_getters_->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(tree_getters_->GetClassIndexing(&output_class_indexing), {});
TreeGetters *consumer = tree_getters_.get();
runtime_context->AssignConsumer(tree_getters_);
RETURN_SECOND_IF_ERROR(consumer->Init(this->IRNode()), {});
RETURN_SECOND_IF_ERROR(consumer->GetClassIndexing(&output_class_indexing), {});
return ClassIndexStringToChar(output_class_indexing);
}

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include "common/common.h"
#include "minddata/dataset/include/config.h"
#include "minddata/dataset/include/datasets.h"
#include "minddata/dataset/include/transforms.h"
#include "minddata/dataset/include/vision.h"
@ -840,6 +841,9 @@ TEST_F(MindDataTestPipeline, TestRandomResizeSuccess2) {
TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess1) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomResizeWithBBoxSuccess1 with single integer input.";
// setting seed here to prevent random core dump
uint32_t current_seed = config::get_seed();
config::set_seed(327362);
// Create an VOC Dataset
std::string folder_path = datasets_root_path_ + "/testVOC2012_2";
@ -873,14 +877,16 @@ TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess1) {
}
EXPECT_EQ(i, 3);
// Manually terminate the pipeline
iter->Stop();
config::set_seed(current_seed);
}
TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess2) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomResizeWithBBoxSuccess2 with (height, width) input.";
uint32_t current_seed = config::get_seed();
config::set_seed(327362);
// Create an VOC Dataset
std::string folder_path = datasets_root_path_ + "/testVOC2012_2";
std::shared_ptr<Dataset> ds =
@ -921,6 +927,7 @@ TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess2) {
// Manually terminate the pipeline
iter->Stop();
config::set_seed(current_seed);
}
TEST_F(MindDataTestPipeline, TestRandomResizedCropSuccess1) {
@ -1086,6 +1093,8 @@ TEST_F(MindDataTestPipeline, TestRandomResizedCropWithBBoxSuccess1) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomResizedCropWithBBoxSuccess1.";
// Testing RandomResizedCropWithBBox with default values
// Create an VOC Dataset
uint32_t current_seed = config::get_seed();
config::set_seed(327362);
std::string folder_path = datasets_root_path_ + "/testVOC2012_2";
std::shared_ptr<Dataset> ds =
VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 4));
@ -1118,6 +1127,7 @@ TEST_F(MindDataTestPipeline, TestRandomResizedCropWithBBoxSuccess1) {
EXPECT_EQ(i, 4);
config::set_seed(current_seed);
// Manually terminate the pipeline
iter->Stop();
}
@ -1127,6 +1137,8 @@ TEST_F(MindDataTestPipeline, TestRandomResizedCropWithBBoxSuccess2) {
// Testing RandomResizedCropWithBBox with non-default values
// Create an VOC Dataset
std::string folder_path = datasets_root_path_ + "/testVOC2012_2";
uint32_t current_seed = config::get_seed();
config::set_seed(327362);
std::shared_ptr<Dataset> ds =
VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 4));
EXPECT_NE(ds, nullptr);
@ -1158,6 +1170,7 @@ TEST_F(MindDataTestPipeline, TestRandomResizedCropWithBBoxSuccess2) {
}
EXPECT_EQ(i, 4);
config::set_seed(current_seed);
// Manually terminate the pipeline
iter->Stop();

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 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.
@ -65,6 +65,10 @@ TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp1) {
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp2.";
// setting seed here to prevent random core dump
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
TensorRow output_tensor_row_;
int h_out = 1024;
int w_out = 2048;
@ -78,6 +82,7 @@ TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp2) {
s = op->Compute(tensor_row_, &output_tensor_row_);
EXPECT_TRUE(s.IsOk());
}
GlobalContext::config_manager()->set_seed(current_seed);
}
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp3) {
@ -96,4 +101,4 @@ TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp3) {
EXPECT_TRUE(s.IsOk());
}
MS_LOG(INFO) << "testRandomCropAndResizeWithBBoxOp end.";
}
}

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 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.
@ -74,6 +74,10 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
// Crop params
unsigned int crop_height = 1280;
unsigned int crop_width = 1280;
// setting seed here to prevent random core dump
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, 513, 513, 513, 513, BorderType::kConstant, false));
@ -89,6 +93,7 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
EXPECT_EQ(4, output_tensor_row_[1]->shape()[1]); // check for existence of 4 columns
}
MS_LOG(INFO) << "testRandomCropWithBBoxOp2 end.";
GlobalContext::config_manager()->set_seed(current_seed);
}
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp3) {
@ -96,6 +101,10 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp3) {
// Crop params
unsigned int crop_height = 1280;
unsigned int crop_width = 1280;
// setting seed here to prevent random core dump
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, crop_height * 3 + 1,
crop_height * 3 + 1, crop_width * 3 + 1,
crop_width * 3 + 1, BorderType::kConstant, false));
@ -106,4 +115,5 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp3) {
ASSERT_TRUE(s.StatusCode() == StatusCode::kMDUnexpectedError);
}
MS_LOG(INFO) << "testRandomCropWithBBoxOp3 end.";
}
GlobalContext::config_manager()->set_seed(current_seed);
}

Loading…
Cancel
Save