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.

F_batch_norm.cpp 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "pass_level2.h"
  15. namespace pnnx {
  16. class F_batch_norm : public GraphRewriterPass
  17. {
  18. public:
  19. const char* match_pattern_graph() const
  20. {
  21. return R"PNNXIR(7767517
  22. 11 10
  23. pnnx.Input input_0 0 1 input
  24. pnnx.Input input_1 0 1 running_mean
  25. pnnx.Input input_2 0 1 running_var
  26. pnnx.Input input_3 0 1 weight
  27. pnnx.Input input_4 0 1 bias
  28. prim::Constant op_0 0 1 training value=*
  29. prim::Constant op_1 0 1 momentum value=*
  30. prim::Constant op_2 0 1 eps value=%eps
  31. prim::Constant op_3 0 1 cudnn_enabled value=*
  32. aten::batch_norm op_4 9 1 input weight bias running_mean running_var training momentum eps cudnn_enabled out
  33. pnnx.Output output 1 0 out
  34. )PNNXIR";
  35. }
  36. const char* type_str() const
  37. {
  38. return "F.batch_norm";
  39. }
  40. };
  41. REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_batch_norm, 10)
  42. class F_batch_norm_1 : public GraphRewriterPass
  43. {
  44. public:
  45. const char* match_pattern_graph() const
  46. {
  47. return R"PNNXIR(7767517
  48. 9 10
  49. pnnx.Input input_0 0 1 input
  50. pnnx.Input input_1 0 1 running_mean
  51. pnnx.Input input_2 0 1 running_var
  52. pnnx.Input input_3 0 1 weight
  53. pnnx.Input input_4 0 1 bias
  54. prim::Constant op_0 0 1 momentum value=*
  55. prim::Constant op_1 0 1 eps value=%eps
  56. aten::_native_batch_norm_legit_no_training op_2 7 3 input weight bias running_mean running_var momentum eps out save_mean save_invstd
  57. pnnx.Output output 3 0 out save_mean save_invstd
  58. )PNNXIR";
  59. }
  60. const char* type_str() const
  61. {
  62. return "F.batch_norm";
  63. }
  64. void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& captured_attrs) const
  65. {
  66. GraphRewriterPass::write(op, captured_params, captured_attrs);
  67. op->outputs.resize(1);
  68. }
  69. };
  70. REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_batch_norm_1, 10)
  71. class F_batch_norm_onnx : public GraphRewriterPass
  72. {
  73. public:
  74. const char* match_pattern_graph() const
  75. {
  76. return R"PNNXIR(7767517
  77. 7 6
  78. pnnx.Input input_0 0 1 input
  79. pnnx.Input input_1 0 1 weight
  80. pnnx.Input input_2 0 1 bias
  81. pnnx.Input input_3 0 1 running_mean
  82. pnnx.Input input_4 0 1 running_var
  83. BatchNormalization op_0 5 1 input weight bias running_mean running_var out epsilon=%eps training_mode=* momentum=*
  84. pnnx.Output output 1 0 out
  85. )PNNXIR";
  86. }
  87. const char* type_str() const
  88. {
  89. return "F.batch_norm";
  90. }
  91. };
  92. REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_batch_norm_onnx, 10)
  93. class F_batch_norm_onnx_1 : public GraphRewriterPass
  94. {
  95. public:
  96. const char* match_pattern_graph() const
  97. {
  98. return R"PNNXIR(7767517
  99. 7 6
  100. pnnx.Input input_0 0 1 input
  101. pnnx.Input input_1 0 1 weight
  102. pnnx.Input input_2 0 1 bias
  103. pnnx.Input input_3 0 1 running_mean
  104. pnnx.Input input_4 0 1 running_var
  105. BatchNormalization op_0 5 1 input weight bias running_mean running_var out epsilon=%eps momentum=*
  106. pnnx.Output output 1 0 out
  107. )PNNXIR";
  108. }
  109. const char* type_str() const
  110. {
  111. return "F.batch_norm";
  112. }
  113. };
  114. REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_batch_norm_onnx_1, 10)
  115. } // namespace pnnx