| 73 | } // namespace |
| 74 | |
| 75 | NodeMap::NodeMap(GraphDef* graph) { |
| 76 | CHECK(graph != nullptr); |
| 77 | for (int i = 0; i < graph->node_size(); i++) { |
| 78 | NodeDef* node = graph->mutable_node(i); |
| 79 | const string& node_name = node->name(); |
| 80 | auto rslt = nodes_.emplace(node_name, node); |
| 81 | // Check that the graph doesn't contain multiple nodes with the same name. |
| 82 | if (!rslt.second) { |
| 83 | // The first node found with a given name becomes the canonical. |
| 84 | LOG(WARNING) << "Duplicated node in the graph: " << node_name; |
| 85 | } |
| 86 | NodeDef* canonical = rslt.second ? node : rslt.first->second; |
| 87 | for (const auto& input : node->input()) { |
| 88 | outputs_[NodeName(input)].insert(canonical); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void NodeMap::RemoveNode(const string& name) { |
| 94 | nodes_.erase(NodeName(name)); |