diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index 6e7f34844e..f371c9262c 100644 --- a/mindspore/ccsrc/minddata/dataset/api/datasets.cc +++ b/mindspore/ccsrc/minddata/dataset/api/datasets.cc @@ -275,8 +275,10 @@ int64_t Dataset::GetDatasetSize(bool estimate) { std::unique_ptr runtime_context = std::make_unique(); RETURN_SECOND_IF_ERROR(runtime_context->Init(), -1); std::shared_ptr size_getter = std::make_shared(); - 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 Dataset::GetOutputTypes() { std::vector types; std::unique_ptr runtime_context = std::make_unique(); 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 ret_types; std::transform( types.begin(), types.end(), std::back_inserter(ret_types), @@ -297,8 +301,10 @@ std::vector> Dataset::GetOutputShapes() { std::vector shapes; std::unique_ptr runtime_context = std::make_unique(); 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> ret_shapes; std::transform(shapes.begin(), shapes.end(), std::back_inserter(ret_shapes), [](const TensorShape &s) -> std::vector { return s.AsVector(); }); @@ -309,8 +315,10 @@ int64_t Dataset::GetNumClasses() { int64_t num_classes; std::unique_ptr runtime_context = std::make_unique(); 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> Dataset::GetColumnNamesCharIF() { std::vector col_names; std::unique_ptr runtime_context = std::make_unique(); 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::vector>> Dataset::GetClas std::vector>> output_class_indexing; std::unique_ptr runtime_context = std::make_unique(); 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); } diff --git a/tests/ut/cpp/dataset/c_api_vision_random_test.cc b/tests/ut/cpp/dataset/c_api_vision_random_test.cc index 59d13d6ef1..9837b6ac0e 100644 --- a/tests/ut/cpp/dataset/c_api_vision_random_test.cc +++ b/tests/ut/cpp/dataset/c_api_vision_random_test.cc @@ -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 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 ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared(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 ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared(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(); diff --git a/tests/ut/cpp/dataset/random_crop_and_resize_with_bbox_op_test.cc b/tests/ut/cpp/dataset/random_crop_and_resize_with_bbox_op_test.cc index b30184d1d2..bc5190a1d4 100644 --- a/tests/ut/cpp/dataset/random_crop_and_resize_with_bbox_op_test.cc +++ b/tests/ut/cpp/dataset/random_crop_and_resize_with_bbox_op_test.cc @@ -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."; -} \ No newline at end of file +} diff --git a/tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc b/tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc index 201de384c9..4089f63163 100644 --- a/tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc +++ b/tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc @@ -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 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 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."; -} \ No newline at end of file + GlobalContext::config_manager()->set_seed(current_seed); +}