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.

pad_op.h 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Copyright 2019 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 DATASET_KERNELS_IMAGE_PAD_OP_H_
  17. #define DATASET_KERNELS_IMAGE_PAD_OP_H_
  18. #include <memory>
  19. #include <vector>
  20. #include "dataset/core/tensor.h"
  21. #include "dataset/kernels/tensor_op.h"
  22. #include "dataset/kernels/image/image_utils.h"
  23. #include "dataset/util/status.h"
  24. namespace mindspore {
  25. namespace dataset {
  26. class PadOp : public TensorOp {
  27. public:
  28. // Default values, also used by python_bindings.cc
  29. static const BorderType kDefBorderType;
  30. static const uint8_t kDefFillR;
  31. static const uint8_t kDefFillG;
  32. static const uint8_t kDefFillB;
  33. // Constructor for PadOp.
  34. // @param pad_top number of pixels to pad the top of image with.
  35. // @param pad_bottom number of pixels to pad the bottom of the image with.
  36. // @param pad_left number of pixels to pad the left of the image with.
  37. // @param pad_right number of pixels to pad the right of the image with.
  38. // @param border_types BorderType enum, the type of boarders that we are using.
  39. // @param fill_r R value for the color to pad with.
  40. // @param fill_g G value for the color to pad with.
  41. // @param fill_b B value for the color to pad with.
  42. PadOp(int32_t pad_top, int32_t pad_bottom, int32_t pad_left, int32_t pad_right, BorderType border_types,
  43. uint8_t fill_r = kDefFillR, uint8_t fill_g = kDefFillG, uint8_t fill_b = kDefFillB);
  44. ~PadOp() override = default;
  45. void Print(std::ostream &out) const override { out << "PadOp: "; }
  46. Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
  47. Status OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) override;
  48. private:
  49. int32_t pad_top_;
  50. int32_t pad_bottom_;
  51. int32_t pad_left_;
  52. int32_t pad_right_;
  53. BorderType boarder_type_;
  54. uint8_t fill_r_;
  55. uint8_t fill_g_;
  56. uint8_t fill_b_;
  57. };
  58. } // namespace dataset
  59. } // namespace mindspore
  60. #endif // DATASET_KERNELS_IMAGE_PAD_OP_H_