Tensorflow:无法在 gradle 中解析

2024-05-29

今天早上我打开 Android Studio 时,Gradle 尝试同步时出现以下错误:

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

按照他们的说明Github 自述文件 https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android,他们使用动态版本(Android Studio 警告我这一点)。前一天它还在工作。

我确实尝试使用他们拥有的唯一显式版本:1.3.0,但这在尝试使用示例代码加载语音识别模型时会导致另一个问题:

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)

我尝试单独寻找解决方案,但导入动态版本可以修复它。如果有另一种解决方法,那也能解决我的问题。

当我尝试访问自述文件中链接的包存储库页面时,我也收到了 404 错误:https://bintray.com/google/tensorflow/tensorflow-android https://bintray.com/google/tensorflow/tensorflow-android

我的 build.gradle 文件:

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'

我遇到了同样的错误

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

使用tensorflow-android 1.3.0(在这里找到https://mvnrepository.com/artifact/org.tensorflow/tensorflow-android/1.3.0 https://mvnrepository.com/artifact/org.tensorflow/tensorflow-android/1.3.0).

但是,我能够使用夜间构建来运行示例语音识别应用程序(http://ci.tensorflow.org/view/Nightly/job/nightly-android/286/artifact/out/tensorflow.aar http://ci.tensorflow.org/view/Nightly/job/nightly-android/286/artifact/out/tensorflow.aar).

您必须下载 .aar,将其添加到您的项目中并替换

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

与.aar。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tensorflow:无法在 gradle 中解析 的相关文章

随机推荐