Search code examples
javapythontensorflowjython

what is best way to use trained tensorflow in java


I am coding UI by javaFx in eclipse because I can only use java, no python, no c.

Now I try to use trained tensorflow file in this UI. (this tensorflow file is under python)

I am looking for several ways (API, jython, TCP/IP) but I am not sure which one is best.

Please write your opinion which has more advantages or fewer disadvantages.


Solution

  • I think there are two ways for that,

    1. tensorflow-serving which uses grpc to connect from java to the serving server, making it independent of any language. Look here for details.
    2. Use tensorflow java API. Here and Here is an example of using object detection model in native java program.

    Now, tensorflow-serving is the preferred way to go, as there are several advantages. Serving is heavily optimized for speed and resource management like GPU. It also stacks multiple requests (if there is too many) and then processes them in a batch which utilizes the GPU efficiently.