MCPcopy Create free account
hub / github.com/Tencent/TNN / GetModelConfig

Function GetModelConfig

test/test.cc:260–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258 }
259
260 ModelConfig GetModelConfig() {
261 ModelConfig config;
262 config.model_type = ConvertModelType(FLAGS_mt);
263 if (config.model_type == MODEL_TYPE_TNN || config.model_type == MODEL_TYPE_OPENVINO ||
264 config.model_type == MODEL_TYPE_NCNN) {
265 std::string network_path = FLAGS_mp;
266 int size = static_cast<int>(network_path.size());
267 std::string model_path;
268
269 // TNN file names: xxx.tnnproto xxx.tnnmodel
270 // NCNN file names: xxx.param xxx.bin
271 if (config.model_type == MODEL_TYPE_TNN) {
272 model_path = network_path.substr(0, size - 5) + "model";
273 } else if (config.model_type == MODEL_TYPE_NCNN) {
274 model_path = network_path.substr(0, size - 5) + "bin";
275 } else {
276 model_path = network_path.substr(0, size - 3) + "bin";
277 }
278
279 std::ifstream proto_stream(network_path);
280 if (!proto_stream.is_open() || !proto_stream.good()) {
281 printf("read proto_file failed!\n");
282 return config;
283 }
284 auto buffer =
285 std::string((std::istreambuf_iterator<char>(proto_stream)), std::istreambuf_iterator<char>());
286 config.params.push_back(buffer);
287
288 if (config.model_type == MODEL_TYPE_TNN || config.model_type == MODEL_TYPE_NCNN) {
289 std::ifstream model_stream(model_path, std::ios::binary);
290 if (!model_stream.is_open() || !model_stream.good()) {
291 config.params.push_back("");
292 return config;
293 }
294 std::stringstream model_content;
295 model_content << model_stream.rdbuf();
296
297 config.params.push_back(model_content.str());
298 } else {
299 config.params.push_back(model_path);
300 }
301 } else {
302 config.params.push_back(FLAGS_mp);
303 }
304 return config;
305 }
306
307 NetworkConfig GetNetworkConfig() {
308 NetworkConfig config;

Callers 1

RunFunction · 0.85

Calls 3

ConvertModelTypeFunction · 0.85
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected