forked from tensorflow/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
59 changed files
with
2,164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# TensorFlow Lite PoseNet Android Demo | ||
### Overview | ||
This is an app that continuously detects the body parts in the frames seen by | ||
your device's camera. These instructions walk you through building and running | ||
the demo on an Android device. | ||
|
||
![Demo Image](posenetimage.png) | ||
|
||
## Build the demo using Android Studio | ||
|
||
### Prerequisites | ||
|
||
* If you don't have it already, install **[Android Studio]( | ||
https://developer.android.com/studio/index.html)** 3.2 or | ||
later, following the instructions on the website. | ||
|
||
* Android device and Android development environment with minimum API 21. | ||
|
||
### Building | ||
* Open Android Studio, and from the `Welcome` screen, select | ||
`Open an existing Android Studio project`. | ||
|
||
* From the `Open File or Project` window that appears, navigate to and select | ||
the `tensorflow-lite/examples/posenet/android` directory from wherever you | ||
cloned the TensorFlow Lite sample GitHub repo. Click `OK`. | ||
|
||
* If it asks you to do a `Gradle Sync`, click `OK`. | ||
|
||
* You may also need to install various platforms and tools, if you get errors | ||
like `Failed to find target with hash string 'android-21'` and similar. Click | ||
the `Run` button (the green arrow) or select `Run` > `Run 'android'` from the | ||
top menu. You may need to rebuild the project using `Build` > `Rebuild Project`. | ||
|
||
* If it asks you to use `Instant Run`, click `Proceed Without Instant Run`. | ||
|
||
* Also, you need to have an Android device plugged in with developer options | ||
enabled at this point. See **[here]( | ||
https://developer.android.com/studio/run/device)** for more details | ||
on setting up developer devices. | ||
|
||
|
||
### Model used | ||
Downloading, extraction and placement in assets folder has been managed | ||
automatically by `download.gradle`. | ||
|
||
If you explicitly want to download the model, you can download it from | ||
**[here]( | ||
https://storage.googleapis.com/download.tensorflow.org/models/tflite/posenet_mobilenet_v1_100_513x513_multi_kpt_stripped.tflite)**. | ||
|
||
### Additional Note | ||
_Please do not delete the assets folder content_. If you explicitly deleted the | ||
files, then please choose `Build` > `Rebuild` from menu to re-download the | ||
deleted model files into assets folder. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.0" | ||
defaultConfig { | ||
applicationId "org.tensorflow.lite.examples.posenet" | ||
minSdkVersion 21 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
aaptOptions { | ||
noCompress "tflite" | ||
} | ||
lintOptions { | ||
checkReleaseBuilds false | ||
// Or, if you prefer, you can continue to check for errors in release builds, | ||
// but continue the build even when errors are found: | ||
abortOnError false | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation project(":posenet") | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support:design:28.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
implementation 'org.tensorflow:tensorflow-lite:1.14.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
38 changes: 38 additions & 0 deletions
38
.../app/src/androidTest/java/org/tensorflow/lite/examples/posenet/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2019 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 org.tensorflow.lite.examples.posenet | ||
|
||
import androidx.test.InstrumentationRegistry | ||
import androidx.test.runner.AndroidJUnit4 | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getTargetContext() | ||
assertEquals("org.tensorflow.lite.examples.posenet", appContext.packageName) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
lite/examples/posenet/android/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.tensorflow.lite.examples.posenet"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
|
||
<uses-feature android:name="android.hardware.camera" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<uses-sdk | ||
android:minSdkVersion="21" | ||
android:targetSdkVersion="23" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/tf_ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/tf_ic_launcher" | ||
android:supportsRtl="true" | ||
android:theme="@style/MaterialTheme"> | ||
|
||
<activity | ||
android:name=".TestActivity" | ||
android:label="@string/app_name" | ||
android:exported="true"> | ||
</activity> | ||
|
||
<activity android:name=".CameraActivity" android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
31 changes: 31 additions & 0 deletions
31
.../posenet/android/app/src/main/java/org/tensorflow/lite/examples/posenet/CameraActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2019 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 org.tensorflow.lite.examples.posenet | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
|
||
class CameraActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_camera) | ||
savedInstanceState ?: supportFragmentManager.beginTransaction() | ||
.replace(R.id.container, PosenetActivity()) | ||
.commit() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...enet/android/app/src/main/java/org/tensorflow/lite/examples/posenet/ConfirmationDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2019 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 org.tensorflow.lite.examples.posenet | ||
|
||
import android.Manifest | ||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.os.Bundle | ||
import android.support.v4.app.DialogFragment | ||
|
||
/** | ||
* Shows OK/Cancel confirmation dialog about camera permission. | ||
*/ | ||
class ConfirmationDialog : DialogFragment() { | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = | ||
AlertDialog.Builder(activity) | ||
.setMessage(R.string.request_permission) | ||
.setPositiveButton(android.R.string.ok) { _, _ -> | ||
parentFragment!!.requestPermissions( | ||
arrayOf(Manifest.permission.CAMERA), | ||
REQUEST_CAMERA_PERMISSION | ||
) | ||
} | ||
.setNegativeButton(android.R.string.cancel) { _, _ -> | ||
parentFragment!!.activity?.finish() | ||
} | ||
.create() | ||
} |
27 changes: 27 additions & 0 deletions
27
...mples/posenet/android/app/src/main/java/org/tensorflow/lite/examples/posenet/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
@file:JvmName("Constants") | ||
|
||
package org.tensorflow.lite.examples.posenet | ||
|
||
/** Request camera and external storage permission. */ | ||
const val REQUEST_CAMERA_PERMISSION = 1 | ||
const val REQUEST_CODE_WRITE_EXTERNAL_STORAGE_PERMISSION = 1 | ||
|
||
/** Model input shape for images. */ | ||
const val MODEL_WIDTH = 513 | ||
const val MODEL_HEIGHT = 513 |
Oops, something went wrong.