I managed to get a network parsed from caffe and I serialized it.
According to the following program, I saved the serialized result to “serialized_engine.txt” file successfully .
IHostMemory serializedModel = engine->serialize();
…
// store model to disk
std::ofstream ofs(“serialized_engine.txt”, std::ios::out | std::ios::binary);
ofs.write((char)(serialized_model ->data()), serialized_model ->size());
ofs.close();
But I don’t know how to use the “serialized_engine.txt” and haven’t found something useful in the examples.
Anyone knows how to transform the “serialized_engine.txt” to the serializedModel in inference ?
Please take a look at the latest blog post below. Section “Reuse the TensorRT Engine” describes deserialization process. In short, you need to read the binary file into the memory (e.g. character array), create IRuntime object and use it’s method to recreate engine from serialized part.
In the code example within “Reuse the TensorRT Engine”, there is the following line:
string buffer = readBuffer(enginePath);
I assume the “readBuffer” function is just taking the contents of the engine file and placing it withing the string buffer. Could you please elaborate a little on your preferred method of doing this?
You are correct. The purpose of readBuffer function is to read binary file and place it’s content into a collection of characters. You can find it’s source code at the following GitHub location below. For a reference, I also copy-paste function definition.