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.

test_de.cc 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <vector>
  18. #include "common/common_test.h"
  19. #include "include/api/types.h"
  20. #include "minddata/dataset/include/minddata_eager.h"
  21. #include "minddata/dataset/include/vision.h"
  22. #include "minddata/dataset/kernels/tensor_op.h"
  23. using namespace mindspore::api;
  24. using namespace mindspore::dataset::vision;
  25. class TestDE : public ST::Common {
  26. public:
  27. TestDE() {}
  28. };
  29. TEST_F(TestDE, ResNetPreprocess) {
  30. std::vector<std::shared_ptr<Tensor>> images;
  31. MindDataEager::LoadImageFromDir("/home/workspace/mindspore_dataset/imagenet/imagenet_original/val/n01440764",
  32. &images);
  33. MindDataEager Compose({Decode(), Resize({224, 224}),
  34. Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}),
  35. HWC2CHW()});
  36. for (auto &img : images) {
  37. img = Compose(img);
  38. }
  39. ASSERT_EQ(images[0]->Shape().size(), 3);
  40. ASSERT_EQ(images[0]->Shape()[0], 3);
  41. ASSERT_EQ(images[0]->Shape()[1], 224);
  42. ASSERT_EQ(images[0]->Shape()[2], 224);
  43. }
  44. TEST_F(TestDE, TestDvpp) {
  45. std::vector<std::shared_ptr<Tensor>> images;
  46. MindDataEager::LoadImageFromDir("/root/Dvpp_Unit_Dev/val2014_test/", &images);
  47. MindDataEager Solo({DvppDecodeResizeCropJpeg({224, 224}, {256, 256})});
  48. for (auto &img : images) {
  49. img = Solo(img);
  50. }
  51. ASSERT_EQ(images[0]->Shape().size(), 3);
  52. ASSERT_EQ(images[0]->Shape()[0], 224 * 224 * 1.5);
  53. ASSERT_EQ(images[0]->Shape()[1], 1);
  54. ASSERT_EQ(images[0]->Shape()[2], 1);
  55. }