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.

testlenet.cpp 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <map>
  19. #include <memory>
  20. #include <set>
  21. #include <string>
  22. #include <unordered_map>
  23. #include <unordered_set>
  24. #include <utility>
  25. #include <vector>
  26. #include "include/dataset/datasets.h"
  27. #include "include/dataset/iterator.h"
  28. #include "include/dataset/vision_lite.h"
  29. #include "include/dataset/transforms.h"
  30. #include "include/api/types.h"
  31. using mindspore::dataset::Dataset;
  32. using mindspore::dataset::Iterator;
  33. using mindspore::dataset::Mnist;
  34. using mindspore::dataset::TensorTransform;
  35. int main(int argc, char **argv) {
  36. std::string folder_path = "./testMnistData/";
  37. std::shared_ptr<Dataset> ds = Mnist(folder_path, "all");
  38. std::shared_ptr<TensorTransform> resize(new mindspore::dataset::vision::Resize({32, 32}));
  39. ds = ds->Map({resize});
  40. ds = ds->Shuffle(2);
  41. ds = ds->Batch(2);
  42. std::shared_ptr<Iterator> iter = ds->CreateIterator();
  43. std::unordered_map<std::string, mindspore::MSTensor> row;
  44. iter->GetNextRow(&row);
  45. uint64_t i = 0;
  46. while (row.size() != 0) {
  47. i++;
  48. iter->GetNextRow(&row);
  49. }
  50. iter->Stop();
  51. }