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.

squeeze.cpp 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "squeeze.h"
  15. namespace ncnn {
  16. DEFINE_LAYER_CREATOR(Squeeze)
  17. Squeeze::Squeeze()
  18. {
  19. one_blob_only = true;
  20. support_inplace = false;
  21. }
  22. int Squeeze::load_param(const ParamDict& pd)
  23. {
  24. squeeze_w = pd.get(0, 0);
  25. squeeze_h = pd.get(1, 0);
  26. squeeze_c = pd.get(2, 0);
  27. return 0;
  28. }
  29. int Squeeze::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
  30. {
  31. int w = bottom_blob.w;
  32. int h = bottom_blob.h;
  33. int channels = bottom_blob.c;
  34. int dims = bottom_blob.dims;
  35. top_blob = bottom_blob;
  36. if (squeeze_c && dims == 3 && channels == 1)
  37. {
  38. if (squeeze_h && h == 1)
  39. top_blob = bottom_blob.reshape(w, opt.blob_allocator);
  40. else
  41. top_blob = bottom_blob.reshape(w, h, opt.blob_allocator);
  42. }
  43. else if (squeeze_h && dims >= 2 && h == 1)
  44. {
  45. if (squeeze_w && w == 1)
  46. top_blob = bottom_blob.reshape(channels, opt.blob_allocator);
  47. else
  48. top_blob = bottom_blob.reshape(w, channels, opt.blob_allocator);
  49. }
  50. else if (squeeze_w && dims >= 1 && w == 1)
  51. {
  52. if (squeeze_h && h == 1)
  53. top_blob = bottom_blob.reshape(channels, opt.blob_allocator);
  54. else
  55. top_blob = bottom_blob.reshape(h, channels, opt.blob_allocator);
  56. }
  57. if (top_blob.empty())
  58. return -100;
  59. return 0;
  60. }
  61. } // namespace ncnn