| 36 | // So we need to read the deploy file to get the input |
| 37 | |
| 38 | bool readBinaryProto(trtcaffe::NetParameter* net, const char* file, size_t bufSize) |
| 39 | { |
| 40 | CHECK_NULL_RET_VAL(net, false) |
| 41 | CHECK_NULL_RET_VAL(file, false) |
| 42 | using namespace google::protobuf::io; |
| 43 | |
| 44 | std::ifstream stream(file, std::ios::in | std::ios::binary); |
| 45 | if (!stream) |
| 46 | { |
| 47 | RETURN_AND_LOG_ERROR(false, "Could not open file " + std::string(file)); |
| 48 | } |
| 49 | |
| 50 | IstreamInputStream rawInput(&stream); |
| 51 | CodedInputStream codedInput(&rawInput); |
| 52 | #if GOOGLE_PROTOBUF_VERSION >= 3011000 |
| 53 | codedInput.SetTotalBytesLimit(int(bufSize)); |
| 54 | #else |
| 55 | // Note: This WARs the very low default size limit (64MB) |
| 56 | codedInput.SetTotalBytesLimit(int(bufSize), -1); |
| 57 | #endif |
| 58 | bool ok = net->ParseFromCodedStream(&codedInput); |
| 59 | stream.close(); |
| 60 | |
| 61 | if (!ok) |
| 62 | { |
| 63 | RETURN_AND_LOG_ERROR(false, "Could not parse binary model file"); |
| 64 | } |
| 65 | |
| 66 | return ok; |
| 67 | } |
| 68 | |
| 69 | bool readTextProto(trtcaffe::NetParameter* net, const char* file) |
| 70 | { |