| 58 | } |
| 59 | |
| 60 | std::unordered_map<std::string, bool> GetNodesHasDynamicShapeMap(const GraphDef& gdef) { |
| 61 | // NOTE(jiankeng.pt): should be optimized via topological sort algorithm later |
| 62 | std::unordered_map<std::string, bool> output_shapes; |
| 63 | for (const NodeDef& node : gdef.node()) { |
| 64 | output_shapes[node.name()] = HasDynamicShapeOutput(const_cast<NodeDef*>(&node)); |
| 65 | } |
| 66 | |
| 67 | // True when node has dynamic input or output, false else. |
| 68 | std::unordered_map<std::string, bool> result; |
| 69 | for (const NodeDef& node : gdef.node()) { |
| 70 | // output shapes |
| 71 | if (output_shapes[node.name()]) { |
| 72 | result[node.name()] = true; |
| 73 | } else { |
| 74 | // input shapes |
| 75 | result[node.name()] = false; |
| 76 | for (std::string in_name : node.input()) { |
| 77 | // control flow edge |
| 78 | if (in_name[0] == '^') { |
| 79 | in_name = in_name.substr(1); |
| 80 | } |
| 81 | auto offset = in_name.find(":"); |
| 82 | if (offset != std::string::npos) { |
| 83 | in_name = in_name.substr(0, offset); |
| 84 | } |
| 85 | if (!output_shapes[in_name]) continue; |
| 86 | result[node.name()] = true; |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | // Sets any parameters not specified in a node to their defaults. |
| 96 | Status AddDefaultAttributes(const GraphDef& input_graph_def, |