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.

testresize.cpp 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "include/dataset/datasets.h"
  29. #include "include/dataset/iterator.h"
  30. #include "include/dataset/vision_lite.h"
  31. #include "include/dataset/transforms.h"
  32. #include "include/api/types.h"
  33. using mindspore::dataset::Album;
  34. using mindspore::dataset::Dataset;
  35. using mindspore::dataset::Iterator;
  36. using mindspore::dataset::SequentialSampler;
  37. using mindspore::dataset::TensorTransform;
  38. using mindspore::dataset::vision::ResizePreserveAR;
  39. int main(int argc, char **argv) {
  40. std::string folder_path = "./testAlbum/images";
  41. std::string schema_file = "./testAlbum/datasetSchema.json";
  42. std::vector<std::string> column_names = {"image", "label", "id"};
  43. // Create a Album Dataset
  44. std::shared_ptr<Dataset> ds =
  45. Album(folder_path, schema_file, column_names, true, std::make_shared<SequentialSampler>(0, 1));
  46. ds = ds->SetNumWorkers(1);
  47. std::shared_ptr<TensorTransform> resize(new ResizePreserveAR(1000, 1000));
  48. ds = ds->Map({resize}, {"image"}, {"image", "ratio", "invM"});
  49. std::shared_ptr<Iterator> iter = ds->CreateIterator();
  50. std::unordered_map<std::string, mindspore::MSTensor> row;
  51. iter->GetNextRow(&row);
  52. uint64_t i = 0;
  53. while (row.size() != 0) {
  54. i++;
  55. iter->GetNextRow(&row);
  56. }
  57. iter->Stop();
  58. }