diff --git a/tensorflow/lite/models/BUILD b/tensorflow/lite/models/BUILD deleted file mode 100644 index 6332636a0db..00000000000 --- a/tensorflow/lite/models/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -# Model tests -package( - default_visibility = ["//visibility:public"], -) - -licenses(["notice"]) # Apache 2.0 - -exports_files(["LICENSE"]) - -exports_files(glob([ - "testdata/*", -])) diff --git a/tensorflow/lite/models/smartreply/BUILD b/tensorflow/lite/models/smartreply/BUILD deleted file mode 100644 index 9819c804cc2..00000000000 --- a/tensorflow/lite/models/smartreply/BUILD +++ /dev/null @@ -1,117 +0,0 @@ -load("//tensorflow:tensorflow.bzl", "tf_cc_test") -load("//tensorflow/lite:build_def.bzl", "gen_selected_ops", "tflite_copts") - -package( - default_visibility = [ - "//visibility:public", - ], - licenses = ["notice"], # Apache 2.0 -) - -exports_files(["LICENSE"]) - -gen_selected_ops( - name = "smartreply_ops", - model = ["@tflite_smartreply//:smartreply.tflite"], -) - -cc_library( - name = "custom_ops", - srcs = [ - "ops/extract_feature.cc", - "ops/normalize.cc", - "ops/predict.cc", - ":smartreply_ops", - ], - copts = tflite_copts(), - deps = [ - "//tensorflow/lite:framework", - "//tensorflow/lite:string_util", - "//tensorflow/lite/kernels:builtin_ops", - "//tensorflow/lite/kernels:kernel_util", - "//tensorflow/lite/kernels/internal:tensor", - "@com_google_absl//absl/strings", - "@com_googlesource_code_re2//:re2", - "@farmhash_archive//:farmhash", - ], - alwayslink = 1, -) - -cc_library( - name = "predictor_lib", - srcs = ["predictor.cc"], - hdrs = ["predictor.h"], - copts = tflite_copts(), - deps = [ - ":custom_ops", - "//tensorflow/lite:framework", - "//tensorflow/lite:string_util", - "//tensorflow/lite/kernels:builtin_ops", - "@com_google_absl//absl/strings", - "@com_googlesource_code_re2//:re2", - ], -) - -# TODO(b/118895218): Make this test compatible with oss. -tf_cc_test( - name = "predictor_test", - srcs = ["predictor_test.cc"], - data = [ - "//tensorflow/lite/models:testdata/smartreply_samples.tsv", - "@tflite_smartreply//:smartreply.tflite", - ], - tags = ["no_oss"], - deps = [ - ":predictor_lib", - "//tensorflow/core:test", - "//tensorflow/lite:string_util", - "//tensorflow/lite/testing:util", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - ], -) - -cc_test( - name = "extract_feature_op_test", - size = "small", - srcs = ["ops/extract_feature_test.cc"], - tags = ["no_oss"], - deps = [ - ":custom_ops", - "//tensorflow/lite:framework", - "//tensorflow/lite/kernels:builtin_ops", - "//tensorflow/lite/kernels:test_util", - "@com_google_googletest//:gtest", - "@farmhash_archive//:farmhash", - ], -) - -cc_test( - name = "normalize_op_test", - size = "small", - srcs = ["ops/normalize_test.cc"], - tags = ["no_oss"], - deps = [ - ":custom_ops", - "//tensorflow/lite:framework", - "//tensorflow/lite:string_util", - "//tensorflow/lite/kernels:builtin_ops", - "//tensorflow/lite/kernels:test_util", - "@com_google_googletest//:gtest", - ], -) - -cc_test( - name = "predict_op_test", - size = "small", - srcs = ["ops/predict_test.cc"], - tags = ["no_oss"], - deps = [ - ":custom_ops", - "//tensorflow/lite:framework", - "//tensorflow/lite:string_util", - "//tensorflow/lite/kernels:builtin_ops", - "//tensorflow/lite/kernels:test_util", - "@com_google_googletest//:gtest", - ], -) diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/AndroidManifest.xml b/tensorflow/lite/models/smartreply/demo/app/src/main/AndroidManifest.xml deleted file mode 100644 index 75ed9432c8f..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/BUILD b/tensorflow/lite/models/smartreply/demo/app/src/main/BUILD deleted file mode 100644 index 8c489cf729f..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/BUILD +++ /dev/null @@ -1,68 +0,0 @@ -load("@build_bazel_rules_android//android:rules.bzl", "android_binary") -load( - "//tensorflow/lite:build_def.bzl", - "tflite_copts", - "tflite_jni_binary", -) - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], # Apache 2.0 -) - -filegroup( - name = "assets", - srcs = [ - "@tflite_smartreply//:model_files", - ], -) - -android_binary( - name = "SmartReplyDemo", - srcs = glob(["java/**/*.java"]), - assets = [":assets"], - assets_dir = "", - custom_package = "com.example.android.smartreply", - manifest = "AndroidManifest.xml", - nocompress_extensions = [ - ".tflite", - ], - resource_files = glob(["res/**"]), - tags = ["manual"], - deps = [ - ":smartreply_runtime", - "@androidsdk//com.android.support:support-v13-25.2.0", - "@androidsdk//com.android.support:support-v4-25.2.0", - ], -) - -cc_library( - name = "smartreply_runtime", - srcs = ["libsmartreply_jni.so"], - visibility = ["//visibility:public"], -) - -tflite_jni_binary( - name = "libsmartreply_jni.so", - deps = [ - ":smartreply_jni_lib", - ], -) - -cc_library( - name = "smartreply_jni_lib", - srcs = [ - "smartreply_jni.cc", - ], - copts = tflite_copts(), - linkopts = [ - "-lm", - "-ldl", - ], - deps = [ - "//tensorflow/lite:framework", - "//tensorflow/lite/java/jni", - "//tensorflow/lite/models/smartreply:predictor_lib", - ], - alwayslink = 1, -) diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/assets/BUILD b/tensorflow/lite/models/smartreply/demo/app/src/main/assets/BUILD deleted file mode 100644 index 86023676484..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/assets/BUILD +++ /dev/null @@ -1,16 +0,0 @@ -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], # Apache 2.0 -) - -exports_files(glob(["*"])) - -filegroup( - name = "assets_files", - srcs = glob( - ["**/*"], - exclude = [ - "BUILD", - ], - ), -) diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/assets/backoff_response.txt b/tensorflow/lite/models/smartreply/demo/app/src/main/assets/backoff_response.txt deleted file mode 100644 index a0a5b46b5f8..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/assets/backoff_response.txt +++ /dev/null @@ -1,16 +0,0 @@ -Ok -Yes -No -👍 -☺ -😟 -❤️ -Lol -Thanks -Got it -Done -Nice -I don't know -What? -Why? -What's up? diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/MainActivity.java b/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/MainActivity.java deleted file mode 100644 index 02fec9ae5e9..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/MainActivity.java +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -package com.example.android.smartreply; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Handler; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -/** - * The main (and only) activity of this demo app. Displays a text box which updates as messages are - * received. - */ -public class MainActivity extends Activity { - private static final String TAG = "SmartReplyDemo"; - private SmartReplyClient client; - - private Button sendButton; - private TextView messageTextView; - private EditText messageInput; - - private Handler handler; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Log.v(TAG, "onCreate"); - setContentView(R.layout.main_activity); - - client = new SmartReplyClient(getApplicationContext()); - handler = new Handler(); - - sendButton = (Button) findViewById(R.id.send_button); - sendButton.setOnClickListener( - (View v) -> { - send(messageInput.getText().toString()); - }); - - messageTextView = (TextView) findViewById(R.id.message_text); - messageInput = (EditText) findViewById(R.id.message_input); - } - - @Override - protected void onStart() { - super.onStart(); - Log.v(TAG, "onStart"); - handler.post( - () -> { - client.loadModel(); - }); - } - - @Override - protected void onStop() { - super.onStop(); - Log.v(TAG, "onStop"); - handler.post( - () -> { - client.unloadModel(); - }); - } - - private void send(final String message) { - handler.post( - () -> { - messageTextView.append("Input: " + message + "\n"); - - SmartReply[] ans = client.predict(new String[] {message}); - for (SmartReply reply : ans) { - appendMessage("Reply: " + reply.getText()); - } - appendMessage("------"); - }); - } - - private void appendMessage(final String message) { - handler.post( - () -> { - messageTextView.append(message + "\n"); - }); - } -} diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReply.java b/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReply.java deleted file mode 100644 index 3357fd17c11..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReply.java +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -package com.example.android.smartreply; - -import android.support.annotation.Keep; - -/** - * SmartReply contains predicted message, and confidence. - * - *

