• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "common/common.h"
21 #include "utils/ms_utils.h"
22 #include "minddata/dataset/core/client.h"
23 #include "minddata/dataset/engine/datasetops/source/voc_op.h"
24 #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h"
25 #include "minddata/dataset/include/dataset/datasets.h"
26 #include "minddata/dataset/util/status.h"
27 #include "gtest/gtest.h"
28 #include "utils/log_adapter.h"
29 #include "securec.h"
30 
31 namespace common = mindspore::common;
32 
33 using namespace mindspore::dataset;
34 using mindspore::LogStream;
35 using mindspore::ExceptionType::NoExceptionType;
36 using mindspore::MsLogLevel::ERROR;
37 
38 std::shared_ptr<ExecutionTree> Build(std::vector<std::shared_ptr<DatasetOp>> ops);
39 
40 class MindDataTestVOCOp : public UT::DatasetOpTesting {
41  protected:
42 };
43 
TEST_F(MindDataTestVOCOp,TestVOCDetection)44 TEST_F(MindDataTestVOCOp, TestVOCDetection) {
45   std::string dataset_path;
46   dataset_path = datasets_root_path_ + "/testVOC2012";
47   std::shared_ptr<Dataset> ds =
48     VOC(dataset_path, "Detection", "train", {}, false, std::make_shared<SequentialSampler>(0, 0));
49   EXPECT_NE(ds, nullptr);
50   std::shared_ptr<Iterator> iter = ds->CreateIterator();
51   EXPECT_NE(iter, nullptr);
52   std::unordered_map<std::string, mindspore::MSTensor> row;
53   ASSERT_OK(iter->GetNextRow(&row));
54   int row_count = 0;
55   while (row.size() != 0) {
56     auto image = row["image"];
57     auto label = row["label"];
58     MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
59     MS_LOG(INFO) << "Tensor label shape: " << label.Shape();
60     ASSERT_OK(iter->GetNextRow(&row));
61     row_count++;
62   }
63   ASSERT_EQ(row_count, 9);
64   iter->Stop();
65 }
66 
TEST_F(MindDataTestVOCOp,TestVOCSegmentation)67 TEST_F(MindDataTestVOCOp, TestVOCSegmentation) {
68   std::string dataset_path;
69   dataset_path = datasets_root_path_ + "/testVOC2012";
70   std::shared_ptr<Dataset> ds =
71     VOC(dataset_path, "Segmentation", "train", {}, false, std::make_shared<SequentialSampler>(0, 0));
72   EXPECT_NE(ds, nullptr);
73   std::shared_ptr<Iterator> iter = ds->CreateIterator();
74   EXPECT_NE(iter, nullptr);
75   std::unordered_map<std::string, mindspore::MSTensor> row;
76   ASSERT_OK(iter->GetNextRow(&row));
77   int row_count = 0;
78   while (!row.empty()) {
79     auto image = row["image"];
80     auto target = row["target"];
81     MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
82     MS_LOG(INFO) << "Tensor target shape: " << target.Shape();
83     ASSERT_OK(iter->GetNextRow(&row));
84     row_count++;
85   }
86   ASSERT_EQ(row_count, 10);
87   iter->Stop();
88 }
89 
TEST_F(MindDataTestVOCOp,TestVOCClassIndex)90 TEST_F(MindDataTestVOCOp, TestVOCClassIndex) {
91   std::string dataset_path;
92   dataset_path = datasets_root_path_ + "/testVOC2012";
93   std::map<std::string, int32_t> class_index;
94   class_index["car"] = 0;
95   class_index["cat"] = 1;
96   class_index["train"] = 5;
97   std::shared_ptr<Dataset> ds =
98     VOC(dataset_path, "Detection", "train", class_index, false, std::make_shared<SequentialSampler>(0, 0));
99   EXPECT_NE(ds, nullptr);
100   std::shared_ptr<Iterator> iter = ds->CreateIterator();
101   EXPECT_NE(iter, nullptr);
102   std::unordered_map<std::string, mindspore::MSTensor> row;
103   ASSERT_OK(iter->GetNextRow(&row));
104   int row_count = 0;
105   while (!row.empty()) {
106     auto image = row["image"];
107     auto label = row["label"];
108     MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
109     MS_LOG(INFO) << "Tensor label shape: " << label.Shape();
110     ASSERT_OK(iter->GetNextRow(&row));
111     row_count++;
112   }
113   ASSERT_EQ(row_count, 6);
114   iter->Stop();
115 }
116