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.

x86-example.cc 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright 2020 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 <string>
  17. #include <fstream>
  18. #include <iostream>
  19. #include <memory>
  20. #include "minddata/dataset/include/datasets.h"
  21. #include "minddata/dataset/engine/ir/datasetops/source/cifar10_node.h"
  22. #include "minddata/dataset/util/path.h"
  23. using Dataset = mindspore::dataset::api::Dataset;
  24. using Iterator = mindspore::dataset::api::Iterator;
  25. using mindspore::dataset::Tensor;
  26. using mindspore::dataset::api::Cifar10;
  27. using mindspore::dataset::api::RandomSampler;
  28. int main() {
  29. MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar10Dataset.";
  30. // Create a Cifar10 Dataset
  31. std::string folder_path = "./testCifar10Data/";
  32. std::shared_ptr<Dataset> ds = Cifar10(folder_path, std::string(), RandomSampler(false, 10));
  33. // Create an iterator over the result of the above dataset
  34. // This will trigger the creation of the Execution Tree and launch it.
  35. std::shared_ptr<Iterator> iter = ds->CreateIterator();
  36. // Iterate the dataset and get each row
  37. std::unordered_map<std::string, std::shared_ptr<Tensor>> row;
  38. iter->GetNextRow(&row);
  39. uint64_t i = 0;
  40. while (row.size() != 0) {
  41. i++;
  42. auto image = row["image"];
  43. MS_LOG(INFO) << "Tensor image shape: " << image->shape();
  44. iter->GetNextRow(&row);
  45. }
  46. // Manually terminate the pipeline
  47. iter->Stop();
  48. }