1 /**
2 * Copyright 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 <sys/stat.h>
17 #include <unistd.h>
18 #include <fstream>
19 #include <iostream>
20 #include <map>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include <unordered_map>
25 #include <unordered_set>
26 #include <utility>
27 #include <vector>
28
29 #include "include/dataset/datasets.h"
30 #include "include/dataset/iterator.h"
31 #include "include/dataset/vision_lite.h"
32 #include "include/dataset/transforms.h"
33 #include "include/api/types.h"
34
35 using mindspore::dataset::Album;
36 using mindspore::dataset::Dataset;
37 using mindspore::dataset::Iterator;
38 using mindspore::dataset::SequentialSampler;
39 using mindspore::dataset::TensorTransform;
40 using mindspore::dataset::vision::ResizePreserveAR;
41
42
main(int argc,char ** argv)43 int main(int argc, char **argv) {
44 std::string folder_path = "./testAlbum/images";
45 std::string schema_file = "./testAlbum/datasetSchema.json";
46 std::vector<std::string> column_names = {"image", "label", "id"};
47
48 // Create a Album Dataset
49 std::shared_ptr<Dataset> ds =
50 Album(folder_path, schema_file, column_names, true, std::make_shared<SequentialSampler>(0, 1));
51 ds = ds->SetNumWorkers(1);
52
53 std::shared_ptr<TensorTransform> resize(new ResizePreserveAR(1000, 1000));
54 ds = ds->Map({resize}, {"image"}, {"image", "ratio", "invM"});
55
56 std::shared_ptr<Iterator> iter = ds->CreateIterator();
57
58 std::unordered_map<std::string, mindspore::MSTensor> row;
59 iter->GetNextRow(&row);
60
61 while (row.size() != 0) {
62 iter->GetNextRow(&row);
63 }
64
65 iter->Stop();
66 }
67