MCPcopy Create free account
hub / github.com/alibaba/MNN / genStaticModel

Function genStaticModel

tools/converter/source/common/convertToStaticModel.cpp:118–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118static void genStaticModel(CommandBuffer buffer, const std::string& modelName, std::map<Tensor*, std::pair<std::string, int>>& tensorNames, std::vector<std::string>&& outputNames, const Net* originNetInfo) {
119 MNN_PRINT("gen Static Model ... \n");
120 std::unique_ptr<MNN::NetT> netT = std::unique_ptr<MNN::NetT>(new MNN::NetT());
121 netT->outputName = std::move(outputNames);
122 netT->usage = Usage_INFERENCE_STATIC;
123 std::map<Tensor*, int> tensorMap;
124 // Add tensorName to new netT
125 netT->tensorName.resize(tensorNames.size());
126 std::vector<std::unique_ptr<OpT>> inputOps;
127 for (auto& iter : tensorNames) {
128 netT->tensorName[iter.second.second] = iter.second.first;
129 tensorMap.insert(std::make_pair(iter.first, iter.second.second));
130 if (TensorUtils::getDescribe(iter.first)->usage == MNN::Tensor::InsideDescribe::INPUT) {
131 std::unique_ptr<OpT> input(new OpT);
132 input->type = OpType_Input;
133 input->name = iter.second.first;
134 input->outputIndexes = {iter.second.second};
135 input->main.value = new InputT;
136 input->main.type = OpParameter_Input;
137 input->main.AsInput()->dims = iter.first->shape();
138 input->main.AsInput()->dformat = TensorUtils::getDescribe(iter.first)->dimensionFormat;
139 auto type = iter.first->getType();
140 if (type.code == halide_type_float) {
141 if (type.bits == 32) {
142 input->main.AsInput()->dtype = DataType_DT_FLOAT;
143 } else if (type.bits == 16) {
144 input->main.AsInput()->dtype = DataType_DT_HALF;
145 }
146 } else if (type.code == halide_type_int) {
147 if (type.bits == 32) {
148 input->main.AsInput()->dtype = DataType_DT_INT32;
149 } else if (type.bits == 16) {
150 input->main.AsInput()->dtype = DataType_DT_INT16;
151 } else if (type.bits == 8) {
152 input->main.AsInput()->dtype = DataType_DT_INT8;
153 }
154 } else if (type.code == halide_type_uint) {
155 if (type.bits == 16) {
156 input->main.AsInput()->dtype = DataType_DT_UINT16;
157 } else if (type.bits == 8) {
158 input->main.AsInput()->dtype = DataType_DT_UINT8;
159 }
160 }
161 inputOps.emplace_back(std::move(input));
162 }
163 }
164 // add Tensors to netT
165 for (auto& iterP : buffer.command) {
166 auto& iter = *iterP;
167 std::function<void(Tensor*)> insertTensor = [&](Tensor* t) {
168 if (tensorMap.find(t) == tensorMap.end()) {
169 int index = static_cast<int>(tensorMap.size());
170 tensorMap.insert(std::make_pair(t, index));
171 std::string tensorName = "ExtraTensor_" + std::to_string(index);
172 netT->tensorName.push_back(tensorName);
173 }
174 };
175 for (auto& t : iter.inputs) {

Callers 1

converToStaticModelFunction · 0.85

Calls 13

AsInputMethod · 0.80
shapeMethod · 0.80
to_stringFunction · 0.50
resizeMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
getTypeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
dimensionsMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected