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.

layer.cpp 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2017 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 "layer.h"
  15. #include <string.h>
  16. namespace ncnn {
  17. Layer::Layer()
  18. {
  19. one_blob_only = false;
  20. support_inplace = false;
  21. }
  22. Layer::~Layer()
  23. {
  24. }
  25. int Layer::load_param(const ParamDict& /*pd*/)
  26. {
  27. return 0;
  28. }
  29. int Layer::load_model(const ModelBin& /*mb*/)
  30. {
  31. return 0;
  32. }
  33. int Layer::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_blobs) const
  34. {
  35. if (!support_inplace)
  36. return -1;
  37. top_blobs = bottom_blobs;
  38. for (int i = 0; i < (int)top_blobs.size(); i++)
  39. {
  40. top_blobs[i] = bottom_blobs[i].clone();
  41. if (top_blobs[i].empty())
  42. return -100;
  43. }
  44. return forward_inplace(top_blobs);
  45. }
  46. int Layer::forward(const Mat& bottom_blob, Mat& top_blob) const
  47. {
  48. if (!support_inplace)
  49. return -1;
  50. top_blob = bottom_blob.clone();
  51. if (top_blob.empty())
  52. return -100;
  53. return forward_inplace(top_blob);
  54. }
  55. int Layer::forward_inplace(std::vector<Mat>& /*bottom_top_blobs*/) const
  56. {
  57. return -1;
  58. }
  59. int Layer::forward_inplace(Mat& /*bottom_top_blob*/) const
  60. {
  61. return -1;
  62. }
  63. #include "layer_declaration.h"
  64. static const layer_registry_entry layer_registry[] =
  65. {
  66. #include "layer_registry.h"
  67. };
  68. static const int layer_registry_entry_count = sizeof(layer_registry) / sizeof(layer_registry_entry);
  69. #if NCNN_STRING
  70. int layer_to_index(const char* type)
  71. {
  72. for (int i=0; i<layer_registry_entry_count; i++)
  73. {
  74. if (strcmp(type, layer_registry[i].name) == 0)
  75. return i;
  76. }
  77. return -1;
  78. }
  79. Layer* create_layer(const char* type)
  80. {
  81. int index = layer_to_index(type);
  82. if (index == -1)
  83. return 0;
  84. return create_layer(index);
  85. }
  86. #endif // NCNN_STRING
  87. Layer* create_layer(int index)
  88. {
  89. if (index < 0 || index >= layer_registry_entry_count)
  90. return 0;
  91. layer_creator_func layer_creator = layer_registry[index].creator;
  92. if (!layer_creator)
  93. return 0;
  94. return layer_creator();
  95. }
  96. } // namespace ncnn