From: 박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Thu, 8 Mar 2018 00:57:23 +0000 (+0900) Subject: Introduce graphdump tool (#43) X-Git-Tag: 0.1~674 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5642e7a5feffca9a34e4c56845eb120035de56e4;p=platform%2Fcore%2Fml%2Fnnfw.git Introduce graphdump tool (#43) This commit introduces graphdump tool that shows the content of saved models(.pb) in text. Note that decode.sh under tools/graphdef already allows us to dump the content of saved models, but this graphdump is introduced to test tensorflow_graphdef library. Signed-off-by: Jonghyun Park --- diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index b383236..cb946d9 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -19,6 +19,10 @@ set(TENSORFLOW_LITE_BASE ${TENSORFLOW_BASE}/tensorflow/contrib/lite) # 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) @@ -41,7 +45,8 @@ if(ENABLE_TENSORFLOW_GRAPHDEF) 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) # diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1abaede..ab88628 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,2 +1,3 @@ +add_subdirectory(graphdump) add_subdirectory(tflite_run) add_subdirectory(nnapi_bindings) diff --git a/tools/graphdump/CMakeLists.txt b/tools/graphdump/CMakeLists.txt new file mode 100644 index 0000000..ebb6a4f --- /dev/null +++ b/tools/graphdump/CMakeLists.txt @@ -0,0 +1,7 @@ +# 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) diff --git a/tools/graphdump/src/graphdump.cc b/tools/graphdump/src/graphdump.cc new file mode 100644 index 0000000..f96c813 --- /dev/null +++ b/tools/graphdump/src/graphdump.cc @@ -0,0 +1,40 @@ +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include + +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; +}