MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetBuffer

Method GetBuffer

tensorflow/lite/experimental/writer/writer_lib.cc:234–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234TfLiteStatus InterpreterWriter::GetBuffer(std::unique_ptr<uint8_t[]>* out,
235 size_t* size) {
236 if (!out || !size) return kTfLiteError;
237 FlatBufferBuilder builder(/*initial_size=*/10240);
238
239 std::vector<Offset<SubGraph>> subgraphs_as_vector;
240 { // subgraph specific stuff
241 auto tensors = ExportTensors(&builder);
242 std::vector<int> written_inputs =
243 RemapTensorIndicesToWritten(interpreter_->inputs());
244 std::vector<int> written_outputs =
245 RemapTensorIndicesToWritten(interpreter_->outputs());
246 auto inputs = ExportVector<int32_t>(&builder, written_inputs);
247 auto outputs = ExportVector<int32_t>(&builder, written_outputs);
248
249 auto ops = ExportOperators(&builder);
250 subgraphs_as_vector.push_back(
251 CreateSubGraph(builder, tensors, inputs, outputs, ops, /* name */ 0));
252 }
253 Offset<Vector<Offset<Buffer>>> buffers = ExportBuffers(&builder);
254
255 auto description = builder.CreateString("Exported from Interpreter.");
256
257 auto op_codes = CreateOpCodeTable(&builder);
258 auto model = CreateModel(builder, TFLITE_SCHEMA_VERSION, op_codes,
259 builder.CreateVector(subgraphs_as_vector),
260 description, buffers);
261 ::tflite::FinishModelBuffer(builder, model);
262 const uint8_t* buffer = builder.GetBufferPointer();
263 *size = builder.GetSize();
264 (*out).reset(new uint8_t[*size]);
265 memcpy(out->get(), buffer, *size);
266 return kTfLiteOk;
267}
268
269TfLiteStatus InterpreterWriter::Write(const std::string& filename) {
270 std::unique_ptr<uint8_t[]> buffer;

Callers 11

AddTfOpMethod · 0.45
BaseMfccOpModelMethod · 0.45
ExportOperatorsFunction · 0.45
SerializeMethod · 0.45
SerializeMethod · 0.45
mainFunction · 0.45
MicroFrontendOpModelMethod · 0.45

Calls 13

ExportTensorsFunction · 0.85
ExportOperatorsFunction · 0.85
CreateSubGraphFunction · 0.85
ExportBuffersFunction · 0.85
CreateModelFunction · 0.85
FinishModelBufferFunction · 0.85
CreateVectorMethod · 0.80
inputsMethod · 0.45
outputsMethod · 0.45
push_backMethod · 0.45
GetSizeMethod · 0.45
resetMethod · 0.45

Tested by 8

AddTfOpMethod · 0.36
BaseMfccOpModelMethod · 0.36
mainFunction · 0.36
MicroFrontendOpModelMethod · 0.36