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.

bboxop_common.h 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_
  17. #define TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_
  18. #include "cvop_common.h"
  19. #include "minddata/dataset/util/path.h"
  20. namespace UT {
  21. namespace CVOP {
  22. namespace BBOXOP {
  23. class BBoxOpCommon : public CVOpCommon {
  24. public:
  25. enum FileType {
  26. kExpected,
  27. kActual
  28. };
  29. BBoxOpCommon();
  30. ~BBoxOpCommon();
  31. /// \brief Sets up the class's variable, images_and_annotations
  32. void SetUp() override;
  33. /// \brief Get all images and annotations in images_and_annotations TensorTable from dir
  34. /// \param[in] dir directory containing images and annotation folders
  35. /// \param[in] num_of_samples number of rows to fetch (default = 1)
  36. void GetInputImagesAndAnnotations(const std::string &dir, std::size_t num_of_samples = 1);
  37. /// \brief Save the given tensor table
  38. /// \param[in] type type of images to be stored (e.g. Expected or Actual)
  39. /// \param[in] op_name name of op being tested
  40. /// \param[in] table rows of images and corresponding annotations
  41. void SaveImagesWithAnnotations(FileType type, const std::string &op_name, const TensorTable &table);
  42. /// \brief Compare actual and expected results. The images will have the bounding boxes on them
  43. /// Log if images don't match
  44. /// \param[in] op_name name of op being tested
  45. void CompareActualAndExpected(const std::string &op_name);
  46. /// \brief Load BBox data from an XML file into a Tensor
  47. /// \param[in] path path to XML bbox data file
  48. /// \param[in, out] target_BBox pointer to a Tensor to load
  49. /// \return True if file loaded successfully, false if error -> logged to STD out
  50. bool LoadAnnotationFile(const std::string &path, std::shared_ptr<Tensor> *target_BBox);
  51. TensorTable images_and_annotations_;
  52. private:
  53. // directory of image_folder when the dataset/data gets transferred to build
  54. std::string image_folder_build_;
  55. // directory of image_folder in the source project (used to store expected results)
  56. std::string image_folder_src_;
  57. };
  58. } // namespace BBOXOP
  59. } // namespace CVOP
  60. } // namespace UT
  61. #endif // TESTS_DATASET_UT_CORE_COMMON_DE_UT_BBOXOP_COMMON_H_