Skip to content

A Java Library for Protobuf in TensorFlow and TensorFlow-Serving

License

Notifications You must be signed in to change notification settings

YuanWenqing/tensorflow4j

Repository files navigation

TensorFlow proto

Since TensorFlow and TensorFlow-Serving do not support official jars for their protobuf files right now, we create this project to do it just for convenience and sharing.

Usage

tensorflow-proto contains and compiles all protobuf files in TensorFlow, and serving-proto does that for TensorFlow-Serving. Since compiling of serving-proto imports protobuf from tensorflow-proto, actually serving-proto contains all that tensorflow-proto has. Therefore serving-proto is the only library you need when you want to do something with TensorFlow-Serving.

maven:

<dependencies>
    <dependency>
        <groupId>xyz.codemeans.tensorflow4j</groupId>
        <artifactId>tensorflow-proto</artifactId>
        <version>1.12.0</version>
    </dependency>

    <dependency>
        <groupId>xyz.codemeans.tensorflow4j</groupId>
        <artifactId>serving-proto</artifactId>
        <version>1.12.0</version>
    </dependency>
</dependencies>

gradle:

implementation 'xyz.codemeans.tensorflow4j:tensorflow-proto:1.12.0'

implementation 'xyz.codemeans.tensorflow4j:serving-proto:1.12.0'

Sync Protobuf Files

Clone those two projects, checkout the latest version(or any other version you want), and then run:

python sync_proto.py /path/to/tensorflow_project tensorflow-proto
python sync_proto.py /path/to/tensorflow_serving_project serving-proto

NOTE: a little BUGFIX must be done to tensorflow/compiler/tf2xla/host_compute_metadata.proto, change java_outer_classname as below:

// option java_outer_classname = "Tf2XlaProtos";
option java_outer_classname = "HostComputeMetadataProtos";

Build JAR Library

Requirements:

  • protoc
  • gradle
  • protobuf lib

run:

gradle clean build

If you want to publish the built jars, you can run:

# publish to local maven repository (`~/.m2`)
gradle local

or

# config maven publishing and publish to nexus
gradle publish

Version

Current version of TensorFlow and TensorFlow-Servng are both 1.12.0.

If you want to build library for another version, you MUST:

  • checkout TensorFlow and TensorFlow-Serving source of exact version you want, then sync all proto files
  • change version and publish setting in build.gradle for publishing somewhere