assert(false && "All unsupported types should have been found before this pass.");
}
- assert(layer.top_size() == static_cast<int>(outputs.size()) && "Number of outputs differs.");
+ assert(static_cast<int>(outputs.size()) == layer.top_size() && "Number of outputs differs.");
for (int i = 0; i < layer.top_size(); ++i)
- _blobNameToOpOutput[layer.top(i)] = outputs.at(i);
+ setOutputForBlob(layer.top(i), outputs[i]);
}
void CaffeImporter::collectUnsupportedOp(const LayerParameter &lp)
std::vector<mir::Operation::Output *> inputs;
for (const auto &input_name : layer.bottom())
- inputs.push_back(_blobNameToOpOutput.at(input_name));
+ inputs.push_back(getOutputForBlob(input_name));
return inputs;
}
+mir::Operation::Output *CaffeImporter::getOutputForBlob(const std::string &blob_name) const
+{
+ return _blobNameToOpOutput.at(blob_name);
+}
+
+void CaffeImporter::setOutputForBlob(const std::string &blob_name, mir::Operation::Output *output)
+{
+ const auto it = _blobNameToOpOutput.find(blob_name);
+ if (it != _blobNameToOpOutput.cend())
+ {
+ // caffe 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(blob_name);
+ _blobNameToOpOutput[blob_name] = output;
+}
+
void CaffeImporter::setGraphOutputs()
{
const auto &last_layer = _net->layer(_net->layer_size() - 1);
- // For now, we assume that:
+ // TODO For now, we assume that:
// - there is exactly one output;
// - the output is from the last layer.
- auto output = _blobNameToOpOutput[last_layer.top(0)];
+ auto output = getOutputForBlob(last_layer.top(0));
_graph->create<mir::ops::OutputOp>(output->getNode()->getName(), output);
output->getNode()->setName("");
}