OVIC Benchmarker App (current without the functionality to bind to a CPU).
PiperOrigin-RevId: 195503895
This commit is contained in:
parent
5fb53fe69a
commit
f21beadedc
@ -46,12 +46,27 @@ android_library(
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
android_library(
|
||||
name = "ovicbenchmarkerlib",
|
||||
srcs = [
|
||||
"ovic/src/main/java/org/tensorflow/ovic/OvicClassifier.java",
|
||||
"ovic/src/main/java/org/tensorflow/ovic/OvicSingleImageResult.java",
|
||||
],
|
||||
manifest = "AndroidManifest.xml",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":tensorflowlite",
|
||||
"//tensorflow/contrib/lite/java/src/testhelper/java/org/tensorflow/lite:testhelper",
|
||||
"@org_checkerframework_qual",
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "ovicbenchmarkerlib_java",
|
||||
srcs = [
|
||||
"ovic/src/main/java/org/tensorflow/ovic/OvicClassifier.java",
|
||||
"ovic/src/main/java/org/tensorflow/ovic/OvicSingleImageResult.java",
|
||||
],
|
||||
javacopts = JAVACOPTS,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
@ -170,18 +185,14 @@ java_test(
|
||||
size = "medium",
|
||||
srcs = ["ovic/src/test/java/org/tensorflow/ovic/OvicClassifierTest.java"],
|
||||
data = [
|
||||
"ovic/src/testdata/float_model.lite",
|
||||
"ovic/src/testdata/labels.txt",
|
||||
"ovic/src/testdata/low_res_model.lite",
|
||||
"ovic/src/testdata/quantized_model.lite",
|
||||
"ovic/src/testdata/test_image_128.jpg",
|
||||
"ovic/src/testdata/test_image_224.jpg",
|
||||
"//tensorflow/contrib/lite/java/ovic/src/testdata:labels.txt",
|
||||
"//tensorflow/contrib/lite/java/ovic/src/testdata:ovic_testdata",
|
||||
],
|
||||
javacopts = JAVACOPTS,
|
||||
test_class = "org.tensorflow.ovic.OvicClassifierTest",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":ovicbenchmarkerlib",
|
||||
":ovicbenchmarkerlib_java",
|
||||
"@com_google_truth",
|
||||
"@junit",
|
||||
],
|
||||
|
@ -37,7 +37,7 @@ unzip -j /tmp/ovic.zip -d tensorflow/contrib/lite/java/ovic/src/testdata/
|
||||
You can run test with Bazel as below. This helps to ensure that the installation is correct.
|
||||
|
||||
```sh
|
||||
bazel test --cxxopt=--std=c++11 //tensorflow/contrib/lite/java:OvicClassifierTest --test_output=all
|
||||
bazel test --cxxopt=--std=c++11 //tensorflow/contrib/lite/java:OvicClassifierTest --cxxopt=-Wno-all --test_output=all
|
||||
```
|
||||
|
||||
### Test your submissions
|
||||
@ -56,28 +56,27 @@ cp /tmp/my_model.lite tensorflow/contrib/lite/java/ovic/src/testdata/
|
||||
|
||||
The test images can be found at `tensorflow/contrib/lite/java/ovic/src/testdata/test_image_*.jpg`. You may reuse these images if your image resolutions are 128x128 or 224x224.
|
||||
|
||||
* Add your model and test image to the BUILD rule:
|
||||
* Add your model and test image to the BUILD rule at `tensorflow/contrib/lite/java/ovic/src/testdata/BUILD`:
|
||||
|
||||
```JSON
|
||||
java_test(
|
||||
name = "OvicClassifierTest",
|
||||
size = "medium",
|
||||
srcs = ["ovic/src/test/java/org/tensorflow/ovic/OvicClassifierTest.java"],
|
||||
data = [
|
||||
"ovic/src/testdata/float_model.lite",
|
||||
"ovic/src/testdata/labels.txt",
|
||||
"ovic/src/testdata/low_res_model.lite",
|
||||
"ovic/src/testdata/quantized_model.lite",
|
||||
"ovic/src/testdata/test_image_128.jpg",
|
||||
"ovic/src/testdata/test_image_224.jpg",
|
||||
"ovic/src/testdata/my_model.lite", # <--- Your submission.
|
||||
"ovic/src/testdata/my_test_image.jpg", # <--- Your test image.
|
||||
],
|
||||
...
|
||||
filegroup(
|
||||
name = "ovic_testdata",
|
||||
srcs = [
|
||||
"@tflite_ovic_testdata//:float_model.lite",
|
||||
"@tflite_ovic_testdata//:low_res_model.lite",
|
||||
"@tflite_ovic_testdata//:quantized_model.lite",
|
||||
"@tflite_ovic_testdata//:test_image_128.jpg",
|
||||
"@tflite_ovic_testdata//:test_image_224.jpg"
|
||||
"my_model.lite", # <--- Your submission.
|
||||
"my_test_image.jpg", # <--- Your test image.
|
||||
],
|
||||
...
|
||||
```
|
||||
|
||||
* Modify `OvicClassifierTest.java` to test your model.
|
||||
|
||||
Change `TEST_IMAGE_PATH` to `testdata/my_test_image.jpg`. If your model runs inference in floating point, change `FLOAT_MODEL_PATH` to `testdata/my_model.lite`. If your model runs [quantized inference](https://www.tensorflow.org/performance/quantization), change `QUANTIZED_MODEL_PATH` to `testdata/my_model.lite`.
|
||||
Change `TEST_IMAGE_PATH` to `my_test_image.jpg`. Change either `FLOAT_MODEL_PATH` or `QUANTIZED_MODEL_PATH` to `my_model.lite` depending on whether your model runs inference in float or [8-bit](https://www.tensorflow.org/performance/quantization).
|
||||
|
||||
Now you can run the bazel tests to catch any runtime issues with the submission.
|
||||
|
||||
Note: Please make sure that your submission passes the test. If a submission fails to pass the test it will not be processed by the submission server.
|
||||
|
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ovic.demo.app"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="19"
|
||||
android:targetSdkVersion="21" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:largeHeap="true"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name="ovic.demo.app.OvicBenchmarkerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
29
tensorflow/contrib/lite/java/ovic/demo/app/BUILD
Normal file
29
tensorflow/contrib/lite/java/ovic/demo/app/BUILD
Normal file
@ -0,0 +1,29 @@
|
||||
# Sample app for OVIC benchmarking.
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
android_binary(
|
||||
name = "ovic_benchmarker_binary",
|
||||
srcs = [
|
||||
"OvicBenchmarker.java",
|
||||
"OvicBenchmarkerActivity.java",
|
||||
],
|
||||
assets = [
|
||||
"//tensorflow/contrib/lite/java/ovic/src/testdata:ovic_testdata",
|
||||
"//tensorflow/contrib/lite/java/ovic/src/testdata:labels.txt",
|
||||
],
|
||||
assets_dir = "",
|
||||
custom_package = "ovic.demo.app",
|
||||
manifest = "AndroidManifest.xml",
|
||||
nocompress_extensions = [
|
||||
".lite",
|
||||
".tflite",
|
||||
],
|
||||
resource_files = glob(["res/**"]),
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//tensorflow/contrib/lite/java:ovicbenchmarkerlib",
|
||||
"//tensorflow/contrib/lite/java:tensorflowlite",
|
||||
"//third_party/java/android/android_sdk_linux/extras/android/compatibility/v13",
|
||||
"//third_party/java/android/android_sdk_linux/extras/android/compatibility/v4",
|
||||
],
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
/*Copyright 2018 Google LLC
|
||||
/* Copyright 2018 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.
|
||||
@ -12,7 +12,7 @@ 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 org.tensorflow.ovic;
|
||||
package ovic.demo.app;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.SystemClock;
|
||||
@ -22,6 +22,8 @@ import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import org.tensorflow.ovic.OvicClassifier;
|
||||
import org.tensorflow.ovic.OvicSingleImageResult;
|
||||
|
||||
/**
|
||||
* Class that benchmarks image classifier models.
|
@ -0,0 +1,163 @@
|
||||
/* Copyright 2018 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 ovic.demo.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.DecimalFormat;
|
||||
import org.tensorflow.ovic.OvicSingleImageResult;
|
||||
|
||||
/** Class that benchmark image classifier models. */
|
||||
public class OvicBenchmarkerActivity extends Activity {
|
||||
/** Tag for the {@link Log}. */
|
||||
private static final String TAG = "OvicBenchmarkerActivity";
|
||||
|
||||
/** Name of the label file stored in Assets. */
|
||||
private static final String LABEL_PATH = "labels.txt";
|
||||
|
||||
private static final String TEST_IMAGE_PATH = "test_image_224.jpg";
|
||||
private static final String MODEL_PATH = "float_model.lite";
|
||||
/**
|
||||
* Each bottom press will launch a benchmarking experiment. The experiment stops when either the
|
||||
* total native latency reaches WALL_TIME or the number of iterations reaches MAX_ITERATIONS,
|
||||
* whichever comes first.
|
||||
*/
|
||||
/** Wall time for each benchmarking experiment. */
|
||||
private static final double WALL_TIME = 3000;
|
||||
/** Maximum number of iterations in each benchmarking experiment. */
|
||||
private static final int MAX_ITERATIONS = 100;
|
||||
|
||||
/* The model to be benchmarked. */
|
||||
private MappedByteBuffer model = null;
|
||||
private InputStream labelInputStream = null;
|
||||
private OvicBenchmarker benchmarker;
|
||||
/** Inference result of each iteration. */
|
||||
OvicSingleImageResult iterResult = null;
|
||||
|
||||
private TextView textView = null;
|
||||
// private Button startButton = null;
|
||||
private static final DecimalFormat df2 = new DecimalFormat(".##");
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// TextView used to display the progress, for information purposes only.
|
||||
textView = (TextView) findViewById(R.id.textView);
|
||||
}
|
||||
|
||||
private Bitmap loadTestBitmap() throws IOException {
|
||||
InputStream imageStream = getAssets().open(TEST_IMAGE_PATH);
|
||||
return BitmapFactory.decodeStream(imageStream);
|
||||
}
|
||||
|
||||
public void initializeTest() throws IOException {
|
||||
Log.i(TAG, "Initializing benchmarker.");
|
||||
benchmarker = new OvicBenchmarker(WALL_TIME);
|
||||
AssetManager am = getAssets();
|
||||
AssetFileDescriptor fileDescriptor = am.openFd(MODEL_PATH);
|
||||
FileInputStream modelInputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
|
||||
FileChannel fileChannel = modelInputStream.getChannel();
|
||||
long startOffset = fileDescriptor.getStartOffset();
|
||||
long declaredLength = fileDescriptor.getDeclaredLength();
|
||||
model = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
|
||||
labelInputStream = am.open(LABEL_PATH);
|
||||
}
|
||||
|
||||
public Boolean doTestIteration() throws IOException, InterruptedException {
|
||||
if (benchmarker == null) {
|
||||
throw new RuntimeException("Benchmarker has not been initialized.");
|
||||
}
|
||||
if (benchmarker.shouldStop()) {
|
||||
return false;
|
||||
}
|
||||
if (!benchmarker.readyToTest()) {
|
||||
Log.i(TAG, "getting ready to test.");
|
||||
benchmarker.getReadyToTest(labelInputStream, model);
|
||||
if (!benchmarker.readyToTest()) {
|
||||
throw new RuntimeException("Failed to get the benchmarker ready.");
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "Going to do test iter.");
|
||||
// Start testing.
|
||||
Bitmap testImageBitmap = loadTestBitmap();
|
||||
iterResult = benchmarker.doTestIteration(testImageBitmap);
|
||||
testImageBitmap.recycle();
|
||||
if (iterResult == null) {
|
||||
throw new RuntimeException("Inference failed to produce a result.");
|
||||
}
|
||||
Log.i(TAG, iterResult.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
public void startPressed(View view) throws IOException {
|
||||
Log.i(TAG, "Start pressed");
|
||||
try {
|
||||
initializeTest();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Can't initialize benchmarker.", e);
|
||||
throw e;
|
||||
}
|
||||
Log.i(TAG, "Successfully initialized benchmarker.");
|
||||
int testIter = 0;
|
||||
Boolean iterSuccess = false;
|
||||
double totalLatency = 0.0f;
|
||||
while (testIter < MAX_ITERATIONS) {
|
||||
try {
|
||||
iterSuccess = doTestIteration();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error during iteration " + testIter);
|
||||
throw e;
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "Interrupted at iteration " + testIter);
|
||||
}
|
||||
if (!iterSuccess) {
|
||||
break;
|
||||
}
|
||||
testIter++;
|
||||
totalLatency += (double) iterResult.latency;
|
||||
}
|
||||
;
|
||||
Log.i(TAG, "Benchmarking finished");
|
||||
|
||||
if (textView != null) {
|
||||
if (testIter > 0) {
|
||||
textView
|
||||
.setText(
|
||||
MODEL_PATH
|
||||
+ ": Average latency="
|
||||
+ df2.format(totalLatency / testIter)
|
||||
+ "ms after "
|
||||
+ testIter
|
||||
+ " runs.");
|
||||
} else {
|
||||
textView.setText("Benchmarker failed to run on more than one images.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
tensorflow/contrib/lite/java/ovic/demo/app/build.gradle
Normal file
58
tensorflow/contrib/lite/java/ovic/demo/app/build.gradle
Normal file
@ -0,0 +1,58 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "26.0.1"
|
||||
defaultConfig {
|
||||
applicationId "android.example.com.ovicbenchmarker"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
// Remove this block.
|
||||
jackOptions {
|
||||
enabled true
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
aaptOptions {
|
||||
noCompress "lite", "tflite"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://google.bintray.com/tensorflow'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:25.2.0'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
compile 'com.android.support:design:25.2.0'
|
||||
compile 'com.android.support:support-annotations:25.3.1'
|
||||
compile 'com.android.support:support-v13:25.2.0'
|
||||
|
||||
compile 'org.tensorflow:tensorflow-lite:+'
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<selector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_enabled="false">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#808080"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:state_enabled="true"
|
||||
android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#44ff44"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:state_enabled="true"
|
||||
android:state_pressed="false">
|
||||
<shape android:shape="rectangle" >
|
||||
<solid android:color="#227f22"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="ovic.demo.app.OvicBenchmarkerActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/initial_status_msg"
|
||||
android:id="@+id/textView"
|
||||
android:layout_above="@+id/button_start"
|
||||
android:layout_alignParentTop="true"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/start_label"
|
||||
android:id="@id/button_start"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="@drawable/start_button_color"
|
||||
android:padding="10dp"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginLeft="100dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:foreground="#000000"
|
||||
android:textColor="#ffffff"
|
||||
android:enabled="true"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:onClick="startPressed"/>
|
||||
|
||||
</RelativeLayout>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
<dimen name="activity_vertical_margin">20dp</dimen>
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
</resources>
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">Benchmarker</string>
|
||||
|
||||
<string name="start_label" translatable="false">Start</string>
|
||||
<string name="initial_status_msg" translatable="false"> Press start to run the benchmarks.</string>
|
||||
</resources>
|
23
tensorflow/contrib/lite/java/ovic/demo/build.gradle
Normal file
23
tensorflow/contrib/lite/java/ovic/demo/build.gradle
Normal file
@ -0,0 +1,23 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
17
tensorflow/contrib/lite/java/ovic/demo/gradle.properties
Normal file
17
tensorflow/contrib/lite/java/ovic/demo/gradle.properties
Normal file
@ -0,0 +1,17 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
BIN
tensorflow/contrib/lite/java/ovic/demo/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
tensorflow/contrib/lite/java/ovic/demo/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
tensorflow/contrib/lite/java/ovic/demo/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
tensorflow/contrib/lite/java/ovic/demo/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Thu Sep 28 09:01:41 PDT 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
160
tensorflow/contrib/lite/java/ovic/demo/gradlew
vendored
Executable file
160
tensorflow/contrib/lite/java/ovic/demo/gradlew
vendored
Executable file
@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
90
tensorflow/contrib/lite/java/ovic/demo/gradlew.bat
vendored
Normal file
90
tensorflow/contrib/lite/java/ovic/demo/gradlew.bat
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
1
tensorflow/contrib/lite/java/ovic/demo/settings.gradle
Normal file
1
tensorflow/contrib/lite/java/ovic/demo/settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
include ':app'
|
@ -67,7 +67,7 @@ public class OvicClassifier {
|
||||
});
|
||||
|
||||
/** Initializes an {@code OvicClassifier}. */
|
||||
OvicClassifier(InputStream labelInputStream, MappedByteBuffer model)
|
||||
public OvicClassifier(InputStream labelInputStream, MappedByteBuffer model)
|
||||
throws IOException, RuntimeException {
|
||||
if (model == null) {
|
||||
throw new RuntimeException("Input model is empty.");
|
||||
@ -106,7 +106,7 @@ public class OvicClassifier {
|
||||
|
||||
/** Classifies a {@link ByteBuffer} image. */
|
||||
// @throws RuntimeException if model is uninitialized.
|
||||
OvicSingleImageResult classifyByteBuffer(ByteBuffer imgData) throws RuntimeException {
|
||||
public OvicSingleImageResult classifyByteBuffer(ByteBuffer imgData) {
|
||||
if (tflite == null) {
|
||||
throw new RuntimeException(TAG + ": ImageNet classifier has not been initialized; Failed.");
|
||||
}
|
||||
|
19
tensorflow/contrib/lite/java/ovic/src/testdata/BUILD
vendored
Normal file
19
tensorflow/contrib/lite/java/ovic/src/testdata/BUILD
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Testdata for OVIC benchmarker demo App and tests.
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
filegroup(
|
||||
name = "ovic_testdata",
|
||||
srcs = [
|
||||
"float_model.lite",
|
||||
"low_res_model.lite",
|
||||
"quantized_model.lite",
|
||||
"test_image_128.jpg",
|
||||
"test_image_224.jpg",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
exports_files(
|
||||
["labels.txt"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
12
tensorflow/opensource_only/tflite_ovic_testdata.BUILD
Normal file
12
tensorflow/opensource_only/tflite_ovic_testdata.BUILD
Normal file
@ -0,0 +1,12 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
exports_files(
|
||||
glob(
|
||||
["**/*"],
|
||||
exclude = [
|
||||
"BUILD",
|
||||
],
|
||||
),
|
||||
)
|
@ -744,6 +744,17 @@ def tf_workspace(path_prefix="", tf_repo_name=""):
|
||||
build_file = clean_dep("//third_party:tflite_smartreply.BUILD"),
|
||||
)
|
||||
|
||||
tf_http_archive(
|
||||
name = "tflite_ovic_testdata",
|
||||
sha256 = "a9a705d8d519220178e2e65d383fdb21da37fdb31d1e909b0a1acdac46479e9c",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/storage.googleapis.com/download.tensorflow.org/data/ovic.zip",
|
||||
"https://storage.googleapis.com/download.tensorflow.org/data/ovic.zip",
|
||||
],
|
||||
build_file = clean_dep("//third_party:tflite_ovic_testdata.BUILD"),
|
||||
strip_prefix = "ovic",
|
||||
)
|
||||
|
||||
##############################################################################
|
||||
# BIND DEFINITIONS
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user