model::Activation convertActivation(ActivationFunctionType type);
model::DataType tensorTypeToDataType(TensorType type);
- // Load data from buffer to tensor on index
- void loadConstantTensor(const Buffer *buffer, const uint32_t &index);
// Create operands form tflite::Tensor
void loadOperand(const Tensor *tensor);
void loadOperationIO(const Operator *op, model::OperandIndexSequence &inputs,
std::vector<char> _buffer;
// Reference on loadable Graph
graph::Graph &_graph;
- // Mapping from tensor index to Graph OperandIndex
- std::map<uint32_t, model::OperandIndex> _tensor_to_operand;
// Mapping from operator pointer to subgraph pointer
std::map<const Operator *, const SubGraph *> _op_to_subgraph;
const Model *_model;
model::TypeInfo type_info(data_type);
// Create operand
const auto &operand_index = _graph.addOperand(shape, type_info);
- // Buffer index
- if (tensor->buffer() != 0)
- _tensor_to_operand[tensor->buffer()] = operand_index;
+
+ // Constant tensors are indicated by non-empty data.
+ const auto *data = _model->buffers()->Get(tensor->buffer())->data();
+ if (data != nullptr)
+ {
+ auto ptr = nnfw::cpp14::make_unique<model::CachedData>(data->data(), data->size());
+ _graph.setOperandValue(operand_index, std::move(ptr));
+ }
+
// Name unused
// auto name = tensor->name();
// Quantization
}
template <typename LoaderDomain, typename SpecificLoader>
-void BaseLoader<LoaderDomain, SpecificLoader>::loadConstantTensor(const Buffer *buffer,
- const uint32_t &index)
-{
- const auto *data = buffer->data();
- if (data != nullptr)
- {
- auto ptr = nnfw::cpp14::make_unique<model::CachedData>(data->data(), data->size());
- const auto &operand_index = _tensor_to_operand[index];
- auto &operand = _graph.operands().at(operand_index);
- operand.data(std::move(ptr));
- }
-}
-
-template <typename LoaderDomain, typename SpecificLoader>
void BaseLoader<LoaderDomain, SpecificLoader>::loadModel()
{
static_cast<SpecificLoader *>(this)->verify();
// const auto version = _model->version();
// Description unused
// const auto *description = _model->description();
- const auto *buffers = _model->buffers();
// Metabuffer unsued
// const auto *metadata_buffer = _model->metadata_buffer();
// Load subgraphs and mapping from op to subgraph
static_cast<SpecificLoader *>(this)->loadSubgraph(subgraph);
}
- // Load buffers with constant tensors
- for (uint32_t ind = 0; ind < buffers->size(); ind++)
- {
- loadConstantTensor(buffers->Get(ind), ind);
- }
_graph.finishBuilding();
}