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

Method ParseTensors

tensorflow/lite/model.cc:427–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427TfLiteStatus InterpreterBuilder::ParseTensors(
428 const flatbuffers::Vector<flatbuffers::Offset<Buffer>>* buffers,
429 const flatbuffers::Vector<flatbuffers::Offset<Tensor>>* tensors,
430 Subgraph* subgraph) {
431 TfLiteStatus status = kTfLiteOk;
432
433 // A little helper to get the names of inputs and outputs. Note that they
434 // must outlive the subgraph.
435 auto get_name = [](const tflite::Tensor* t) -> const char* {
436 auto name = t->name();
437 if (name) return name->c_str();
438 return kEmptyTensorName;
439 };
440
441 for (int i = 0; i < tensors->Length(); ++i) {
442 const auto* tensor = tensors->Get(i);
443 std::vector<int> dims = FlatBufferIntArrayToVector(tensor->shape());
444
445 TfLiteType type;
446 if (ConvertTensorType(tensor->type(), &type, error_reporter_) !=
447 kTfLiteOk) {
448 status = kTfLiteError;
449 continue;
450 }
451 auto get_readonly_data = [&](const char** buffer_data,
452 size_t* buffer_size) {
453 // TODO(aselle): Check what happens if we have an unspecified size
454 // constant.
455 *buffer_data = nullptr;
456 if (tensor->buffer() == 0) return kTfLiteOk;
457 if (tensor->buffer() >= buffers->size()) {
458 error_reporter_->Report(
459 "Tensor %d specifies out of range buffer %d (only %d buffers).\n",
460 i, tensor->buffer(), buffers->size());
461 return kTfLiteError;
462 }
463 if (auto* buffer = (*buffers)[tensor->buffer()]) {
464 if (auto* array = buffer->data()) {
465 if (size_t size = array->size()) {
466 *buffer_size = size;
467 *buffer_data = reinterpret_cast<const char*>(array->data());
468 return kTfLiteOk;
469 }
470 }
471 }
472 return kTfLiteOk;
473 };
474 size_t buffer_size = 0;
475 const char* buffer_ptr;
476 TF_LITE_ENSURE_STATUS(get_readonly_data(&buffer_ptr, &buffer_size));
477
478 const auto* src_quantization = tensor->quantization();
479 TfLiteQuantization quantization;
480 if (ParseQuantization(src_quantization, &quantization, dims) != kTfLiteOk) {
481 status = kTfLiteError;
482 continue;
483 }
484

Callers

nothing calls this directly

Calls 14

ConvertTensorTypeFunction · 0.85
c_strMethod · 0.80
nameMethod · 0.65
typeMethod · 0.65
LengthMethod · 0.45
GetMethod · 0.45
shapeMethod · 0.45
bufferMethod · 0.45
sizeMethod · 0.45
ReportMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected