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