You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

image_folder_op_test.cc 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. * Copyright 2019-2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <iostream>
  17. #include <memory>
  18. #include <string>
  19. #include "common/common.h"
  20. #include "utils/ms_utils.h"
  21. #include "minddata/dataset/core/client.h"
  22. #include "minddata/dataset/core/global_context.h"
  23. #include "minddata/dataset/engine/datasetops/source/image_folder_op.h"
  24. #include "minddata/dataset/engine/datasetops/source/sampler/distributed_sampler.h"
  25. #include "minddata/dataset/engine/datasetops/source/sampler/pk_sampler.h"
  26. #include "minddata/dataset/engine/datasetops/source/sampler/random_sampler.h"
  27. #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h"
  28. #include "minddata/dataset/engine/datasetops/source/sampler/sequential_sampler.h"
  29. #include "minddata/dataset/engine/datasetops/source/sampler/subset_random_sampler.h"
  30. #include "minddata/dataset/engine/datasetops/source/sampler/weighted_random_sampler.h"
  31. #include "minddata/dataset/util/status.h"
  32. #include "gtest/gtest.h"
  33. #include "utils/log_adapter.h"
  34. #include "securec.h"
  35. namespace common = mindspore::common;
  36. using namespace mindspore::dataset;
  37. using mindspore::LogStream;
  38. using mindspore::ExceptionType::NoExceptionType;
  39. using mindspore::MsLogLevel::ERROR;
  40. // std::shared_ptr<BatchOp> Batch(int batch_size = 1, bool drop = false);
  41. // std::shared_ptr<RepeatOp> Repeat(int repeat_cnt);
  42. // std::shared_ptr<ExecutionTree> Build(std::vector<std::shared_ptr<DatasetOp>> ops);
  43. std::shared_ptr<ImageFolderOp> ImageFolder(int64_t num_works, int64_t rows, int64_t conns, std::string path,
  44. bool shuf = false, std::shared_ptr<SamplerRT> sampler = nullptr,
  45. std::map<std::string, int32_t> map = {}, bool decode = false) {
  46. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  47. TensorShape scalar = TensorShape::CreateScalar();
  48. (void)schema->AddColumn(ColDescriptor("image", DataType(DataType::DE_UINT8), TensorImpl::kFlexible, 1));
  49. (void)schema->AddColumn(ColDescriptor("label", DataType(DataType::DE_INT32), TensorImpl::kFlexible, 0, &scalar));
  50. std::set<std::string> ext = {".jpg", ".JPEG"};
  51. if (sampler == nullptr) {
  52. int64_t num_samples = 0; // default num samples of 0 means to sample entire set of data
  53. int64_t start_index = 0;
  54. sampler = std::make_shared<SequentialSamplerRT>(start_index, num_samples);
  55. }
  56. std::shared_ptr<ImageFolderOp> so =
  57. std::make_shared<ImageFolderOp>(num_works, path, conns, false, decode, ext, map, std::move(schema), sampler);
  58. return so;
  59. }
  60. Status Create1DTensor(std::shared_ptr<Tensor> *sample_ids, int64_t num_elements, unsigned char *data = nullptr,
  61. DataType::Type data_type = DataType::DE_UINT32) {
  62. TensorShape shape(std::vector<int64_t>(1, num_elements));
  63. RETURN_IF_NOT_OK(Tensor::CreateFromMemory(shape, DataType(data_type), data, sample_ids));
  64. return Status::OK();
  65. }
  66. class MindDataTestImageFolderSampler : public UT::DatasetOpTesting {
  67. protected:
  68. };
  69. TEST_F(MindDataTestImageFolderSampler, TestSequentialImageFolderWithRepeat) {
  70. std::string folder_path = datasets_root_path_ + "/testPK/data";
  71. auto op1 = ImageFolder(16, 2, 32, folder_path, false);
  72. auto op2 = Repeat(2);
  73. op1->set_total_repeats(2);
  74. op1->set_num_repeats_per_epoch(2);
  75. auto tree = Build({op1, op2});
  76. tree->Prepare();
  77. int32_t res[] = {0, 1, 2, 3};
  78. Status rc = tree->Launch();
  79. if (rc.IsError()) {
  80. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  81. EXPECT_TRUE(false);
  82. } else {
  83. DatasetIterator di(tree);
  84. TensorMap tensor_map;
  85. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  86. EXPECT_TRUE(rc.IsOk());
  87. uint64_t i = 0;
  88. int32_t label = 0;
  89. while (tensor_map.size() != 0) {
  90. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  91. EXPECT_TRUE(res[(i % 44) / 11] == label);
  92. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  93. i++;
  94. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  95. }
  96. EXPECT_TRUE(i == 88);
  97. }
  98. }
  99. TEST_F(MindDataTestImageFolderSampler, TestRandomImageFolder) {
  100. std::string folder_path = datasets_root_path_ + "/testPK/data";
  101. auto tree = Build({ImageFolder(16, 2, 32, folder_path, true, nullptr)});
  102. tree->Prepare();
  103. Status rc = tree->Launch();
  104. if (rc.IsError()) {
  105. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  106. EXPECT_TRUE(false);
  107. } else {
  108. DatasetIterator di(tree);
  109. TensorMap tensor_map;
  110. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  111. EXPECT_TRUE(rc.IsOk());
  112. uint64_t i = 0;
  113. int32_t label = 0;
  114. while (tensor_map.size() != 0) {
  115. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  116. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  117. i++;
  118. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  119. }
  120. EXPECT_TRUE(i == 44);
  121. }
  122. }
  123. TEST_F(MindDataTestImageFolderSampler, TestRandomSamplerImageFolder) {
  124. int32_t original_seed = GlobalContext::config_manager()->seed();
  125. GlobalContext::config_manager()->set_seed(0);
  126. int64_t num_samples = 12;
  127. std::shared_ptr<SamplerRT> sampler = std::make_unique<RandomSamplerRT>(true, num_samples, true);
  128. int32_t res[] = {2, 2, 2, 3, 2, 3, 2, 3, 1, 2, 2, 1}; // ground truth label
  129. std::string folder_path = datasets_root_path_ + "/testPK/data";
  130. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(sampler))});
  131. tree->Prepare();
  132. Status rc = tree->Launch();
  133. if (rc.IsError()) {
  134. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  135. EXPECT_TRUE(false);
  136. } else {
  137. DatasetIterator di(tree);
  138. TensorMap tensor_map;
  139. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  140. EXPECT_TRUE(rc.IsOk());
  141. uint64_t i = 0;
  142. int32_t label = 0;
  143. while (tensor_map.size() != 0) {
  144. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  145. EXPECT_TRUE(res[i] == label);
  146. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  147. i++;
  148. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  149. }
  150. EXPECT_TRUE(i == 12);
  151. }
  152. GlobalContext::config_manager()->set_seed(original_seed);
  153. }
  154. TEST_F(MindDataTestImageFolderSampler, TestSequentialImageFolderWithRepeatBatch) {
  155. std::string folder_path = datasets_root_path_ + "/testPK/data";
  156. auto op1 = ImageFolder(16, 2, 32, folder_path, false);
  157. auto op2 = Repeat(2);
  158. auto op3 = Batch(11);
  159. op1->set_total_repeats(2);
  160. op1->set_num_repeats_per_epoch(2);
  161. auto tree = Build({op1, op2, op3});
  162. tree->Prepare();
  163. int32_t res[4][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  164. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  165. {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
  166. {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}};
  167. Status rc = tree->Launch();
  168. if (rc.IsError()) {
  169. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  170. EXPECT_TRUE(false);
  171. } else {
  172. DatasetIterator di(tree);
  173. TensorMap tensor_map;
  174. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  175. EXPECT_TRUE(rc.IsOk());
  176. uint64_t i = 0;
  177. while (tensor_map.size() != 0) {
  178. std::shared_ptr<Tensor> label;
  179. Create1DTensor(&label, 11, reinterpret_cast<unsigned char *>(res[i % 4]), DataType::DE_INT32);
  180. EXPECT_TRUE((*label) == (*tensor_map["label"]));
  181. MS_LOG(DEBUG) << "row: " << i << " " << tensor_map["image"]->shape() << " (*label):" << (*label)
  182. << " *tensor_map[label]: " << *tensor_map["label"] << std::endl;
  183. i++;
  184. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  185. }
  186. EXPECT_TRUE(i == 8);
  187. }
  188. }
  189. TEST_F(MindDataTestImageFolderSampler, TestSubsetRandomSamplerImageFolder) {
  190. // id range 0 - 10 is label 0, and id range 11 - 21 is label 1
  191. std::vector<int64_t> indices({0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 11});
  192. int64_t num_samples = 0;
  193. std::shared_ptr<SamplerRT> sampler = std::make_shared<SubsetRandomSamplerRT>(indices, num_samples);
  194. std::string folder_path = datasets_root_path_ + "/testPK/data";
  195. // Expect 6 samples for label 0 and 1
  196. int res[2] = {6, 6};
  197. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(sampler))});
  198. tree->Prepare();
  199. Status rc = tree->Launch();
  200. if (rc.IsError()) {
  201. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  202. EXPECT_TRUE(false);
  203. } else {
  204. DatasetIterator di(tree);
  205. TensorMap tensor_map;
  206. rc = di.GetNextAsMap(&tensor_map);
  207. EXPECT_TRUE(rc.IsOk());
  208. uint64_t i = 0;
  209. int32_t label = 0;
  210. while (tensor_map.size() != 0) {
  211. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  212. res[label]--;
  213. i++;
  214. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  215. }
  216. EXPECT_EQ(res[0], 0);
  217. EXPECT_EQ(res[1], 0);
  218. EXPECT_TRUE(i == 12);
  219. }
  220. }
  221. TEST_F(MindDataTestImageFolderSampler, TestWeightedRandomSamplerImageFolder) {
  222. // num samples to draw.
  223. int64_t num_samples = 12;
  224. int64_t total_samples = 44;
  225. int64_t samples_per_tensor = 10;
  226. std::vector<double> weights(total_samples, std::rand() % 100);
  227. // create sampler with replacement = replacement
  228. std::shared_ptr<SamplerRT> sampler =
  229. std::make_shared<WeightedRandomSamplerRT>(weights, num_samples, true, samples_per_tensor);
  230. std::string folder_path = datasets_root_path_ + "/testPK/data";
  231. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(sampler))});
  232. tree->Prepare();
  233. Status rc = tree->Launch();
  234. if (rc.IsError()) {
  235. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  236. EXPECT_TRUE(false);
  237. } else {
  238. DatasetIterator di(tree);
  239. TensorMap tensor_map;
  240. rc = di.GetNextAsMap(&tensor_map);
  241. EXPECT_TRUE(rc.IsOk());
  242. uint64_t i = 0;
  243. int32_t label = 0;
  244. while (tensor_map.size() != 0) {
  245. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  246. i++;
  247. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  248. }
  249. EXPECT_TRUE(i == 12);
  250. }
  251. }
  252. TEST_F(MindDataTestImageFolderSampler, TestImageFolderClassIndex) {
  253. std::string folder_path = datasets_root_path_ + "/testPK/data";
  254. std::map<std::string, int32_t> map;
  255. map["class3"] = 333;
  256. map["class1"] = 111;
  257. map["wrong folder name"] = 1234; // this is skipped
  258. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, nullptr, map)});
  259. int64_t res[2] = {111, 333};
  260. tree->Prepare();
  261. Status rc = tree->Launch();
  262. if (rc.IsError()) {
  263. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  264. EXPECT_TRUE(false);
  265. } else {
  266. DatasetIterator di(tree);
  267. TensorMap tensor_map;
  268. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  269. EXPECT_TRUE(rc.IsOk());
  270. uint64_t i = 0;
  271. int32_t label = 0;
  272. while (tensor_map.size() != 0) {
  273. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  274. EXPECT_TRUE(label == res[i / 11]);
  275. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  276. i++;
  277. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  278. }
  279. EXPECT_TRUE(i == 22);
  280. }
  281. }
  282. TEST_F(MindDataTestImageFolderSampler, TestDistributedSampler) {
  283. int64_t num_samples = 0;
  284. std::shared_ptr<SamplerRT> sampler = std::make_shared<DistributedSamplerRT>(11, 10, false, num_samples);
  285. std::string folder_path = datasets_root_path_ + "/testPK/data";
  286. auto op1 = ImageFolder(16, 2, 32, folder_path, false, std::move(sampler));
  287. auto op2 = Repeat(4);
  288. op1->set_total_repeats(4);
  289. op1->set_num_repeats_per_epoch(4);
  290. auto tree = Build({op1, op2});
  291. tree->Prepare();
  292. Status rc = tree->Launch();
  293. if (rc.IsError()) {
  294. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  295. EXPECT_TRUE(false);
  296. } else {
  297. DatasetIterator di(tree);
  298. TensorMap tensor_map;
  299. rc = di.GetNextAsMap(&tensor_map);
  300. EXPECT_TRUE(rc.IsOk());
  301. uint64_t i = 0;
  302. int32_t label = 0;
  303. while (tensor_map.size() != 0) {
  304. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  305. EXPECT_EQ(i % 4, label);
  306. MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n";
  307. i++;
  308. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  309. }
  310. EXPECT_TRUE(i == 16);
  311. }
  312. }
  313. TEST_F(MindDataTestImageFolderSampler, TestPKSamplerImageFolder) {
  314. int64_t num_samples = 0;
  315. std::shared_ptr<SamplerRT> sampler = std::make_shared<PKSamplerRT>(3, false, num_samples, 4);
  316. int32_t res[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3}; // ground truth label
  317. std::string folder_path = datasets_root_path_ + "/testPK/data";
  318. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(sampler))});
  319. tree->Prepare();
  320. Status rc = tree->Launch();
  321. if (rc.IsError()) {
  322. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  323. EXPECT_TRUE(false);
  324. } else {
  325. DatasetIterator di(tree);
  326. TensorMap tensor_map;
  327. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  328. EXPECT_TRUE(rc.IsOk());
  329. uint64_t i = 0;
  330. int32_t label = 0;
  331. while (tensor_map.size() != 0) {
  332. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  333. EXPECT_TRUE(res[i] == label);
  334. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  335. i++;
  336. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  337. }
  338. EXPECT_TRUE(i == 12);
  339. }
  340. }
  341. TEST_F(MindDataTestImageFolderSampler, TestImageFolderDecode) {
  342. std::string folder_path = datasets_root_path_ + "/testPK/data";
  343. std::map<std::string, int32_t> map;
  344. map["class3"] = 333;
  345. map["class1"] = 111;
  346. map["wrong folder name"] = 1234; // this is skipped
  347. int64_t num_samples = 20;
  348. int64_t start_index = 0;
  349. auto seq_sampler = std::make_shared<SequentialSamplerRT>(start_index, num_samples);
  350. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(seq_sampler), map, true)});
  351. int64_t res[2] = {111, 333};
  352. tree->Prepare();
  353. Status rc = tree->Launch();
  354. if (rc.IsError()) {
  355. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  356. EXPECT_TRUE(false);
  357. } else {
  358. DatasetIterator di(tree);
  359. TensorMap tensor_map;
  360. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  361. EXPECT_TRUE(rc.IsOk());
  362. uint64_t i = 0;
  363. int32_t label = 0;
  364. while (tensor_map.size() != 0) {
  365. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  366. EXPECT_TRUE(label == res[i / 11]);
  367. EXPECT_TRUE(tensor_map["image"]->shape() ==
  368. TensorShape({2268, 4032, 3})); // verify shapes are correct after decode
  369. MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n";
  370. i++;
  371. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  372. }
  373. EXPECT_TRUE(i == 20);
  374. }
  375. }
  376. TEST_F(MindDataTestImageFolderSampler, TestImageFolderSharding1) {
  377. int64_t num_samples = 5;
  378. std::shared_ptr<SamplerRT> sampler = std::make_shared<DistributedSamplerRT>(4, 0, false, num_samples);
  379. std::string folder_path = datasets_root_path_ + "/testPK/data";
  380. // numWrks, rows, conns, path, shuffle, sampler, map, numSamples, decode
  381. auto tree = Build({ImageFolder(16, 2, 32, folder_path, false, std::move(sampler), {})});
  382. tree->Prepare();
  383. Status rc = tree->Launch();
  384. int32_t labels[5] = {0, 0, 0, 1, 1};
  385. if (rc.IsError()) {
  386. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  387. EXPECT_TRUE(false);
  388. } else {
  389. DatasetIterator di(tree);
  390. TensorMap tensor_map;
  391. rc = di.GetNextAsMap(&tensor_map);
  392. EXPECT_TRUE(rc.IsOk());
  393. uint64_t i = 0;
  394. int32_t label = 0;
  395. while (tensor_map.size() != 0) {
  396. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  397. EXPECT_EQ(labels[i], label);
  398. MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n";
  399. i++;
  400. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  401. }
  402. EXPECT_TRUE(i == 5);
  403. }
  404. }
  405. TEST_F(MindDataTestImageFolderSampler, TestImageFolderSharding2) {
  406. int64_t num_samples = 12;
  407. std::shared_ptr<SamplerRT> sampler = std::make_shared<DistributedSamplerRT>(4, 3, false, num_samples);
  408. std::string folder_path = datasets_root_path_ + "/testPK/data";
  409. // numWrks, rows, conns, path, shuffle, sampler, map, numSamples, decode
  410. auto tree = Build({ImageFolder(16, 16, 32, folder_path, false, std::move(sampler), {})});
  411. tree->Prepare();
  412. Status rc = tree->Launch();
  413. uint32_t labels[11] = {0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3};
  414. if (rc.IsError()) {
  415. MS_LOG(ERROR) << "Return code error detected during tree launch: " << common::SafeCStr(rc.ToString()) << ".";
  416. EXPECT_TRUE(false);
  417. } else {
  418. DatasetIterator di(tree);
  419. TensorMap tensor_map;
  420. rc = di.GetNextAsMap(&tensor_map);
  421. EXPECT_TRUE(rc.IsOk());
  422. uint64_t i = 0;
  423. int32_t label = 0;
  424. while (tensor_map.size() != 0) {
  425. tensor_map["label"]->GetItemAt<int32_t>(&label, {});
  426. EXPECT_EQ(labels[i], label);
  427. MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n";
  428. i++;
  429. ASSERT_OK(di.GetNextAsMap(&tensor_map));
  430. }
  431. EXPECT_TRUE(i == 11);
  432. }
  433. }