// TODO Caffe2 does not provide a way to detect model inputs. For now assume that the first input
// of the first operation is the only input to the model.
const auto &input_name = _predict_net->op(0).input(0);
- _blobNameToOutput[input_name] = _opCreator->createInput(input_name, _inputShapes[0]);
+ auto input = _opCreator->createInput(input_name, _inputShapes[0]);
+ setOutputForTensor(input_name, input);
for (const auto &op : _predict_net->op())
createMIRNodesFromOp(op);
for (size_t i = 0; i < outputs.size(); ++i)
{
- // caffe2 input blob name could be same as output blob name, and next line will overwrite
- // '_blobNameToOpOutput' element, but in all networks that I saw it was not a problem
- _blobNameToOutput[op.output(i)] = outputs.at(i);
+ setOutputForTensor(op.output(i), outputs[i]);
}
// `outputs` can be empty if constant input was not processed.
for (const auto &input_name : op.input())
{
- if (_blobNameToOutput.find(input_name) == _blobNameToOutput.end())
- throw std::runtime_error("Cannot find blob \"" + input_name + "\".");
- inputs.push_back(_blobNameToOutput[input_name]);
+ inputs.push_back(getOutputForTensor(input_name));
}
return inputs;
}
+void Caffe2Importer::setOutputForTensor(const std::string &tensor_name, Operation::Output *output)
+{
+ auto it = _blobNameToOutput.find(tensor_name);
+ if (it != _blobNameToOutput.cend())
+ {
+ // caffe2 input blob name could be same as output blob name, and next line will overwrite
+ // '_blobNameToOpOutput' element, but in all networks that I saw it was not a problem
+ it->second->setName("");
+ }
+ output->setName(tensor_name);
+ _blobNameToOutput[tensor_name] = output;
+}
+
+mir::Operation::Output *Caffe2Importer::getOutputForTensor(const std::string &name) const
+{
+ return _blobNameToOutput.at(name);
+}
+
void Caffe2Importer::setGraphOutputs()
{
// For now, we assume that: