void loadDiv(const Operator *op);
void loadRelu(const Operator *op);
void loadRelu6(const Operator *op);
+ void loadResizeBilinear(const Operator *op);
void loadRsqrt(const Operator *op);
void loadSqrt(const Operator *op);
void loadSquaredDifference(const Operator *op);
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;
// Mapping from operator code to BuiltinOperator
std::vector<BuiltinOperator> _op_code_to_builtin_op;
std::unordered_map<uint32_t, std::string> _opcode_index_to_custom_opcode;
+ const Model *_model;
};
template <typename LoaderDomain, typename SpecificLoader>
}
template <typename LoaderDomain, typename SpecificLoader>
+void BaseLoader<LoaderDomain, SpecificLoader>::loadResizeBilinear(const Operator *op)
+{
+ model::OperandIndexSequence inputs;
+ model::OperandIndexSequence outputs;
+
+ const auto input_index = (*op->inputs())[0];
+ inputs.append(model::OperandIndex(input_index));
+ const auto output_index = (*op->outputs())[0];
+ outputs.append(model::OperandIndex(output_index));
+
+ model::operation::ResizeBilinearNode::Param param;
+ const auto size_tensor_index = op->inputs()->Get(1);
+ const auto *size_tensor = _op_to_subgraph[op]->tensors()->Get(size_tensor_index);
+ const auto *size_buffer = _model->buffers()->Get(size_tensor->buffer());
+ assert(size_buffer->data()->size() != 0);
+ const auto *size_out = reinterpret_cast<const int32_t *>(size_buffer->data()->data());
+ param.height_out = size_out[0];
+ param.width_out = size_out[1];
+
+ std::unique_ptr<model::Operation> new_op(
+ new model::operation::ResizeBilinearNode(inputs, outputs, param));
+ _graph.addOperation(std::move(new_op));
+}
+
+template <typename LoaderDomain, typename SpecificLoader>
void BaseLoader<LoaderDomain, SpecificLoader>::loadRsqrt(const Operator *op)
{
model::OperandIndexSequence inputs;
case BuiltinOperator::BuiltinOperator_RELU6:
loadRelu6(op);
return;
+ case BuiltinOperator::BuiltinOperator_RESIZE_BILINEAR:
+ loadResizeBilinear(op);
+ return;
case BuiltinOperator::BuiltinOperator_RSQRT:
loadRsqrt(op);
return;
template <typename LoaderDomain, typename SpecificLoader>
void BaseLoader<LoaderDomain, SpecificLoader>::loadModel()
{
- const auto *model = LoaderDomain::GetModel(_buffer.data());
+ _model = LoaderDomain::GetModel(_buffer.data());
// Version unused
- // const auto version = model->version();
- const auto *op_codes = model->operator_codes();
- const auto *subgraphs = model->subgraphs();
+ // const auto version = _model->version();
+ const auto *op_codes = _model->operator_codes();
+ const auto *subgraphs = _model->subgraphs();
// Description unused
- // const auto *description = model->description();
- const auto *buffers = model->buffers();
+ // const auto *description = _model->description();
+ const auto *buffers = _model->buffers();
// Metabuffer unsued
- // const auto *metadata_buffer = model->metadata_buffer();
+ // const auto *metadata_buffer = _model->metadata_buffer();
// Use operator codes
for (const auto *op_code : *op_codes)
{
// Custom code unsued
// Version unused
}
- // Load subgraphs
+ // Load subgraphs and mapping from op to subgraph
for (const auto *subgraph : *subgraphs)
{
+ // NOTE This loop have to be called before loadOperation
+ for (const auto *op : *subgraph->operators())
+ {
+ _op_to_subgraph[op] = subgraph;
+ }
+
static_cast<SpecificLoader *>(this)->loadSubgraph(subgraph);
}
// Load buffers with constant tensors