Add TensorFlow Lite runtime version

This version is shared with the TensorFlow runtime version.

PiperOrigin-RevId: 239032347
This commit is contained in:
Jared Duke 2019-03-18 12:00:33 -07:00 committed by TensorFlower Gardener
parent 00d8c76eb4
commit 724d99bef8
13 changed files with 71 additions and 9 deletions

View File

@ -45,9 +45,17 @@ TFLITE_DEFAULT_COPTS = if_not_windows([
])
cc_library(
name = "schema_fbs_version",
name = "version",
hdrs = ["version.h"],
copts = TFLITE_DEFAULT_COPTS,
# Note that we only use the header defines from :version_lib.
deps = ["//tensorflow/core:version_lib"],
)
# TODO(b/128420794): Migrate clients to use :version directly.
alias(
name = "schema_fbs_version",
actual = ":version",
)
cc_library(
@ -181,10 +189,10 @@ cc_library(
":graph_info",
":memory_planner",
":minimal_logging",
":schema_fbs_version",
":simple_memory_arena",
":string",
":util",
":version",
"//tensorflow/lite/c:c_api_internal",
"//tensorflow/lite/core/api",
"//tensorflow/lite/nnapi:nnapi_implementation",

View File

@ -44,7 +44,6 @@ cc_library(
deps = [
"//tensorflow/lite:builtin_op_data",
"//tensorflow/lite:framework",
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite:string",
"//tensorflow/lite:string_util",
"//tensorflow/lite/kernels:builtin_ops",

View File

@ -22,7 +22,6 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/string_util.h"
#include "tensorflow/lite/version.h"
namespace tflite {
namespace label_image {

View File

@ -64,6 +64,7 @@ cc_library(
":c_api_internal",
"//tensorflow/lite:context",
"//tensorflow/lite:framework",
"//tensorflow/lite:version",
"//tensorflow/lite/kernels:builtin_ops",
],
)

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/version.h"
#ifdef __cplusplus
extern "C" {
@ -49,6 +50,8 @@ class CallbackErrorReporter : public tflite::ErrorReporter {
// LINT.IfChange
const char* TFL_Version() { return TFLITE_VERSION_STRING; }
TFL_Model* TFL_NewModel(const void* model_data, size_t model_size) {
auto model = tflite::FlatBufferModel::BuildFromBuffer(
static_cast<const char*>(model_data), model_size);

View File

@ -59,6 +59,11 @@ typedef TfLiteStatus TFL_Status;
typedef TfLiteTensor TFL_Tensor;
typedef TfLiteType TFL_Type;
// --------------------------------------------------------------------------
// TFL_Version returns a string describing version information of the
// TensorFlow Lite library. TensorFlow Lite uses semantic versioning.
TFL_CAPI_EXPORT extern const char* TFL_Version(void);
// --------------------------------------------------------------------------
// TFL_Model wraps a loaded TensorFlow Lite model.
typedef struct TFL_Model TFL_Model;

View File

@ -23,6 +23,8 @@ limitations under the License.
namespace {
TEST(CAPI, Version) { EXPECT_STRNE("", TFL_Version()); }
TEST(CApiSimple, Smoke) {
TFL_Model* model = TFL_NewModelFromFile(
"tensorflow/lite/testdata/add.bin");

View File

@ -72,7 +72,7 @@ public enum DataType {
"DataType error: DataType "
+ c
+ " is not recognized in Java (version "
+ TensorFlowLite.version()
+ TensorFlowLite.runtimeVersion()
+ ")");
}

View File

@ -23,8 +23,21 @@ public final class TensorFlowLite {
private TensorFlowLite() {}
/**
* Returns the version of the underlying TensorFlowLite model schema.
*
* @deprecated Prefer using {@link #runtimeVersion() or #schemaVersion()}.
*/
@Deprecated
public static String version() {
return schemaVersion();
}
/** Returns the version of the underlying TensorFlowLite runtime. */
public static native String version();
public static native String runtimeVersion();
/** Returns the version of the underlying TensorFlowLite model schema. */
public static native String schemaVersion();
/**
* Initialize tensorflow's libraries. This will throw an exception if used when TensorFlow isn't

View File

@ -19,7 +19,14 @@ limitations under the License.
#include "tensorflow/lite/version.h"
JNIEXPORT jstring JNICALL
Java_org_tensorflow_lite_TensorFlowLite_version(JNIEnv* env, jclass /*clazz*/) {
Java_org_tensorflow_lite_TensorFlowLite_runtimeVersion(JNIEnv* env,
jclass /*clazz*/) {
const char* kTfLiteVersionString = TFLITE_VERSION_STRING;
return env->NewStringUTF(kTfLiteVersionString);
}
JNIEXPORT jstring JNICALL Java_org_tensorflow_lite_TensorFlowLite_schemaVersion(
JNIEnv* env, jclass /*clazz*/) {
char buf[64];
snprintf(buf, sizeof(buf), "%d", TFLITE_SCHEMA_VERSION);
return env->NewStringUTF(buf);

View File

@ -24,11 +24,19 @@ extern "C" {
/*
* Class: org_tensorflow_lite_TensorFlowLite
* Method: version
* Method: runtimeVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_org_tensorflow_lite_TensorFlowLite_version(JNIEnv*, jclass);
Java_org_tensorflow_lite_TensorFlowLite_runtimeVersion(JNIEnv*, jclass);
/*
* Class: org_tensorflow_lite_TensorFlowLite
* Method: schemaVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_org_tensorflow_lite_TensorFlowLite_schemaVersion(JNIEnv*, jclass);
#ifdef __cplusplus
} // extern "C"

View File

@ -26,7 +26,18 @@ import org.junit.runners.JUnit4;
public final class TensorFlowLiteTest {
@Test
@SuppressWarnings("deprecation")
public void testVersion() {
assertThat(TensorFlowLite.version()).isEqualTo("3");
}
@Test
public void testSchemaVersion() {
assertThat(TensorFlowLite.schemaVersion()).isEqualTo("3");
}
@Test
public void testRuntimeVersion() {
assertThat(TensorFlowLite.runtimeVersion()).startsWith("1.");
}
}

View File

@ -15,9 +15,15 @@ limitations under the License.
#ifndef TENSORFLOW_LITE_VERSION_H_
#define TENSORFLOW_LITE_VERSION_H_
#include "tensorflow/core/public/version.h"
// The version number of the Schema. Ideally all changes will be backward
// compatible. If that ever changes, we must ensure that version is the first
// entry in the new tflite root so that we can see that version is not 1.
#define TFLITE_SCHEMA_VERSION (3)
// TensorFlow Lite Runtime version.
// This value is currently shared with that of TensorFlow.
#define TFLITE_VERSION_STRING TF_VERSION_STRING
#endif // TENSORFLOW_LITE_VERSION_H_