| 57 | } |
| 58 | |
| 59 | int InitModelConfig(ModelConfig& model_config, std::string proto_file, std::string model_file) { |
| 60 | FILE* fp = fopen(proto_file.c_str(), "r"); |
| 61 | if (fp == NULL) { |
| 62 | printf("invalid proto file\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | fseek(fp, 0, SEEK_END); |
| 67 | int size = ftell(fp); |
| 68 | rewind(fp); |
| 69 | char* buffer = new char[size + 1]; |
| 70 | memset(buffer, 0, size + 1); |
| 71 | int ret = fread(buffer, 1, size, fp); |
| 72 | if (ret != size) { |
| 73 | printf("read proto_file failed!\n"); |
| 74 | return -1; |
| 75 | } |
| 76 | fclose(fp); |
| 77 | |
| 78 | ParseProtoFile(buffer, size); |
| 79 | std::string buffer_str(buffer); |
| 80 | |
| 81 | model_config.params.push_back(buffer_str); |
| 82 | delete[] buffer; |
| 83 | |
| 84 | { |
| 85 | std::ifstream model_stream(model_file); |
| 86 | if (!model_stream.is_open() || !model_stream.good()) { |
| 87 | printf("read model_file failed!\n"); |
| 88 | return -1; |
| 89 | } |
| 90 | std::string model_content = |
| 91 | std::string((std::istreambuf_iterator<char>(model_stream)), std::istreambuf_iterator<char>()); |
| 92 | |
| 93 | model_config.params.push_back(model_content); |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | bool GetInputType(std::string name, FileFormat& format) { |
| 100 | int pos = name.rfind('.'); |
no test coverage detected