modelbin.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef NCNN_MODELBIN_H
  15. #define NCNN_MODELBIN_H
  16. #include "mat.h"
  17. namespace ncnn {
  18. class DataReader;
  19. class NCNN_EXPORT ModelBin
  20. {
  21. public:
  22. ModelBin();
  23. virtual ~ModelBin();
  24. // element type
  25. // 0 = auto
  26. // 1 = float32
  27. // 2 = float16
  28. // 3 = int8
  29. // load vec
  30. virtual Mat load(int w, int type) const = 0;
  31. // load image
  32. virtual Mat load(int w, int h, int type) const;
  33. // load dim
  34. virtual Mat load(int w, int h, int c, int type) const;
  35. // load cube
  36. virtual Mat load(int w, int h, int d, int c, int type) const;
  37. };
  38. class ModelBinFromDataReaderPrivate;
  39. class NCNN_EXPORT ModelBinFromDataReader : public ModelBin
  40. {
  41. public:
  42. explicit ModelBinFromDataReader(const DataReader& dr);
  43. virtual ~ModelBinFromDataReader();
  44. virtual Mat load(int w, int type) const;
  45. private:
  46. ModelBinFromDataReader(const ModelBinFromDataReader&);
  47. ModelBinFromDataReader& operator=(const ModelBinFromDataReader&);
  48. private:
  49. ModelBinFromDataReaderPrivate* const d;
  50. };
  51. class ModelBinFromMatArrayPrivate;
  52. class NCNN_EXPORT ModelBinFromMatArray : public ModelBin
  53. {
  54. public:
  55. // construct from weight blob array
  56. explicit ModelBinFromMatArray(const Mat* weights);
  57. virtual ~ModelBinFromMatArray();
  58. virtual Mat load(int w, int type) const;
  59. private:
  60. ModelBinFromMatArray(const ModelBinFromMatArray&);
  61. ModelBinFromMatArray& operator=(const ModelBinFromMatArray&);
  62. private:
  63. ModelBinFromMatArrayPrivate* const d;
  64. };
  65. } // namespace ncnn
  66. #endif // NCNN_MODELBIN_H