4

When I opened up Android Studio this morning, I got this error when Gradle tried to sync:

Error:(103, 13) Failed to resolve: org.tensorflow:tensorflow-android:+

As per the instructions in their Github readme, they use a dynamic version (which Android Studio warns me about). It had been working just the day before.

I did try using the only explicit version they have: 1.3.0, but this leads to another problem when trying to load their speech recognition model with their sample code:

java.lang.RuntimeException: Failed to load model from 'file:///android_asset/conv_actions_frozen.pb'
    [...]
Caused by: java.io.IOException: Not a valid TensorFlow Graph serialization: Shape must be rank 1 but is rank 0 for 'Mfcc' (op: 'Mfcc') with input shapes: [16000,0,257], [].
    at org.tensorflow.contrib.android.TensorFlowInferenceInterface.loadGraph(TensorFlowInferenceInterface.java:398)
    at org.tensorflow.contrib.android.TensorFlowInferenceInterface.<init>(TensorFlowInferenceInterface.java:97)

I've tried searching for a solution to that separately, but importing the dynamic version fixes it. If there was another workaround, that would also solve my problem.

I'm also getting a 404 when I try to go to their package repository page linked to in the readme: https://bintray.com/google/tensorflow/tensorflow-android

My build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
apply plugin: 'com.google.firebase.firebase-perf'

ext {
    grpcVersion = '1.6.1'
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId [HIDDEN]
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "a10_10"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            multiDexEnabled true
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/io.netty.versions.properties'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/project.properties'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.1.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.1'
    }
}

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.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.google.code.findbugs:jsr305:2.0.1'

    compile("io.grpc:grpc-okhttp:$grpcVersion") {
        exclude group: 'com.google.code.findbugs'
    }
    compile("io.grpc:grpc-stub:$grpcVersion") {
        exclude group: 'com.google.code.findbugs'
    }

    compile('com.google.cloud:google-cloud-speech:0.25.0-alpha') {
        exclude group: 'com.google.cloud', module: 'google-cloud-core-grpc'
        exclude group: 'com.google.code.findbugs'
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.cloud', module: 'google-cloud-core'
    }

    compile('com.google.cloud:google-cloud-core-grpc:1.7.0') {
        exclude group: 'com.google.cloud', module: 'google-cloud-core'
        exclude group: 'com.google.code.findbugs'
        exclude group: 'org.apache.httpcomponents'
    }

    // OAuth2 for Google API
    compile('com.google.auth:google-auth-library-oauth2-http:0.8.0') {
        exclude module: 'httpclient'
    }

    //noinspection GradleDynamicVersion
    compile 'org.tensorflow:tensorflow-android:+'

    compile 'commons-io:commons-io:2.5'
    compile 'org.apache.commons:commons-lang3:3.6'

    compile 'com.google.firebase:firebase-crash:11.4.2'
    compile 'com.google.firebase:firebase-perf:11.4.2'
    compile 'com.google.firebase:firebase-auth:11.4.2'
    compile 'com.google.firebase:firebase-storage:11.4.2'
    compile 'com.google.firebase:firebase-database:11.4.2'
    compile 'com.google.android.gms:play-services-auth:11.4.2'

    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
J Brewer
  • 195
  • 2
  • 10
  • did u solved the problem? – Nati Krisi Oct 12 '17 at 03:46
  • It looks like they moved their library to maven (https://mvnrepository.com/artifact/org.tensorflow/tensorflow-android). You can add mavenCentral() to repositories in build.gradle to fix that one. – Cameron Oct 12 '17 at 07:34
  • Very interesting, adding mavenCentral() and leaving in the dynamic version actually downloads 1.4.0-rc0, but it still throws an exception when loading the model file – J Brewer Oct 12 '17 at 17:05
  • Which version of tensorflow are you using to train the model? I think this exception was getting caused because the version used to train the model is higher than the android version. In my case when I got the exception, I used a recent nightly build to train the model. – Cameron Oct 12 '17 at 17:55
  • I'm actually using their sample/tutorial model for the time being. That's a good question though, depending on what version they used to train their sample. It was from around Aug. 16th, which was about the same time they released 1.3 from what I can tell – J Brewer Oct 12 '17 at 18:20

2 Answers2

1

I got the same error

java.lang.RuntimeException: Failed to load model from 'file:///android_asset/conv_actions_frozen.pb'

using tensorflow-android 1.3.0 (found here https://mvnrepository.com/artifact/org.tensorflow/tensorflow-android/1.3.0).

However, I was able to get the sample speech recognition app to run using a nightly build (http://ci.tensorflow.org/view/Nightly/job/nightly-android/286/artifact/out/tensorflow.aar).

You'll have to download the .aar, add it to your project and replace

compile 'org.tensorflow:tensorflow-android:+'

with the .aar.

Cameron
  • 756
  • 6
  • 16
  • This worked for me too, no exceptions thrown. It's manual but at least it isn't dependent on a repository if they change something – J Brewer Oct 12 '17 at 17:15
  • what do u mean by replace with aar? do i need to add something to the gradle.build? – Nati Krisi Oct 13 '17 at 03:30
  • Here's a post explaining how to add an aar library to a project https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst After you have added the aar, you will need to replace compile 'org.tensorflow:tensorflow-android:+' with compile(name:'tensorflow', ext:'aar') in the build.gradle. – Cameron Oct 13 '17 at 05:20
1

There's a temporary problem where the artifacts were incorrectly removed from jcenter.

Please see https://github.com/tensorflow/tensorflow/issues/13653#issuecomment-336145329

kbs
  • 226
  • 2
  • 1