| 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 | #include "memorydata.h" |
| 16 | |
| 17 | namespace ncnn { |
| 18 | |
| 19 | MemoryData::MemoryData() |
| 20 | { |
| 21 | one_blob_only = false; |
| 22 | support_inplace = false; |
| 23 | } |
| 24 | |
| 25 | int MemoryData::load_param(const ParamDict& pd) |
| 26 | { |
| 27 | w = pd.get(0, 0); |
| 28 | h = pd.get(1, 0); |
| 29 | d = pd.get(11, 0); |
| 30 | c = pd.get(2, 0); |
| 31 | load_type = pd.get(21, 1); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int MemoryData::load_model(const ModelBin& mb) |
| 37 | { |
| 38 | if (d != 0) |
| 39 | { |
| 40 | data = mb.load(w, h, d, c, load_type); |
| 41 | } |
| 42 | else if (c != 0) |
| 43 | { |
| 44 | data = mb.load(w, h, c, load_type); |
| 45 | } |
| 46 | else if (h != 0) |
| 47 | { |
| 48 | data = mb.load(w, h, load_type); |
| 49 | } |
| 50 | else if (w != 0) |
| 51 | { |
| 52 | data = mb.load(w, load_type); |
| 53 | } |
| 54 | else // 0 0 0 |
| 55 | { |
| 56 | data.create(1); |
| 57 | } |
| 58 | if (data.empty()) |
| 59 | return -100; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int MemoryData::forward(const std::vector<Mat>& /*bottom_blobs*/, std::vector<Mat>& top_blobs, const Option& opt) const |
| 65 | { |
| 66 | Mat& top_blob = top_blobs[0]; |
| 67 | |
| 68 | top_blob = data.clone(opt.blob_allocator); |
| 69 | if (top_blob.empty()) |
| 70 | return -100; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | } // namespace ncnn |