1 /**
2 * Copyright 2020-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 "common/common.h"
17 #include "minddata/dataset/include/dataset/datasets.h"
18
19 using namespace mindspore::dataset;
20 using mindspore::dataset::dsize_t;
21 using mindspore::dataset::Tensor;
22 using mindspore::dataset::TensorShape;
23
24 class MindDataTestPipeline : public UT::DatasetOpTesting {
25 protected:
26 };
27
TEST_F(MindDataTestPipeline,TestCocoDefault)28 TEST_F(MindDataTestPipeline, TestCocoDefault) {
29 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDefault.";
30 // Create a Coco Dataset
31 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
32 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
33
34 std::shared_ptr<Dataset> ds = Coco(folder_path, annotation_file);
35 EXPECT_NE(ds, nullptr);
36
37 // Create an iterator over the result of the above dataset
38 // This will trigger the creation of the Execution Tree and launch it.
39 std::shared_ptr<Iterator> iter = ds->CreateIterator();
40 EXPECT_NE(iter, nullptr);
41
42 // Iterate the dataset and get each row
43 std::unordered_map<std::string, mindspore::MSTensor> row;
44 ASSERT_OK(iter->GetNextRow(&row));
45
46 uint64_t i = 0;
47 while (row.size() != 0) {
48 auto image = row["image"];
49 auto bbox = row["bbox"];
50 auto category_id = row["category_id"];
51 MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
52 MS_LOG(INFO) << "Tensor bbox shape: " << bbox.Shape();
53 MS_LOG(INFO) << "Tensor category_id shape: " << category_id.Shape();
54 ASSERT_OK(iter->GetNextRow(&row));
55 i++;
56 }
57
58 EXPECT_EQ(i, 6);
59
60 // Manually terminate the pipeline
61 iter->Stop();
62 }
63
TEST_F(MindDataTestPipeline,TestCocoDefaultWithPipeline)64 TEST_F(MindDataTestPipeline, TestCocoDefaultWithPipeline) {
65 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDefaultWithPipeline.";
66 // Create two Coco Dataset
67 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
68 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
69
70 std::shared_ptr<Dataset> ds1 = Coco(folder_path, annotation_file);
71 std::shared_ptr<Dataset> ds2 = Coco(folder_path, annotation_file);
72 EXPECT_NE(ds1, nullptr);
73 EXPECT_NE(ds2, nullptr);
74
75 // Create two Repeat operation on ds
76 int32_t repeat_num = 2;
77 ds1 = ds1->Repeat(repeat_num);
78 EXPECT_NE(ds1, nullptr);
79 repeat_num = 3;
80 ds2 = ds2->Repeat(repeat_num);
81 EXPECT_NE(ds2, nullptr);
82
83 // Create two Project operation on ds
84 std::vector<std::string> column_project = {"image", "bbox", "category_id"};
85 ds1 = ds1->Project(column_project);
86 EXPECT_NE(ds1, nullptr);
87 ds2 = ds2->Project(column_project);
88 EXPECT_NE(ds2, nullptr);
89
90 // Create a Concat operation on the ds
91 ds1 = ds1->Concat({ds2});
92 EXPECT_NE(ds1, nullptr);
93
94 // Create an iterator over the result of the above dataset
95 // This will trigger the creation of the Execution Tree and launch it.
96 std::shared_ptr<Iterator> iter = ds1->CreateIterator();
97 EXPECT_NE(iter, nullptr);
98
99 // Iterate the dataset and get each row
100 std::unordered_map<std::string, mindspore::MSTensor> row;
101 ASSERT_OK(iter->GetNextRow(&row));
102
103 uint64_t i = 0;
104 while (row.size() != 0) {
105 auto image = row["image"];
106 auto bbox = row["bbox"];
107 auto category_id = row["category_id"];
108 MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
109 MS_LOG(INFO) << "Tensor bbox shape: " << bbox.Shape();
110 MS_LOG(INFO) << "Tensor category_id shape: " << category_id.Shape();
111 ASSERT_OK(iter->GetNextRow(&row));
112 i++;
113 }
114
115 EXPECT_EQ(i, 30);
116
117 // Manually terminate the pipeline
118 iter->Stop();
119 }
120
TEST_F(MindDataTestPipeline,TestCocoGetters)121 TEST_F(MindDataTestPipeline, TestCocoGetters) {
122 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoGetters.";
123 // Create a Coco Dataset
124 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
125 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
126
127 std::shared_ptr<Dataset> ds = Coco(folder_path, annotation_file);
128 EXPECT_NE(ds, nullptr);
129
130 std::vector<std::string> column_names = {"image", "bbox", "category_id", "iscrowd"};
131 EXPECT_EQ(ds->GetDatasetSize(), 6);
132 EXPECT_EQ(ds->GetColumnNames(), column_names);
133 }
134
TEST_F(MindDataTestPipeline,TestCocoDetection)135 TEST_F(MindDataTestPipeline, TestCocoDetection) {
136 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDetection.";
137 // Create a Coco Dataset
138 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
139 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
140
141 std::shared_ptr<Dataset> ds =
142 Coco(folder_path, annotation_file, "Detection", false, std::make_shared<SequentialSampler>(0, 6));
143 EXPECT_NE(ds, nullptr);
144
145 // Create an iterator over the result of the above dataset
146 // This will trigger the creation of the Execution Tree and launch it.
147 std::shared_ptr<Iterator> iter = ds->CreateIterator();
148 EXPECT_NE(iter, nullptr);
149
150 // Iterate the dataset and get each row
151 std::unordered_map<std::string, mindspore::MSTensor> row;
152 ASSERT_OK(iter->GetNextRow(&row));
153
154 std::string expect_file[] = {"000000391895", "000000318219", "000000554625",
155 "000000574769", "000000060623", "000000309022"};
156 std::vector<std::vector<float>> expect_bbox_vector = {{10.0, 10.0, 10.0, 10.0, 70.0, 70.0, 70.0, 70.0},
157 {20.0, 20.0, 20.0, 20.0, 80.0, 80.0, 80.0, 80.0},
158 {30.0, 30.0, 30.0, 30.0},
159 {40.0, 40.0, 40.0, 40.0},
160 {50.0, 50.0, 50.0, 50.0},
161 {60.0, 60.0, 60.0, 60.0}};
162 std::vector<std::vector<uint32_t>> expect_catagoryid_list = {{1, 7}, {2, 8}, {3}, {4}, {5}, {6}};
163 uint64_t i = 0;
164 while (row.size() != 0) {
165 auto image = row["image"];
166 auto bbox = row["bbox"];
167 auto category_id = row["category_id"];
168
169 mindspore::MSTensor expect_image = ReadFileToTensor(folder_path + "/" + expect_file[i] + ".jpg");
170 EXPECT_MSTENSOR_EQ(image, expect_image);
171
172 std::shared_ptr<Tensor> de_expect_bbox;
173 dsize_t bbox_num = static_cast<dsize_t>(expect_bbox_vector[i].size() / 4);
174 ASSERT_OK(Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape({bbox_num, 4}), &de_expect_bbox));
175 mindspore::MSTensor expect_bbox =
176 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_bbox));
177 EXPECT_MSTENSOR_EQ(bbox, expect_bbox);
178
179 std::shared_ptr<Tensor> de_expect_categoryid;
180 ASSERT_OK(Tensor::CreateFromVector(expect_catagoryid_list[i], TensorShape({bbox_num, 1}), &de_expect_categoryid));
181 mindspore::MSTensor expect_categoryid =
182 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_categoryid));
183 EXPECT_MSTENSOR_EQ(category_id, expect_categoryid);
184
185 ASSERT_OK(iter->GetNextRow(&row));
186 i++;
187 }
188
189 EXPECT_EQ(i, 6);
190
191 // Manually terminate the pipeline
192 iter->Stop();
193 }
194
TEST_F(MindDataTestPipeline,TestCocoFail)195 TEST_F(MindDataTestPipeline, TestCocoFail) {
196 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoFail.";
197 // Create a Coco Dataset
198 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
199 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
200 std::string invalid_folder_path = "./NotExist";
201 std::string invalid_annotation_file = "./NotExistFile";
202
203 std::shared_ptr<Dataset> ds0 = Coco(invalid_folder_path, annotation_file);
204 EXPECT_NE(ds0, nullptr);
205 // Create an iterator over the result of the above dataset
206 std::shared_ptr<Iterator> iter0 = ds0->CreateIterator();
207 // Expect failure: invalid COCO input
208 EXPECT_EQ(iter0, nullptr);
209
210 std::shared_ptr<Dataset> ds1 = Coco(folder_path, invalid_annotation_file);
211 EXPECT_NE(ds1, nullptr);
212 // Create an iterator over the result of the above dataset
213 std::shared_ptr<Iterator> iter1 = ds1->CreateIterator();
214 // Expect failure: invalid COCO input
215 EXPECT_EQ(iter1, nullptr);
216
217 std::shared_ptr<Dataset> ds2 = Coco(folder_path, annotation_file, "valid_mode");
218 EXPECT_NE(ds2, nullptr);
219 // Create an iterator over the result of the above dataset
220 std::shared_ptr<Iterator> iter2 = ds2->CreateIterator();
221 // Expect failure: invalid COCO input
222 EXPECT_EQ(iter2, nullptr);
223 }
224
TEST_F(MindDataTestPipeline,TestCocoKeypoint)225 TEST_F(MindDataTestPipeline, TestCocoKeypoint) {
226 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoKeypoint.";
227 // Create a Coco Dataset
228 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
229 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/key_point.json";
230
231 std::shared_ptr<Dataset> ds =
232 Coco(folder_path, annotation_file, "Keypoint", false, std::make_shared<SequentialSampler>(0, 2));
233 EXPECT_NE(ds, nullptr);
234
235 // Create an iterator over the result of the above dataset
236 // This will trigger the creation of the Execution Tree and launch it.
237 std::shared_ptr<Iterator> iter = ds->CreateIterator();
238 EXPECT_NE(iter, nullptr);
239
240 // Iterate the dataset and get each row
241 std::unordered_map<std::string, mindspore::MSTensor> row;
242 ASSERT_OK(iter->GetNextRow(&row));
243
244 std::string expect_file[] = {"000000391895", "000000318219"};
245 std::vector<std::vector<float>> expect_keypoint_vector = {
246 {368.0, 61.0, 1.0, 369.0, 52.0, 2.0, 0.0, 0.0, 0.0, 382.0, 48.0, 2.0, 0.0, 0.0, 0.0, 368.0, 84.0, 2.0,
247 435.0, 81.0, 2.0, 362.0, 125.0, 2.0, 446.0, 125.0, 2.0, 360.0, 153.0, 2.0, 0.0, 0.0, 0.0, 397.0, 167.0, 1.0,
248 439.0, 166.0, 1.0, 369.0, 193.0, 2.0, 461.0, 234.0, 2.0, 361.0, 246.0, 2.0, 474.0, 287.0, 2.0},
249 {244.0, 139.0, 2.0, 0.0, 0.0, 0.0, 226.0, 118.0, 2.0, 0.0, 0.0, 0.0, 154.0, 159.0, 2.0, 143.0, 261.0, 2.0,
250 135.0, 312.0, 2.0, 271.0, 423.0, 2.0, 184.0, 530.0, 2.0, 261.0, 280.0, 2.0, 347.0, 592.0, 2.0, 0.0, 0.0, 0.0,
251 123.0, 596.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}};
252 std::vector<std::vector<dsize_t>> expect_size = {{1, 51}, {1, 51}};
253 std::vector<std::vector<uint32_t>> expect_num_keypoints_list = {{14}, {10}};
254 uint64_t i = 0;
255 while (row.size() != 0) {
256 auto image = row["image"];
257 auto keypoints = row["keypoints"];
258 auto num_keypoints = row["num_keypoints"];
259
260 mindspore::MSTensor expect_image = ReadFileToTensor(folder_path + "/" + expect_file[i] + ".jpg");
261 EXPECT_MSTENSOR_EQ(image, expect_image);
262
263 std::shared_ptr<Tensor> de_expect_keypoints;
264 dsize_t keypoints_size = expect_size[i][0];
265 ASSERT_OK(Tensor::CreateFromVector(expect_keypoint_vector[i], TensorShape(expect_size[i]), &de_expect_keypoints));
266 mindspore::MSTensor expect_keypoints =
267 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_keypoints));
268 EXPECT_MSTENSOR_EQ(keypoints, expect_keypoints);
269
270 std::shared_ptr<Tensor> de_expect_num_keypoints;
271 ASSERT_OK(Tensor::CreateFromVector(expect_num_keypoints_list[i], TensorShape({keypoints_size, 1}),
272 &de_expect_num_keypoints));
273 mindspore::MSTensor expect_num_keypoints =
274 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_num_keypoints));
275 EXPECT_MSTENSOR_EQ(num_keypoints, expect_num_keypoints);
276
277 ASSERT_OK(iter->GetNextRow(&row));
278 i++;
279 }
280
281 EXPECT_EQ(i, 2);
282
283 // Manually terminate the pipeline
284 iter->Stop();
285 }
286
TEST_F(MindDataTestPipeline,TestCocoPanoptic)287 TEST_F(MindDataTestPipeline, TestCocoPanoptic) {
288 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoPanoptic.";
289 // Create a Coco Dataset
290 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
291 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/panoptic.json";
292
293 std::shared_ptr<Dataset> ds =
294 Coco(folder_path, annotation_file, "Panoptic", false, std::make_shared<SequentialSampler>(0, 2));
295 EXPECT_NE(ds, nullptr);
296
297 // Create an iterator over the result of the above dataset
298 // This will trigger the creation of the Execution Tree and launch it.
299 std::shared_ptr<Iterator> iter = ds->CreateIterator();
300 EXPECT_NE(iter, nullptr);
301
302 // Iterate the dataset and get each row
303 std::unordered_map<std::string, mindspore::MSTensor> row;
304 ASSERT_OK(iter->GetNextRow(&row));
305
306 std::string expect_file[] = {"000000391895", "000000574769"};
307 std::vector<std::vector<float>> expect_bbox_vector = {{472, 173, 36, 48, 340, 22, 154, 301, 486, 183, 30, 35},
308 {103, 133, 229, 422, 243, 175, 93, 164}};
309 std::vector<std::vector<uint32_t>> expect_categoryid_vector = {{1, 1, 2}, {1, 3}};
310 std::vector<std::vector<uint32_t>> expect_iscrowd_vector = {{0, 0, 0}, {0, 0}};
311 std::vector<std::vector<uint32_t>> expect_area_vector = {{705, 14062, 626}, {43102, 6079}};
312 std::vector<std::vector<dsize_t>> expect_size = {{3, 4}, {2, 4}};
313 uint64_t i = 0;
314 while (row.size() != 0) {
315 auto image = row["image"];
316 auto bbox = row["bbox"];
317 auto category_id = row["category_id"];
318 auto iscrowd = row["iscrowd"];
319 auto area = row["area"];
320
321 mindspore::MSTensor expect_image = ReadFileToTensor(folder_path + "/" + expect_file[i] + ".jpg");
322 EXPECT_MSTENSOR_EQ(image, expect_image);
323
324 std::shared_ptr<Tensor> de_expect_bbox;
325 dsize_t bbox_size = expect_size[i][0];
326 ASSERT_OK(Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape(expect_size[i]), &de_expect_bbox));
327 mindspore::MSTensor expect_bbox =
328 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_bbox));
329 EXPECT_MSTENSOR_EQ(bbox, expect_bbox);
330
331 std::shared_ptr<Tensor> de_expect_categoryid;
332 ASSERT_OK(Tensor::CreateFromVector(expect_categoryid_vector[i], TensorShape({bbox_size, 1}), &de_expect_categoryid));
333 mindspore::MSTensor expect_categoryid =
334 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_categoryid));
335 EXPECT_MSTENSOR_EQ(category_id, expect_categoryid);
336
337 std::shared_ptr<Tensor> de_expect_iscrowd;
338 ASSERT_OK(Tensor::CreateFromVector(expect_iscrowd_vector[i], TensorShape({bbox_size, 1}), &de_expect_iscrowd));
339 mindspore::MSTensor expect_iscrowd =
340 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_iscrowd));
341 EXPECT_MSTENSOR_EQ(iscrowd, expect_iscrowd);
342
343 std::shared_ptr<Tensor> de_expect_area;
344 ASSERT_OK(Tensor::CreateFromVector(expect_area_vector[i], TensorShape({bbox_size, 1}), &de_expect_area));
345 mindspore::MSTensor expect_area =
346 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_area));
347 EXPECT_MSTENSOR_EQ(area, expect_area);
348
349 ASSERT_OK(iter->GetNextRow(&row));
350 i++;
351 }
352
353 EXPECT_EQ(i, 2);
354
355 // Manually terminate the pipeline
356 iter->Stop();
357 }
358
TEST_F(MindDataTestPipeline,TestCocoPanopticGetClassIndex)359 TEST_F(MindDataTestPipeline, TestCocoPanopticGetClassIndex) {
360 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoPanopticGetClassIndex.";
361 // Create a Coco Dataset
362 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
363 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/panoptic.json";
364
365 std::shared_ptr<Dataset> ds =
366 Coco(folder_path, annotation_file, "Panoptic", false, std::make_shared<SequentialSampler>(0, 2));
367 EXPECT_NE(ds, nullptr);
368
369 std::vector<std::pair<std::string, std::vector<int32_t>>> class_index1 = ds->GetClassIndexing();
370 EXPECT_EQ(class_index1.size(), 3);
371 EXPECT_EQ(class_index1[0].first, "person");
372 EXPECT_EQ(class_index1[0].second[0], 1);
373 EXPECT_EQ(class_index1[0].second[1], 1);
374 EXPECT_EQ(class_index1[1].first, "bicycle");
375 EXPECT_EQ(class_index1[1].second[0], 2);
376 EXPECT_EQ(class_index1[1].second[1], 1);
377 EXPECT_EQ(class_index1[2].first, "car");
378 EXPECT_EQ(class_index1[2].second[0], 3);
379 EXPECT_EQ(class_index1[2].second[1], 1);
380 }
381
TEST_F(MindDataTestPipeline,TestCocoStuff)382 TEST_F(MindDataTestPipeline, TestCocoStuff) {
383 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoStuff.";
384 // Create a Coco Dataset
385 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
386 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
387
388 std::shared_ptr<Dataset> ds =
389 Coco(folder_path, annotation_file, "Stuff", false, std::make_shared<SequentialSampler>(0, 6));
390 EXPECT_NE(ds, nullptr);
391
392 // Create an iterator over the result of the above dataset
393 // This will trigger the creation of the Execution Tree and launch it.
394 std::shared_ptr<Iterator> iter = ds->CreateIterator();
395 EXPECT_NE(iter, nullptr);
396
397 // Iterate the dataset and get each row
398 std::unordered_map<std::string, mindspore::MSTensor> row;
399 ASSERT_OK(iter->GetNextRow(&row));
400
401 std::string expect_file[] = {"000000391895", "000000318219", "000000554625",
402 "000000574769", "000000060623", "000000309022"};
403 std::vector<std::vector<float>> expect_segmentation_vector = {
404 {10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
405 70.0, 72.0, 73.0, 74.0, 75.0, -1.0, -1.0, -1.0, -1.0, -1.0},
406 {20.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0,
407 10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, -1.0},
408 {40.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 40.0, 41.0, 42.0},
409 {50.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0},
410 {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0},
411 {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0}};
412 std::vector<std::vector<dsize_t>> expect_size = {{2, 10}, {2, 11}, {1, 12}, {1, 13}, {1, 14}, {2, 7}};
413 uint64_t i = 0;
414 while (row.size() != 0) {
415 auto image = row["image"];
416 auto segmentation = row["segmentation"];
417
418 mindspore::MSTensor expect_image = ReadFileToTensor(folder_path + "/" + expect_file[i] + ".jpg");
419 EXPECT_MSTENSOR_EQ(image, expect_image);
420
421 std::shared_ptr<Tensor> de_expect_segmentation;
422 ASSERT_OK(Tensor::CreateFromVector(expect_segmentation_vector[i], TensorShape(expect_size[i]), &de_expect_segmentation));
423 mindspore::MSTensor expect_segmentation =
424 mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_expect_segmentation));
425 EXPECT_MSTENSOR_EQ(segmentation, expect_segmentation);
426
427 ASSERT_OK(iter->GetNextRow(&row));
428 i++;
429 }
430
431 EXPECT_EQ(i, 6);
432
433 // Manually terminate the pipeline
434 iter->Stop();
435 }
436
TEST_F(MindDataTestPipeline,TestCocoWithNullSamplerFail)437 TEST_F(MindDataTestPipeline, TestCocoWithNullSamplerFail) {
438 MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoWithNullSamplerFail.";
439 // Create a Coco Dataset
440 std::string folder_path = datasets_root_path_ + "/testCOCO/train";
441 std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json";
442
443 std::shared_ptr<Dataset> ds = Coco(folder_path, annotation_file, "Detection", false, nullptr);
444 EXPECT_NE(ds, nullptr);
445
446 // Create an iterator over the result of the above dataset
447 std::shared_ptr<Iterator> iter = ds->CreateIterator();
448 // Expect failure: invalid COCO input, sampler cannot be nullptr
449 EXPECT_EQ(iter, nullptr);
450 }
451