Returns indices of the given tensors in the subgraph. Returns error if a tensor name cannot be found in the subgraph.
| 633 | // Returns indices of the given tensors in the subgraph. Returns error if a |
| 634 | // tensor name cannot be found in the subgraph. |
| 635 | StatusOr<std::vector<int>> GetTensorIndices( |
| 636 | const tflite::SubGraphT& subgraph, |
| 637 | const std::vector<std::string>& tensor_names) { |
| 638 | absl::flat_hash_map<std::string, int> name_to_index; |
| 639 | for (auto index_and_tensor : llvm::enumerate(subgraph.tensors)) { |
| 640 | name_to_index[index_and_tensor.value()->name] = index_and_tensor.index(); |
| 641 | } |
| 642 | |
| 643 | std::vector<int> indices; |
| 644 | indices.reserve(tensor_names.size()); |
| 645 | |
| 646 | for (const auto& name : tensor_names) { |
| 647 | auto found = name_to_index.find(name); |
| 648 | if (found != name_to_index.end()) { |
| 649 | indices.push_back(found->second); |
| 650 | } else { |
| 651 | return errors::InvalidArgument("could not find tensor in subgraph: ", |
| 652 | name); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | return indices; |
| 657 | } |
| 658 | |
| 659 | // Given a list of tensor indices, returns a string of concatenated tensor names |
| 660 | // wrapped in a NamedAttribute. |
no test coverage detected