From: @cathwong Reviewed-by: @robingrosman,@liucunwei Signed-off-by: @robingrosmantags/v1.2.0-rc1
| @@ -48,16 +48,18 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetAFQMC) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| // std::vector<std::string> expected_result = {"蚂蚁借呗等额还款能否换成先息后本", "蚂蚁花呗说我违约了", | |||
| // "帮我看看本月花呗账单结清了没"}; | |||
| std::vector<std::string> expected_result = {"蚂蚁借呗等额还款能否换成先息后本", "蚂蚁花呗说我违约了", | |||
| "帮我看看本月花呗账单结清了没"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -71,7 +73,7 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetAFQMC) { | |||
| // test | |||
| usage = "test"; | |||
| // expected_result = {"借呗取消的时间", "网商贷用什么方法转变成借呗", "我的借呗为什么开通不了"}; | |||
| expected_result = {"借呗取消的时间", "网商贷用什么方法转变成借呗", "我的借呗为什么开通不了"}; | |||
| ds = CLUE({test_file}, task, usage, 0, ShuffleMode::kFalse); | |||
| EXPECT_NE(ds, nullptr); | |||
| iter = ds->CreateIterator(); | |||
| @@ -80,11 +82,13 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetAFQMC) { | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| auto text = row["sentence1"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -92,7 +96,7 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetAFQMC) { | |||
| // eval | |||
| usage = "eval"; | |||
| // expected_result = {"你有花呗吗", "吃饭能用花呗吗", "蚂蚁花呗支付金额有什么限制"}; | |||
| expected_result = {"你有花呗吗", "吃饭能用花呗吗", "蚂蚁花呗支付金额有什么限制"}; | |||
| ds = CLUE({eval_file}, task, usage, 0, ShuffleMode::kFalse); | |||
| EXPECT_NE(ds, nullptr); | |||
| iter = ds->CreateIterator(); | |||
| @@ -101,11 +105,13 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetAFQMC) { | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| auto text = row["sentence1"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -238,15 +244,17 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetCMNLI) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| // std::vector<std::string> expected_result = {"你应该给这件衣服定一个价格。", "我怎么知道他要说什么", "向左。"}; | |||
| std::vector<std::string> expected_result = {"你应该给这件衣服定一个价格。", "我怎么知道他要说什么", "向左。"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -279,15 +287,17 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetCSL) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("abst"), row.end()); | |||
| // std::vector<std::string> expected_result = {"这是一段长文本", "这是一段长文本", "这是一段长文本"}; | |||
| std::vector<std::string> expected_result = {"这是一段长文本", "这是一段长文本", "这是一段长文本"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["abst"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -420,15 +430,17 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetIFLYTEK) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence"), row.end()); | |||
| // std::vector<std::string> expected_result = {"第一个文本", "第二个文本", "第三个文本"}; | |||
| std::vector<std::string> expected_result = {"第一个文本", "第二个文本", "第三个文本"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["sentence"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -475,22 +487,24 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetShuffleFilesA) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| // std::vector<std::string> expected_result = {"你有花呗吗", | |||
| // "吃饭能用花呗吗", | |||
| // "蚂蚁花呗支付金额有什么限制", | |||
| // "蚂蚁借呗等额还款能否换成先息后本", | |||
| // "蚂蚁花呗说我违约了", | |||
| // "帮我看看本月花呗账单结清了没"}; | |||
| std::vector<std::string> expected_result = {"你有花呗吗", | |||
| "吃饭能用花呗吗", | |||
| "蚂蚁花呗支付金额有什么限制", | |||
| "蚂蚁借呗等额还款能否换成先息后本", | |||
| "蚂蚁花呗说我违约了", | |||
| "帮我看看本月花呗账单结清了没"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| auto text = row["sentence1"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -540,21 +554,23 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetShuffleFilesB) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| // std::vector<std::string> expected_result = {"你有花呗吗", | |||
| // "吃饭能用花呗吗", | |||
| // "蚂蚁花呗支付金额有什么限制", | |||
| // "蚂蚁借呗等额还款能否换成先息后本", | |||
| // "蚂蚁花呗说我违约了", | |||
| // "帮我看看本月花呗账单结清了没"}; | |||
| std::vector<std::string> expected_result = {"你有花呗吗", | |||
| "吃饭能用花呗吗", | |||
| "蚂蚁花呗支付金额有什么限制", | |||
| "蚂蚁借呗等额还款能否换成先息后本", | |||
| "蚂蚁花呗说我违约了", | |||
| "帮我看看本月花呗账单结清了没"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| auto text = row["sentence1"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -598,15 +614,17 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetShuffleGlobal) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence1"), row.end()); | |||
| // std::vector<std::string> expected_result = {"蚂蚁花呗说我违约了", "帮我看看本月花呗账单结清了没", | |||
| // "蚂蚁借呗等额还款能否换成先息后本"}; | |||
| std::vector<std::string> expected_result = {"蚂蚁花呗说我违约了", "帮我看看本月花呗账单结清了没", | |||
| "蚂蚁借呗等额还款能否换成先息后本"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["sentence1"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| @@ -643,15 +661,17 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetTNEWS) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("sentence"), row.end()); | |||
| // std::vector<std::string> expected_result = {"新闻1", "新闻2", "新闻3"}; | |||
| std::vector<std::string> expected_result = {"新闻1", "新闻2", "新闻3"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["sentence"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -684,16 +704,18 @@ TEST_F(MindDataTestPipeline, TestCLUEDatasetWSC) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("text"), row.end()); | |||
| // std::vector<std::string> expected_result = {"小明呢,他在哪?", "小红刚刚看到小明,他在操场", | |||
| // "等小明回来,小张你叫他交作业"}; | |||
| std::vector<std::string> expected_result = {"小明呢,他在哪?", "小红刚刚看到小明,他在操场", | |||
| "等小明回来,小张你叫他交作业"}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -329,8 +329,7 @@ TEST_F(MindDataTestPipeline, TestCocoPanoptic) { | |||
| EXPECT_MSTENSOR_EQ(bbox, expect_bbox); | |||
| std::shared_ptr<Tensor> de_expect_categoryid; | |||
| ASSERT_OK( | |||
| Tensor::CreateFromVector(expect_categoryid_vector[i], TensorShape({bbox_size, 1}), &de_expect_categoryid)); | |||
| ASSERT_OK(Tensor::CreateFromVector(expect_categoryid_vector[i], TensorShape({bbox_size, 1}), &de_expect_categoryid)); | |||
| mindspore::MSTensor expect_categoryid = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_categoryid)); | |||
| EXPECT_MSTENSOR_EQ(category_id, expect_categoryid); | |||
| @@ -420,8 +419,7 @@ TEST_F(MindDataTestPipeline, TestCocoStuff) { | |||
| EXPECT_MSTENSOR_EQ(image, expect_image); | |||
| std::shared_ptr<Tensor> de_expect_segmentation; | |||
| ASSERT_OK( | |||
| Tensor::CreateFromVector(expect_segmentation_vector[i], TensorShape(expect_size[i]), &de_expect_segmentation)); | |||
| ASSERT_OK(Tensor::CreateFromVector(expect_segmentation_vector[i], TensorShape(expect_size[i]), &de_expect_segmentation)); | |||
| mindspore::MSTensor expect_segmentation = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_segmentation)); | |||
| EXPECT_MSTENSOR_EQ(segmentation, expect_segmentation); | |||
| @@ -132,18 +132,21 @@ TEST_F(MindDataTestPipeline, TestShuffleWithSeed) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("text"), row.end()); | |||
| // std::vector<std::string> expected_result = {"Good luck to everyone.", "Be happy every day.", "This is a text | |||
| // file."}; | |||
| std::vector<std::string> expected_result = {"Good luck to everyone.", "Be happy every day.", "This is a text file."}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["text"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| auto text = row["text"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -194,22 +197,26 @@ TEST_F(MindDataTestPipeline, TestCallShuffleTwice) { | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("text"), row.end()); | |||
| // std::vector<std::string> first_copy; | |||
| // std::vector<std::string> second_copy; | |||
| std::vector<std::string> first_copy; | |||
| std::vector<std::string> second_copy; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto text = row["text"]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| auto text = row["text"]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // The first three samples are the first copy and the rest are the second | |||
| // if (i < 3) { | |||
| // first_copy.push_back(ss); | |||
| // } else { | |||
| // second_copy.push_back(ss); | |||
| // } | |||
| if (i < 3) { | |||
| first_copy.push_back(ss); | |||
| } else { | |||
| second_copy.push_back(ss); | |||
| } | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -218,9 +225,9 @@ TEST_F(MindDataTestPipeline, TestCallShuffleTwice) { | |||
| EXPECT_EQ(i, 6); | |||
| // Compare the two copies which are deterministic difference | |||
| // for (int j = 0; j < 3; j++) { | |||
| // EXPECT_STRNE(first_copy.at(j).c_str(), second_copy.at(j).c_str()); | |||
| // } | |||
| for (int j = 0; j < 3; j++) { | |||
| EXPECT_STRNE(first_copy.at(j).c_str(), second_copy.at(j).c_str()); | |||
| } | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -44,21 +44,23 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetBasic) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"1", "2", "3", "4"}, | |||
| // {"5", "6", "7", "8"}, | |||
| // {"9", "10", "11", "12"}, | |||
| // }; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"1", "2", "3", "4"}, | |||
| {"5", "6", "7", "8"}, | |||
| {"9", "10", "11", "12"}, | |||
| }; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -109,20 +111,22 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetMultiFiles) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"17", "18", "19", "20"}, {"1", "2", "3", "4"}, {"5", "6", "7", "8"}, | |||
| // {"13", "14", "15", "16"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| // }; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"17", "18", "19", "20"}, {"1", "2", "3", "4"}, {"5", "6", "7", "8"}, | |||
| {"13", "14", "15", "16"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| }; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -156,17 +160,19 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetNumSamples) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}}; | |||
| std::vector<std::vector<std::string>> expected_result = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -196,17 +202,19 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetDistribution) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}}; | |||
| std::vector<std::vector<std::string>> expected_result = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -241,41 +249,43 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetType) { | |||
| // Iterate the dataset and get each row | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| // std::vector<std::vector<std::shared_ptr<CsvBase>>> expected = { | |||
| // { | |||
| // std::make_shared<CsvRecord<std::string>>(CsvType::STRING, ""), | |||
| // std::make_shared<CsvRecord<int>>(CsvType::INT, 2), | |||
| // std::make_shared<CsvRecord<float>>(CsvType::FLOAT, 3.0), | |||
| // std::make_shared<CsvRecord<std::string>>(CsvType::STRING, ""), | |||
| // }, | |||
| // { | |||
| // std::make_shared<CsvRecord<std::string>>(CsvType::STRING, "a"), | |||
| // std::make_shared<CsvRecord<int>>(CsvType::INT, 4), | |||
| // std::make_shared<CsvRecord<float>>(CsvType::FLOAT, 5.0), | |||
| // std::make_shared<CsvRecord<std::string>>(CsvType::STRING, "b"), | |||
| // }, | |||
| // }; | |||
| std::vector<std::vector<std::shared_ptr<CsvBase>>> expected = { | |||
| { | |||
| std::make_shared<CsvRecord<std::string>>(CsvType::STRING, ""), | |||
| std::make_shared<CsvRecord<int>>(CsvType::INT, 2), | |||
| std::make_shared<CsvRecord<float>>(CsvType::FLOAT, 3.0), | |||
| std::make_shared<CsvRecord<std::string>>(CsvType::STRING, ""), | |||
| }, | |||
| { | |||
| std::make_shared<CsvRecord<std::string>>(CsvType::STRING, "a"), | |||
| std::make_shared<CsvRecord<int>>(CsvType::INT, 4), | |||
| std::make_shared<CsvRecord<float>>(CsvType::FLOAT, 5.0), | |||
| std::make_shared<CsvRecord<std::string>>(CsvType::STRING, "b"), | |||
| }, | |||
| }; | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // if (colum_type[j]->type == CsvType::INT) { | |||
| // int val; | |||
| // text->GetItemAt(&val, {0}); | |||
| // EXPECT_EQ(val, std::dynamic_pointer_cast<CsvRecord<int>>(expected[i][j])->value); | |||
| // } else if (colum_type[j]->type == CsvType::FLOAT) { | |||
| // float val; | |||
| // text->GetItemAt(&val, {0}); | |||
| // EXPECT_EQ(val, std::dynamic_pointer_cast<CsvRecord<float>>(expected[i][j])->value); | |||
| // } else if (colum_type[j]->type == CsvType::STRING) { | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), std::dynamic_pointer_cast<CsvRecord<std::string>>(expected[i][j])->value.c_str()); | |||
| // } | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| if (colum_type[j]->type == CsvType::INT) { | |||
| int val; | |||
| de_text->GetItemAt(&val, {0}); | |||
| EXPECT_EQ(val, std::dynamic_pointer_cast<CsvRecord<int>>(expected[i][j])->value); | |||
| } else if (colum_type[j]->type == CsvType::FLOAT) { | |||
| float val; | |||
| de_text->GetItemAt(&val, {0}); | |||
| EXPECT_EQ(val, std::dynamic_pointer_cast<CsvRecord<float>>(expected[i][j])->value); | |||
| } else if (colum_type[j]->type == CsvType::STRING) { | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), std::dynamic_pointer_cast<CsvRecord<std::string>>(expected[i][j])->value.c_str()); | |||
| } | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -304,20 +314,22 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetHeader) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"a", "b", "c", "d"}, | |||
| // }; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"a", "b", "c", "d"}, | |||
| }; | |||
| uint64_t i = 0; | |||
| // std::vector<std::string> column_names = {"col1", "col2", "col3", "col4"}; | |||
| std::vector<std::string> column_names = {"col1", "col2", "col3", "col4"}; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -411,20 +423,22 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetShuffleFilesA) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"13", "14", "15", "16"}, {"1", "2", "3", "4"}, {"17", "18", "19", "20"}, | |||
| // {"5", "6", "7", "8"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| // }; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"13", "14", "15", "16"}, {"1", "2", "3", "4"}, {"17", "18", "19", "20"}, | |||
| {"5", "6", "7", "8"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| }; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -466,21 +480,23 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetShuffleFilesB) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"13", "14", "15", "16"}, {"1", "2", "3", "4"}, {"17", "18", "19", "20"}, | |||
| // {"5", "6", "7", "8"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| // }; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"13", "14", "15", "16"}, {"1", "2", "3", "4"}, {"17", "18", "19", "20"}, | |||
| {"5", "6", "7", "8"}, {"21", "22", "23", "24"}, {"9", "10", "11", "12"}, | |||
| }; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -522,18 +538,20 @@ TEST_F(MindDataTestPipeline, TestCSVDatasetShuffleGlobal) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| EXPECT_NE(row.find("col1"), row.end()); | |||
| // std::vector<std::vector<std::string>> expected_result = { | |||
| // {"5", "6", "7", "8"}, {"9", "10", "11", "12"}, {"1", "2", "3", "4"}}; | |||
| std::vector<std::vector<std::string>> expected_result = { | |||
| {"5", "6", "7", "8"}, {"9", "10", "11", "12"}, {"1", "2", "3", "4"}}; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // for (int j = 0; j < column_names.size(); j++) { | |||
| // auto text = row[column_names[j]]; | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| // } | |||
| for (int j = 0; j < column_names.size(); j++) { | |||
| auto text = row[column_names[j]]; | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i][j].c_str()); | |||
| } | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -238,15 +238,20 @@ TEST_F(MindDataTestPipeline, TestManifestClassIndex) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // int32_t label_idx = 0; | |||
| int32_t label_idx = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| auto image = row["image"]; | |||
| auto label = row["label"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| // row["label"]->GetItemAt<int32_t>(&label_idx, {}); | |||
| // MS_LOG(INFO) << "Tensor label value: " << label_idx; | |||
| // auto label_it = std::find(expected_label.begin(), expected_label.end(), label_idx); | |||
| // EXPECT_NE(label_it, expected_label.end()); | |||
| std::shared_ptr<Tensor> de_label; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt<int32_t>(&label_idx, {}); | |||
| MS_LOG(INFO) << "Tensor label value: " << label_idx; | |||
| auto label_it = std::find(expected_label.begin(), expected_label.end(), label_idx); | |||
| EXPECT_NE(label_it, expected_label.end()); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -46,8 +46,8 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess1) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["file_name"]; | |||
| // MS_LOG(INFO) << "Tensor image file name: " << *image; | |||
| auto image = row["file_name"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor image file name: ", image); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -96,8 +96,9 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess2) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["file_name"]; | |||
| // MS_LOG(INFO) << "Tensor image file name: " << *image; | |||
| auto image = row["file_name"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor image file name: ", image); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -131,8 +132,9 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess3) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["file_name"]; | |||
| // MS_LOG(INFO) << "Tensor image file name: " << *image; | |||
| auto image = row["file_name"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor image file name: ", image); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -165,8 +167,8 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess4) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| auto label = row["label"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -266,7 +268,8 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess6) { | |||
| uint64_t j = 0; | |||
| while (row.size() != 0) { | |||
| j++; | |||
| // MS_LOG(INFO) << "Tensor label: " << *row["label"]; | |||
| auto label = row["label"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| EXPECT_EQ(j, expected_samples[i]); | |||
| @@ -312,10 +315,10 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess7) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["file_name"]; | |||
| auto image = row["file_name"]; | |||
| auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor file name: " << *image; | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor image file name: ", image); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| EXPECT_MSTENSOR_EQ(label, expect_item); | |||
| @@ -383,10 +386,10 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess8) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["file_name"]; | |||
| auto image = row["file_name"]; | |||
| auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor file name: " << *image; | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor image file name: ", image); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| EXPECT_MSTENSOR_EQ(label, expect_item); | |||
| @@ -459,7 +462,7 @@ TEST_F(MindDataTestPipeline, TestMindDataSuccess9) { | |||
| while (row.size() != 0) { | |||
| i++; | |||
| auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| EXPECT_MSTENSOR_EQ(label, expect_item); | |||
| @@ -632,20 +632,24 @@ TEST_F(MindDataTestPipeline, TestFilterSuccess1) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| // std::vector<uint64_t> label_list; | |||
| std::vector<uint64_t> label_list; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto label = row["label"]; | |||
| // uint64_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // label_list.push_back(label_value); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| uint64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| label_list.push_back(label_value); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| // Only 1 column whose label is equal to 3 | |||
| EXPECT_EQ(i, 1); | |||
| // EXPECT_EQ(label_list.at(0), 3); | |||
| EXPECT_EQ(label_list.at(0), 3); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -674,21 +678,25 @@ TEST_F(MindDataTestPipeline, TestFilterSuccess2) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| // std::vector<uint64_t> label_list; | |||
| std::vector<uint64_t> label_list; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto label = row["label"]; | |||
| // uint64_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // label_list.push_back(label_value); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| uint64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| label_list.push_back(label_value); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| // There are 2 columns whose label is more than 1 | |||
| EXPECT_EQ(i, 2); | |||
| // EXPECT_EQ(label_list.at(0), 2); | |||
| // EXPECT_EQ(label_list.at(1), 3); | |||
| EXPECT_EQ(label_list.at(0), 2); | |||
| EXPECT_EQ(label_list.at(1), 3); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -1079,7 +1087,7 @@ TEST_F(MindDataTestPipeline, TestProjectMapAutoInjection) { | |||
| i++; | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| // EXPECT_EQ(image.Shape()[0], 30); | |||
| EXPECT_EQ(image.Shape()[0], 30); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -46,9 +46,10 @@ TEST_F(MindDataTestPipeline, TestSaveCifar10AndLoad) { | |||
| // Save original data for comparison | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto label = row["label"]; | |||
| // original_data.push_back(label); | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| auto label = row["label"]; | |||
| original_data.push_back(label); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -97,9 +98,10 @@ TEST_F(MindDataTestPipeline, TestSaveCifar10AndLoad) { | |||
| // Expect the output data is same with original_data | |||
| uint64_t j = 0; | |||
| while (row_minddata.size() != 0) { | |||
| // auto label = row_minddata["label"]; | |||
| // EXPECT_EQ(*original_data[j], *label); | |||
| // MS_LOG(INFO) << "Tensor label: " << *label; | |||
| auto label = row_minddata["label"]; | |||
| EXPECT_MSTENSOR_EQ(original_data[j], label); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "Tensor label: ", label); | |||
| iter_minddata->GetNextRow(&row_minddata); | |||
| j++; | |||
| } | |||
| @@ -60,12 +60,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetBasic) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -317,12 +320,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFalse1A) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -375,12 +381,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFalse1B) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -432,12 +441,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFalse4Shard) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -492,12 +504,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFiles1A) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -552,12 +567,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFiles1B) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -611,12 +629,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleFiles4) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -666,12 +687,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleGlobal1A) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -724,12 +748,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleGlobal1B) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -782,12 +809,15 @@ TEST_F(MindDataTestPipeline, TestTextFileDatasetShuffleGlobal4) { | |||
| while (row.size() != 0) { | |||
| auto text = row["text"]; | |||
| MS_LOG(INFO) << "Tensor text shape: " << text.Shape(); | |||
| // std::string_view sv; | |||
| // text->GetItemAt(&sv, {0}); | |||
| // std::string ss(sv); | |||
| // MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // // Compare against expected result | |||
| // EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| std::shared_ptr<Tensor> de_text; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(text, &de_text)); | |||
| std::string_view sv; | |||
| de_text->GetItemAt(&sv, {0}); | |||
| std::string ss(sv); | |||
| MS_LOG(INFO) << "Text length: " << ss.length() << ", Text: " << ss.substr(0, 50); | |||
| // Compare against expected result | |||
| EXPECT_STREQ(ss.c_str(), expected_result[i].c_str()); | |||
| i++; | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -148,12 +148,21 @@ TEST_F(MindDataTestPipeline, TestTFRecordDatasetShuffle) { | |||
| iter2->GetNextRow(&row2); | |||
| uint64_t i = 0; | |||
| // int64_t value1 = 0; | |||
| // int64_t value2 = 0; | |||
| int64_t value1 = 0; | |||
| int64_t value2 = 0; | |||
| while (row1.size() != 0 && row2.size() != 0) { | |||
| // row1["scalars"]->GetItemAt(&value1, {0}); | |||
| // row2["scalars"]->GetItemAt(&value2, {0}); | |||
| // EXPECT_EQ(value1, value2); | |||
| auto scalars1 = row1["scalars"]; | |||
| std::shared_ptr<Tensor> de_scalars1; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(scalars1, &de_scalars1)); | |||
| de_scalars1->GetItemAt(&value1, {0}); | |||
| auto scalars2 = row2["scalars"]; | |||
| std::shared_ptr<Tensor> de_scalars2; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(scalars2, &de_scalars2)); | |||
| de_scalars2->GetItemAt(&value2, {0}); | |||
| EXPECT_EQ(value1, value2); | |||
| iter1->GetNextRow(&row1); | |||
| iter2->GetNextRow(&row2); | |||
| i++; | |||
| @@ -191,17 +200,21 @@ TEST_F(MindDataTestPipeline, TestTFRecordDatasetShuffle2) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| // std::vector<int> expect = {9, 3, 4, 7, 2, 1, 6, 8, 10, 5}; | |||
| // std::vector<int> actual = {}; | |||
| // int64_t value = 0; | |||
| std::vector<int> expect = {9, 3, 4, 7, 2, 1, 6, 8, 10, 5}; | |||
| std::vector<int> actual = {}; | |||
| int64_t value = 0; | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // row["scalars"]->GetItemAt(&value, {}); | |||
| // actual.push_back(value); | |||
| auto scalars = row["scalars"]; | |||
| std::shared_ptr<Tensor> de_scalars; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(scalars, &de_scalars)); | |||
| de_scalars->GetItemAt(&value, {0}); | |||
| actual.push_back(value); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| // ASSERT_EQ(actual, expect); | |||
| ASSERT_EQ(actual, expect); | |||
| EXPECT_EQ(i, 10); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -222,7 +222,7 @@ TEST_F(MindDataTestPipeline, TestImageFolderFailWithWrongExtensionFail) { | |||
| std::unordered_map<std::string, mindspore::MSTensor> row; | |||
| iter->GetNextRow(&row); | |||
| // Expect no data: cannot find files with specified extension | |||
| // EXPECT_EQ(row.size(), 0); | |||
| EXPECT_EQ(row.size(), 0); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -26,10 +26,10 @@ class MindDataTestEpochCtrl : public UT::DatasetOpTesting { | |||
| TEST_F(MindDataTestEpochCtrl, TestAutoInjectEpoch) { | |||
| MS_LOG(INFO) << "Doing MindDataTestEpochCtrl-TestAutoInjectEpoch."; | |||
| // int32_t img_class[4] = {0, 1, 2, 3}; | |||
| int32_t img_class[4] = {0, 1, 2, 3}; | |||
| int32_t num_epochs = 2 + std::rand() % 3; | |||
| int32_t sampler_size = 44; | |||
| // int32_t class_size = 11; | |||
| int32_t class_size = 11; | |||
| MS_LOG(INFO) << "num_epochs: " << num_epochs; | |||
| // Create an ImageFolder Dataset | |||
| @@ -50,10 +50,12 @@ TEST_F(MindDataTestEpochCtrl, TestAutoInjectEpoch) { | |||
| iter->GetNextRow(&row); | |||
| while (row.size() != 0) { | |||
| // auto label = row["label"]; | |||
| // int32_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // EXPECT_TRUE(img_class[(i % sampler_size) / class_size] == label_value); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| int64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| EXPECT_TRUE(img_class[(i % sampler_size) / class_size] == label_value); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -64,7 +66,7 @@ TEST_F(MindDataTestEpochCtrl, TestAutoInjectEpoch) { | |||
| // Try to fetch data beyond the specified number of epochs. | |||
| iter->GetNextRow(&row); | |||
| // EXPECT_EQ(row.size(), 2); | |||
| EXPECT_EQ(row.size(), 2); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -94,10 +96,12 @@ TEST_F(MindDataTestEpochCtrl, TestEpoch) { | |||
| for (int epoch = 0; epoch < num_epochs; epoch++) { | |||
| iter->GetNextRow(&row); | |||
| while (row.size() != 0) { | |||
| // auto label = row["label"]; | |||
| // int32_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| int64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -109,7 +113,7 @@ TEST_F(MindDataTestEpochCtrl, TestEpoch) { | |||
| // Try to fetch data beyond the specified number of epochs. | |||
| iter->GetNextRow(&row); | |||
| // EXPECT_EQ(row.size(), 2); | |||
| EXPECT_EQ(row.size(), 2); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -141,10 +145,12 @@ TEST_F(MindDataTestEpochCtrl, TestRepeatEpoch) { | |||
| for (int epoch = 0; epoch < num_epochs; epoch++) { | |||
| iter->GetNextRow(&row); | |||
| while (row.size() != 0) { | |||
| // auto label = row["label"]; | |||
| // int32_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| int64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -156,7 +162,7 @@ TEST_F(MindDataTestEpochCtrl, TestRepeatEpoch) { | |||
| // Try to fetch data beyond the specified number of epochs. | |||
| iter->GetNextRow(&row); | |||
| // EXPECT_EQ(row.size(), 2); | |||
| EXPECT_EQ(row.size(), 2); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -188,10 +194,12 @@ TEST_F(MindDataTestEpochCtrl, TestRepeatRepeatEpoch) { | |||
| for (int epoch = 0; epoch < num_epochs; epoch++) { | |||
| iter->GetNextRow(&row); | |||
| while (row.size() != 0) { | |||
| // auto label = row["label"]; | |||
| // int32_t label_value; | |||
| // label->GetItemAt(&label_value, {0}); | |||
| // EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| auto label = row["label"]; | |||
| std::shared_ptr<Tensor> de_label; | |||
| int64_t label_value; | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(label, &de_label)); | |||
| de_label->GetItemAt(&label_value, {0}); | |||
| EXPECT_TRUE(label_value >= 0 && label_value <= 3); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| @@ -203,7 +211,7 @@ TEST_F(MindDataTestEpochCtrl, TestRepeatRepeatEpoch) { | |||
| // Try to fetch data beyond the specified number of epochs. | |||
| iter->GetNextRow(&row); | |||
| // EXPECT_EQ(row.size(), 2); | |||
| EXPECT_EQ(row.size(), 2); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| @@ -71,15 +71,19 @@ TEST_F(MindDataTestPipeline, TestSentencePieceVocabSuccess1) { | |||
| iter->GetNextRow(&row); | |||
| // Expected result after tokenization | |||
| // std::vector<std::string> expected = {"▁I", "▁sa", "w", "▁a", "▁girl", "▁with", "▁a", "▁te", "les", "co", "pe", | |||
| // "."}; | |||
| std::vector<std::string> expected = {"▁I", "▁sa", "w", "▁a", "▁girl", "▁with", "▁a", "▁te", "les", "co", "pe", "."}; | |||
| std::shared_ptr<Tensor> de_expected_tensor; | |||
| ASSERT_OK(Tensor::CreateFromVector(expected, &de_expected_tensor)); | |||
| mindspore::MSTensor expected_tensor = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_tensor)); | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto txt = row["text"]; | |||
| // MS_LOG(INFO) << *txt; | |||
| // mindspore::MSTensor expected_tensor; | |||
| // Tensor::CreateFromVector(expected, &expected_tensor); | |||
| // EXPECT_EQ(*txt, *expected_tensor); | |||
| auto txt = row["text"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "txt: ", txt); | |||
| EXPECT_MSTENSOR_EQ(txt, expected_tensor); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -127,15 +131,19 @@ TEST_F(MindDataTestPipeline, TestSentencePieceVocabSuccess2) { | |||
| iter->GetNextRow(&row); | |||
| // Expected result after tokenization | |||
| // std::vector<std::string> expected = {"▁I", "▁sa", "w", "▁a", "▁girl", "▁with", "▁a", "▁te", "les", "co", "pe", | |||
| // "."}; | |||
| std::vector<std::string> expected = {"▁I", "▁sa", "w", "▁a", "▁girl", "▁with", "▁a", "▁te", "les", "co", "pe", "."}; | |||
| std::shared_ptr<Tensor> de_expected_tensor; | |||
| ASSERT_OK(Tensor::CreateFromVector(expected, &de_expected_tensor)); | |||
| mindspore::MSTensor expected_tensor = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_tensor)); | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| // auto txt = row["text"]; | |||
| // MS_LOG(INFO) << *txt; | |||
| // mindspore::MSTensor expected_tensor; | |||
| // Tensor::CreateFromVector(expected, &expected_tensor); | |||
| // EXPECT_EQ(*txt, *expected_tensor); | |||
| auto txt = row["text"]; | |||
| TEST_MS_LOG_MSTENSOR(INFO, "txt: ", txt); | |||
| EXPECT_MSTENSOR_EQ(txt, expected_tensor); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -35,6 +35,12 @@ class MindDataTestPipeline : public UT::DatasetOpTesting { | |||
| protected: | |||
| }; | |||
| // Macro to compare 2 MSTensors as not equal; compare datasize only | |||
| #define EXPECT_MSTENSOR_DATA_NE(_mstensor1, _mstensor2) \ | |||
| do { \ | |||
| EXPECT_NE(_mstensor1.DataSize(), _mstensor2.DataSize()); \ | |||
| } while (false) | |||
| TEST_F(MindDataTestPipeline, TestVocabLookupOp) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVocabLookupOp."; | |||
| @@ -67,13 +73,17 @@ TEST_F(MindDataTestPipeline, TestVocabLookupOp) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // std::vector<int32_t> expected = {2, 1, 4, 5, 6, 7}; | |||
| std::vector<int32_t> expected = {2, 1, 4, 5, 6, 7}; | |||
| while (row.size() != 0) { | |||
| // auto ind = row["text"]; | |||
| // MS_LOG(INFO) << ind->shape() << " " << *ind; | |||
| // mindspore::MSTensor expected_item; | |||
| // Tensor::CreateScalar(expected[i], &expected_item); | |||
| // EXPECT_EQ(*ind, *expected_item); | |||
| auto ind = row["text"]; | |||
| MS_LOG(INFO) << ind.Shape(); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "ind: ", ind); | |||
| std::shared_ptr<Tensor> de_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(expected[i], &de_expected_item)); | |||
| mindspore::MSTensor ms_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_item)); | |||
| EXPECT_MSTENSOR_EQ(ind, ms_expected_item); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -111,13 +121,17 @@ TEST_F(MindDataTestPipeline, TestVocabLookupOpEmptyString) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // std::vector<int32_t> expected = {2, 1, 4, 5, 6, 7}; | |||
| std::vector<int32_t> expected = {2, 1, 4, 5, 6, 7}; | |||
| while (row.size() != 0) { | |||
| // auto ind = row["text"]; | |||
| // MS_LOG(INFO) << ind->shape() << " " << *ind; | |||
| // mindspore::MSTensor expected_item; | |||
| // Tensor::CreateScalar(expected[i], &expected_item); | |||
| // EXPECT_EQ(*ind, *expected_item); | |||
| auto ind = row["text"]; | |||
| MS_LOG(INFO) << ind.Shape(); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "ind: ", ind); | |||
| std::shared_ptr<Tensor> de_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(expected[i], &de_expected_item)); | |||
| mindspore::MSTensor ms_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_item)); | |||
| EXPECT_MSTENSOR_EQ(ind, ms_expected_item); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -207,13 +221,17 @@ TEST_F(MindDataTestPipeline, TestVocabFromDataset) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // std::vector<int32_t> expected = {4, 5, 3, 6, 7, 2}; | |||
| std::vector<int32_t> expected = {4, 5, 3, 6, 7, 2}; | |||
| while (row.size() != 0) { | |||
| // auto ind = row["text"]; | |||
| // MS_LOG(INFO) << ind->shape() << " " << *ind; | |||
| // mindspore::MSTensor expected_item; | |||
| // Tensor::CreateScalar(expected[i], &expected_item); | |||
| // EXPECT_EQ(*ind, *expected_item); | |||
| auto ind = row["text"]; | |||
| MS_LOG(INFO) << ind.Shape(); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "ind: ", ind); | |||
| std::shared_ptr<Tensor> de_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(expected[i], &de_expected_item)); | |||
| mindspore::MSTensor ms_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_item)); | |||
| EXPECT_MSTENSOR_EQ(ind, ms_expected_item); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -253,16 +271,25 @@ TEST_F(MindDataTestPipeline, TestVocabFromDatasetDefault) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // std::vector<int32_t> expected = {2, 3, 1, 4, 5, 0}; | |||
| // std::vector<int64_t> not_expected = {2, 3, 1, 4, 5, 0}; | |||
| std::vector<int32_t> expected = {2, 3, 1, 4, 5, 0}; | |||
| std::vector<int64_t> not_expected = {2, 3, 1, 4, 5, 0}; | |||
| while (row.size() != 0) { | |||
| // auto ind = row["text"]; | |||
| // MS_LOG(INFO) << ind->shape() << " " << *ind; | |||
| // mindspore::MSTensor expected_item, not_expected_item; | |||
| // Tensor::CreateScalar(expected[i], &expected_item); | |||
| // Tensor::CreateScalar(not_expected[i], ¬_expected_item); | |||
| // EXPECT_EQ(*ind, *expected_item); | |||
| // EXPECT_NE(*ind, *not_expected_item); | |||
| auto ind = row["text"]; | |||
| MS_LOG(INFO) << ind.Shape(); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "ind: ", ind); | |||
| std::shared_ptr<Tensor> de_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(expected[i], &de_expected_item)); | |||
| mindspore::MSTensor ms_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_item)); | |||
| EXPECT_MSTENSOR_EQ(ind, ms_expected_item); | |||
| std::shared_ptr<Tensor> de_not_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(not_expected[i], &de_not_expected_item)); | |||
| mindspore::MSTensor ms_not_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_not_expected_item)); | |||
| EXPECT_MSTENSOR_DATA_NE(ind, ms_not_expected_item); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -361,16 +388,25 @@ TEST_F(MindDataTestPipeline, TestVocabFromDatasetInt64) { | |||
| iter->GetNextRow(&row); | |||
| uint64_t i = 0; | |||
| // std::vector<int64_t> expected = {2, 3, 1, 4, 5, 0}; | |||
| // std::vector<int8_t> not_expected = {2, 3, 1, 4, 5, 0}; | |||
| std::vector<int64_t> expected = {2, 3, 1, 4, 5, 0}; | |||
| std::vector<int8_t> not_expected = {2, 3, 1, 4, 5, 0}; | |||
| while (row.size() != 0) { | |||
| // auto ind = row["text"]; | |||
| // MS_LOG(INFO) << ind->shape() << " " << *ind; | |||
| // mindspore::MSTensor expected_item, not_expected_item; | |||
| // Tensor::CreateScalar(expected[i], &expected_item); | |||
| // Tensor::CreateScalar(not_expected[i], ¬_expected_item); | |||
| // EXPECT_EQ(*ind, *expected_item); | |||
| // EXPECT_NE(*ind, *not_expected_item); | |||
| auto ind = row["text"]; | |||
| MS_LOG(INFO) << ind.Shape(); | |||
| TEST_MS_LOG_MSTENSOR(INFO, "ind: ", ind); | |||
| std::shared_ptr<Tensor> de_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(expected[i], &de_expected_item)); | |||
| mindspore::MSTensor ms_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expected_item)); | |||
| EXPECT_MSTENSOR_EQ(ind, ms_expected_item); | |||
| std::shared_ptr<Tensor> de_not_expected_item; | |||
| ASSERT_OK(Tensor::CreateScalar(not_expected[i], &de_not_expected_item)); | |||
| mindspore::MSTensor ms_not_expected_item = | |||
| mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_not_expected_item)); | |||
| EXPECT_MSTENSOR_DATA_NE(ind, ms_not_expected_item); | |||
| iter->GetNextRow(&row); | |||
| i++; | |||
| } | |||
| @@ -164,12 +164,10 @@ TEST_F(MindDataTestPipeline, TestDuplicateSuccess) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // FIXME | |||
| // auto image = row["image"]; | |||
| // auto image_copy = row["image_copy"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| // auto n = memcmp(&image, &image_copy, image.DataSize()); | |||
| // EXPECT_EQ(n, 0); | |||
| auto image = row["image"]; | |||
| auto image_copy = row["image_copy"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| EXPECT_MSTENSOR_EQ(image, image_copy); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -66,7 +66,7 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess1) { | |||
| auto image1 = row1["image"]; | |||
| // EXPECT_EQ(*image, *image1); | |||
| EXPECT_MSTENSOR_EQ(image, image1); | |||
| // Manually terminate the pipeline | |||
| iter1->Stop(); | |||
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| * Copyright 2019 Huawei Technologies Co., Ltd | |||
| * Copyright 2019-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. | |||
| @@ -14,8 +14,8 @@ | |||
| * limitations under the License. | |||
| */ | |||
| #include "common.h" | |||
| #include <fstream> | |||
| #include <algorithm> | |||
| #include <fstream> | |||
| #include <string> | |||
| #include <vector> | |||
| @@ -72,6 +72,14 @@ do { | |||
| _mstensor2.DataSize()), 0); \ | |||
| } while (false) | |||
| // Macro to invoke MS_LOG for MSTensor | |||
| #define TEST_MS_LOG_MSTENSOR(_loglevel, _msg, _mstensor) \ | |||
| do { \ | |||
| std::shared_ptr<Tensor> _de_tensor; \ | |||
| ASSERT_OK(Tensor::CreateFromMSTensor(_mstensor, &_de_tensor)); \ | |||
| MS_LOG(_loglevel) << _msg << *_de_tensor; \ | |||
| } while (false) | |||
| namespace UT { | |||
| class Common : public testing::Test { | |||
| public: | |||