std::vector<char> _buffer;
// Reference on loadable Graph
graph::Graph &_graph;
- // Mapping from operator pointer to subgraph pointer
- std::map<const Operator *, const SubGraph *> _op_to_subgraph;
const Model *_model;
};
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));
+ loadOperationIO(op, inputs, outputs);
+ auto input = inputs.at(0);
+ auto size = inputs.at(1);
+
+ // FIXME Handle ResizeBilinearOptions.
+ if (!_graph.operands().at(size).isConstant())
+ throw std::runtime_error("ResizeBilinear: non-constant 'size' is not supported.");
+
+ std::vector<std::int32_t> size_v = _graph.operands().at(size).template asVector<std::int32_t>();
model::operation::ResizeBilinear::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];
+ param.height_out = size_v[0];
+ param.width_out = size_v[1];
std::unique_ptr<model::Operation> new_op(
- new model::operation::ResizeBilinear(inputs, outputs, param));
+ new model::operation::ResizeBilinear({input}, outputs, param));
_graph.addOperation(std::move(new_op));
}
template <typename LoaderDomain, typename SpecificLoader>
void BaseLoader<LoaderDomain, SpecificLoader>::loadSpaceToBatchND(const Operator *op)
{
- model::OperandIndexSequence inputs{(*op->inputs())[0], (*op->inputs())[1], (*op->inputs())[2]};
- model::OperandIndexSequence outputs{(*op->outputs())[0]};
+ model::OperandIndexSequence inputs;
+ model::OperandIndexSequence outputs;
+
+ loadOperationIO(op, inputs, outputs);
std::unique_ptr<model::Operation> new_op{new model::operation::SpaceToBatchND{inputs, outputs}};
_graph.addOperation(std::move(new_op));
template <typename LoaderDomain, typename SpecificLoader>
void BaseLoader<LoaderDomain, SpecificLoader>::loadBatchToSpaceND(const Operator *op)
{
- model::OperandIndexSequence inputs{(*op->inputs())[0], (*op->inputs())[1]};
- model::OperandIndexSequence outputs{(*op->outputs())[0]};
+ model::OperandIndexSequence inputs;
+ model::OperandIndexSequence outputs;
- // Check crop tensor's value
- const auto crop_tensor_index = op->inputs()->Get(2);
- const auto *crop_tensor = _op_to_subgraph[op]->tensors()->Get(crop_tensor_index);
- const auto *crop_buffer = _model->buffers()->Get(crop_tensor->buffer());
+ loadOperationIO(op, inputs, outputs);
+ auto input = inputs.at(0);
+ auto block_shape = inputs.at(1);
+ auto crops = inputs.at(2);
- if (crop_buffer->data()->size() == 0)
- {
- throw std::runtime_error{"Non-const crop input is unsupported"};
- }
+ if (!_graph.operands().at(crops).isConstant())
+ throw std::runtime_error("BatchToSpaceND: non-constant 'crops' is not supported.");
- const auto *crop_ptr = reinterpret_cast<const int32_t *>(crop_buffer->data()->data());
- if (crop_ptr[0] != 0 || crop_ptr[1] != 0 || crop_ptr[2] != 0 || crop_ptr[3] != 0)
- {
- throw std::runtime_error{"Crop value other than {{0, 0}, {0, 0}} is unsupported"};
- }
+ std::vector<std::int32_t> crops_v = _graph.operands().at(crops).template asVector<std::int32_t>();
+ assert(crops_v.size() == 4);
+ if (crops_v != std::vector<std::int32_t>{0, 0, 0, 0})
+ throw std::runtime_error("BatchToSpaceND: 'crops' other than {0, 0, 0, 0} is not supported.");
- std::unique_ptr<model::Operation> new_op{new model::operation::BatchToSpaceND{inputs, outputs}};
+ std::unique_ptr<model::Operation> new_op{
+ new model::operation::BatchToSpaceND{{input, block_shape}, outputs}};
_graph.addOperation(std::move(new_op));
}
// Load subgraphs and mapping from op to subgraph
for (const auto *subgraph : *_model->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);
}