NOTE: this class used by JNI, class name and constructor should not be obfuscated. - */ -@Keep -public class SmartReply { - - private final String text; - private final float score; - - @Keep - public SmartReply(String text, float score) { - this.text = text; - this.score = score; - } - - public String getText() { - return text; - } - - public float getScore() { - return score; - } -} diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReplyClient.java b/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReplyClient.java deleted file mode 100644 index cbd155bb0cd..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/java/com/example/android/smartreply/SmartReplyClient.java +++ /dev/null @@ -1,131 +0,0 @@ -/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -package com.example.android.smartreply; - -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.support.annotation.Keep; -import android.support.annotation.WorkerThread; -import android.util.Log; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.util.ArrayList; -import java.util.List; - -/** Interface to load TfLite model and provide predictions. */ -public class SmartReplyClient implements AutoCloseable { - private static final String TAG = "SmartReplyDemo"; - private static final String MODEL_PATH = "smartreply.tflite"; - private static final String BACKOFF_PATH = "backoff_response.txt"; - private static final String JNI_LIB = "smartreply_jni"; - - private final Context context; - private long storage; - private MappedByteBuffer model; - - private volatile boolean isLibraryLoaded; - - public SmartReplyClient(Context context) { - this.context = context; - } - - public boolean isLoaded() { - return storage != 0; - } - - @WorkerThread - public synchronized void loadModel() { - if (!isLibraryLoaded) { - try { - System.loadLibrary(JNI_LIB); - isLibraryLoaded = true; - } catch (Exception e) { - Log.e(TAG, "Failed to load prebuilt smartreply_jni lib", e); - return; - } - } - - try { - model = loadModelFile(); - String[] backoff = loadBackoffList(); - storage = loadJNI(model, backoff); - } catch (IOException e) { - Log.e(TAG, "Fail to load model", e); - return; - } - } - - @WorkerThread - public synchronized SmartReply[] predict(String[] input) { - if (storage != 0) { - return predictJNI(storage, input); - } else { - return new SmartReply[] {}; - } - } - - @WorkerThread - public synchronized void unloadModel() { - close(); - } - - @Override - public synchronized void close() { - if (storage != 0) { - unloadJNI(storage); - storage = 0; - } - } - - private MappedByteBuffer loadModelFile() throws IOException { - try (AssetFileDescriptor fileDescriptor = context.getAssets().openFd(MODEL_PATH); - FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor())) { - FileChannel fileChannel = inputStream.getChannel(); - long startOffset = fileDescriptor.getStartOffset(); - long declaredLength = fileDescriptor.getDeclaredLength(); - return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); - } - } - - private String[] loadBackoffList() throws IOException { - List labelList = new ArrayList(); - try (BufferedReader reader = - new BufferedReader(new InputStreamReader(context.getAssets().open(BACKOFF_PATH)))) { - String line; - while ((line = reader.readLine()) != null) { - if (!line.isEmpty()) { - labelList.add(line); - } - } - } - String[] ans = new String[labelList.size()]; - labelList.toArray(ans); - return ans; - } - - @Keep - private native long loadJNI(MappedByteBuffer buffer, String[] backoff); - - @Keep - private native SmartReply[] predictJNI(long storage, String[] text); - - @Keep - private native void unloadJNI(long storage); -} diff --git a/tensorflow/lite/models/smartreply/demo/app/src/main/res/layout/main_activity.xml b/tensorflow/lite/models/smartreply/demo/app/src/main/res/layout/main_activity.xml deleted file mode 100644 index 23b4cadc007..00000000000 --- a/tensorflow/lite/models/smartreply/demo/app/src/main/res/layout/main_activity.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - -