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.8 kB

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