2

I searched for the best way to do this, but I was unable to find a clear answer.

Was anyone able to build a tensorflow-serving client using cmake?

I am having difficulties with generating CPP files from proto, since they are needed for prediction service. Those proto files also include proto files from tensorflow.

so far I have come up with this:

project(serving C CXX)
find_package(Protobuf REQUIRED)

file(GLOB_RECURSE proto_files RELATIVE ${serving_SOURCE_DIR}/tensorflow/
    "${serving_SOURCE_DIR}/tensorflow/*.proto")

set(PROTOBUF_GENERATE_CPP_APPEND_PATH OFF)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${proto_files})

add_library(tf_protos ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(tf_protos PUBLIC ${PROTOBUF_LIBRARIES})

Cmake builds successfully but the make command gives me an error:

No rule to make target '../tensorflow/tools/proto_text/test.proto', needed by 'tensorflow/tools/proto_text/test.pb.cc'.  Stop.

To overcome the problem of .proto includes not being found I used command

set(PROTOBUF_GENERATE_CPP_APPEND_PATH OFF)

which was explained here: https://groups.google.com/forum/#!topic/protobuf/eow2fNDUHvc

My current folder structure is

serving/
    CmakeLists.txt
    tensorflow/
    tensorflow_serving/
        apis/

Folder apis contains .proto files that are needed in the client implementation and they include .proto files from the folder tensorflow.

Is this even the right way to go?

Any help/advice would be much appreciated.

Maja
  • 61
  • 9

2 Answers2

0

I was able to get it to work in the layout you have where the CMakeLists.txt file is placed in the same level as the serving repository here. You'll need to install Tensorflow too though (using tensorflow_cc).

However, you probably don't want to muck with a fork of the official tensorflow/serving repository so I went a step further and moved the CMakeLists.txt out so you can just submodule the official repository. I made an example here

The gist is that the protobuf CMake submodule expects proto files to be laid out in the same directory from which it's called. I made some modifications to the submodules to let us call it from a level above serving and to ensure it invokes the compiler with the include paths in the right order to support the nested structure of the proto files in serving/tensorflow_serving/apis/* (and placing it accordingly in the specified build directory)

Hopefully someone else with better knowhow can make this better!

Eddie Ng
  • 13
  • 3
  • I gave up. What I was able to find is, that CMake command (GENERATE_CPP) only generates the .pb files in its build tree. What I did is copy all the needed proto files to a seperate folder (keeping the directory structure) and generated the .pb files explicitly by calling the protoc shell command. And then built a seperate prrotobuf library with cmake. – Maja Dec 13 '17 at 13:29
  • I used [this](https://github.com/philosophus/tf-serving-demo) as a reference. Explained in more detail [here](http://fdahms.com/2017/03/05/tensorflow-serving-jvm-client/) by Florian Dahms – Maja Dec 20 '17 at 12:24
0

These worked for me.

https://github.com/wardsng/inception_cmake

https://github.com/FloopCZ/tensorflow_cc

You can choose a private install directory instead of the default, e.g. /usr/local/...

cmake -DCMAKE_INSTALL_PREFIX= ..

B Abali
  • 433
  • 2
  • 10