# TensorFlow Graph Definition Accessor
#
if(ENABLE_TENSORFLOW_GRAPHDEF)
+ include(FindProtobuf)
+
+ find_package(Protobuf REQUIRED)
+
list(APPEND TF_GRAPH_PROTO_TAGS tensorflow/core/framework/versions)
list(APPEND TF_GRAPH_PROTO_TAGS tensorflow/core/framework/function)
list(APPEND TF_GRAPH_PROTO_TAGS tensorflow/core/framework/types)
endforeach()
add_library(tensorflow_graphdef ${TF_GRAPH_PROTO_SRCS})
- target_include_directories(tensorflow_graphdef PUBLIC ${TF_GRAPH_PROTO_GENERATED})
+ target_include_directories(tensorflow_graphdef PUBLIC ${TF_GRAPH_PROTO_GENERATED} ${PROTOBUF_INCLUDE_DIRS})
+ target_link_libraries(tensorflow_graphdef PUBLIC ${PROTOBUF_LIBRARIES})
endif(ENABLE_TENSORFLOW_GRAPHDEF)
#
+add_subdirectory(graphdump)
add_subdirectory(tflite_run)
add_subdirectory(nnapi_bindings)
--- /dev/null
+# NOTE Graph dump uses libtensorflow_graphdef
+if(ENABLE_TENSORFLOW_GRAPHDEF)
+ list(APPEND SRCS "src/graphdump.cc")
+
+ add_executable(graphdump ${SRCS})
+ target_link_libraries(graphdump tensorflow_graphdef)
+endif(ENABLE_TENSORFLOW_GRAPHDEF)
--- /dev/null
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/text_format.h>
+
+#include <tensorflow/core/framework/graph.pb.h>
+
+#include <iostream>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ tensorflow::GraphDef graph;
+
+ bool loaded = false;
+ {
+ int fd = open(argv[1], O_RDONLY);
+ google::protobuf::io::FileInputStream raw(fd);
+ google::protobuf::io::CodedInputStream in(&raw);
+
+ loaded = graph.ParseFromCodedStream(&in);
+
+ if (!loaded)
+ {
+ std::cerr << "ERROR: ParseFromCodedStream failed" << std::endl;
+ }
+
+ close(fd);
+ }
+
+ if (loaded)
+ {
+ google::protobuf::io::FileOutputStream output(1);
+ google::protobuf::TextFormat::Print(graph, &output);
+ }
+ return 0;
+}