Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate download and unzip of the model file #14853

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions tensorflow/contrib/lite/java/demo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,39 @@ dependencies {

testCompile 'junit:junit:4.12'
}

def modelDownloadUrl = "https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip"
def localCache = "build/intermediates/mobilenet_v1_224_android_quant_2017_11_08.zip"
def targetFolder = "src/main/assets"

task downloadModel(type: DownloadUrlTask) {
doFirst {
println "Downloading ${modelDownloadUrl}"
}
sourceUrl = "${modelDownloadUrl}"
target = file("${localCache}")
}

task unzipModel(type: Copy, dependsOn: 'downloadModel') {
doFirst {
println "Unzipping ${localCache}"
}
from zipTree("${localCache}")
into "${targetFolder}"
}

// Ensure the model file is downloaded and extracted before every build
preBuild.dependsOn unzipModel

class DownloadUrlTask extends DefaultTask {
@Input
String sourceUrl

@OutputFile
File target

@TaskAction
void download() {
ant.get(src: sourceUrl, dest: target)
}
}
23 changes: 11 additions & 12 deletions tensorflow/docs_src/mobile/tflite/demo_android.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ app:
Android Studio project.
* Install all the Gradle extensions it requests.

To get a model, either:

* Download the quantized [Mobilenet TensorFlow Lite model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip)
and unzip and copy `mobilenet_quant_v1_224.tflite` to the assets directory:
`tensorflow/contrib/lite/java/demo/app/src/main/assets/`.
* Or, download the floating point [Inception-v3 model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/inception_v3_slim_2016_android_2017_11_10.zip)
and unzip and copy `inceptionv3_non_slim_2015.tflite` to the assets
directory. Change the chosen classifier in
[Camera2BasicFragment.java](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/java/demo/app/src/main/java/com/example/android/tflitecamerademo/Camera2BasicFragment.java)<br>
from: `classifier = new ImageClassifierQuantizedMobileNet(getActivity());`<br>
to: `classifier = new ImageClassifierFloatInception(getActivity());`.
Now you can build and run the demo app.

Now you can build and run the demo app.
The build process downloads the quantized [Mobilenet TensorFlow Lite model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip), and unzips it into the assets directory: `tensorflow/contrib/lite/java/demo/app/src/main/assets/`.

Some additional details are available on the
[TF Lite Android App page](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo/README.md).

### Using other models

To use a different model:
* Download the floating point [Inception-v3 model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/inception_v3_slim_2016_android_2017_11_10.zip).
* Unzip and copy `inceptionv3_non_slim_2015.tflite` to the assets directory.
* Change the chosen classifier in [Camera2BasicFragment.java](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/java/demo/app/src/main/java/com/example/android/tflitecamerademo/Camera2BasicFragment.java)<br>
from: `classifier = new ImageClassifierQuantizedMobileNet(getActivity());`<br>
to: `classifier = new ImageClassifierFloatInception(getActivity());`.


## Build TensorFlow Lite and the demo app from source

Expand Down