1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_EXAMPLE_EXAMPLE_PARSER_CONFIGURATION_H_ 17 #define TENSORFLOW_CORE_EXAMPLE_EXAMPLE_PARSER_CONFIGURATION_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/core/example/example.pb.h" 23 #include "tensorflow/core/example/example_parser_configuration.pb.h" 24 #include "tensorflow/core/framework/allocator.h" 25 #include "tensorflow/core/framework/graph.pb.h" 26 #include "tensorflow/core/framework/tensor.h" 27 #include "tensorflow/core/framework/types.h" 28 #include "tensorflow/core/platform/types.h" 29 #include "tensorflow/core/public/session.h" 30 #include "tensorflow/core/util/example_proto_helper.h" 31 #include "tensorflow/core/util/sparse/sparse_tensor.h" 32 33 // This is a set of helper methods that will make it possible to share 34 // tensorflow::Example proto Tensor conversion code inside the ExampleParserOp 35 // OpKernel as well as in external code. 36 namespace tensorflow { 37 38 // Given a graph and the node_name of a ParseExample op, 39 // extract the FixedLenFeature/VarLenFeature configurations. 40 Status ExtractExampleParserConfiguration( 41 const tensorflow::GraphDef& graph, const string& node_name, 42 tensorflow::Session* session, 43 std::vector<FixedLenFeature>* fixed_len_features, 44 std::vector<VarLenFeature>* var_len_features); 45 46 // Given a config proto, ostensibly extracted via python, 47 // fill a vector of C++ structs suitable for calling 48 // the tensorflow.Example -> Tensor conversion code. 49 Status ExampleParserConfigurationProtoToFeatureVectors( 50 const ExampleParserConfiguration& config_proto, 51 std::vector<FixedLenFeature>* fixed_len_features, 52 std::vector<VarLenFeature>* var_len_features); 53 54 } // namespace tensorflow 55 56 #endif // TENSORFLOW_CORE_EXAMPLE_EXAMPLE_PARSE_CONFIGURATION_H_ 57