pooling.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_
  13. #define TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_
  14. #include <cstdint>
  15. #include "tensorflow/lite/c/builtin_op_data.h"
  16. #include "tensorflow/lite/c/common.h"
  17. #include "tensorflow/lite/micro/kernels/micro_ops.h"
  18. namespace tflite {
  19. extern const int kPoolingInputTensor;
  20. extern const int kPoolingOutputTensor;
  21. struct OpDataPooling {
  22. TfLitePaddingValues padding;
  23. int32_t activation_min;
  24. int32_t activation_max;
  25. float activation_min_f32;
  26. float activation_max_f32;
  27. };
  28. TfLiteStatus CalculateOpDataPooling(const TfLiteContext* context,
  29. const TfLitePoolParams* params,
  30. const TfLiteTensor* input,
  31. const TfLiteTensor* output,
  32. OpDataPooling* data);
  33. TfLiteStatus PoolingPrepare(TfLiteContext* context, TfLiteNode* node);
  34. void AveragePoolingEvalFloat(const TfLiteContext* context,
  35. const TfLiteNode* node,
  36. const TfLitePoolParams* params,
  37. const OpDataPooling* data,
  38. const TfLiteEvalTensor* input,
  39. TfLiteEvalTensor* output);
  40. void AveragePoolingEvalQuantized(TfLiteContext* context, const TfLiteNode* node,
  41. const TfLitePoolParams* params,
  42. const OpDataPooling* data,
  43. const TfLiteEvalTensor* input,
  44. TfLiteEvalTensor* output);
  45. void MaxPoolingEvalFloat(TfLiteContext* context, TfLiteNode* node,
  46. TfLitePoolParams* params, const OpDataPooling* data,
  47. const TfLiteEvalTensor* input,
  48. TfLiteEvalTensor* output);
  49. void MaxPoolingEvalQuantized(TfLiteContext* context, TfLiteNode* node,
  50. TfLitePoolParams* params,
  51. const OpDataPooling* data,
  52. const TfLiteEvalTensor* input,
  53. TfLiteEvalTensor* output);
  54. #if defined(CMSIS_NN)
  55. TfLiteRegistration Register_AVERAGE_POOL_2D_INT8();
  56. TfLiteRegistration Register_MAX_POOL_2D_INT8();
  57. #else
  58. inline TfLiteRegistration Register_AVERAGE_POOL_2D_INT8() {
  59. return tflite::Register_AVERAGE_POOL_2D();
  60. }
  61. inline TfLiteRegistration Register_MAX_POOL_2D_INT8() {
  62. return tflite::Register_MAX_POOL_2D();
  63. }
  64. #endif
  65. } // namespace tflite
  66. #endif // TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_