我正在遵循Codelab:https://codelabs.developers.google.com/codelabs/mlkit-android-custom-model/#0,并且按原样工作,但是一旦我删除提供的本地模型以强制使用云模型,就会收到一个模糊的错误。
与代码实验室的不同之处是:
// manager.registerLocalModelSource(localModelSource)
manager.registerCloudModelSource(cloudSource)
return FirebaseModelOptions.Builder()
.setCloudModelName(HOSTED_MODEL_NAME)
// .setLocalModelName("asset")
.build()
注释掉“本地”模型配置,因此我强制项目使用托管的ML Kit模型。
但是,运行模型时出现以下错误:
E/MainActivity: com.google.firebase.ml.common.FirebaseMLException: The load task failed
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.ml.common.FirebaseMLException: The load task failed
at com.google.android.gms.tasks.zzu.getResult(Unknown Source:17)
at work.beltran.mlkitcustommodelcodelab.MainActivity$onCreate$$inlined$use$lambda$1.then(MainActivity.kt:61)
at com.google.android.gms.tasks.zzd.run(Unknown Source:26)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: com.google.firebase.ml.common.FirebaseMLException: The load task failed
at com.google.android.gms.internal.firebase_ml.zzgy.zzf(Unknown Source:75)
at com.google.android.gms.internal.firebase_ml.zzgu.call(Unknown Source:8)
at com.google.android.gms.internal.firebase_ml.zzgp.zza(Unknown Source:0)
at com.google.android.gms.internal.firebase_ml.zzgq.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:172)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: com.google.firebase.ml.common.FirebaseMLException: Cannot load custom model
at com.google.android.gms.internal.firebase_ml.zzhn.zzey(Unknown Source:148)
at com.google.android.gms.internal.firebase_ml.zzha.zzfb(Unknown Source:75)
at com.google.android.gms.internal.firebase_ml.zzha.call(Unknown Source:0)
at com.google.android.gms.internal.firebase_ml.zzgp.zza(Unknown Source:0)
at com.google.android.gms.internal.firebase_ml.zzgq.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:172)
at android.os.HandlerThread.run(HandlerThread.java:65)
我尝试过的一些东西:
在有根的模拟器上运行,导航至应用程序数据文件夹,我可以找到名为以下内容的模型文件夹:
/data/data/work.beltran.mlkitcustommodelcodelab/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MTo2ODI2MzU4OTg3OTY6YW5kcm9pZDozMGYwZDA3MmQ5NDBjODEx/mobilenet
但是文件夹为空
我唯一的猜测:Firebase出于某种原因决定不下载模型,无法弄清原因。
答案 0 :(得分:-1)
我必须添加SHA证书指纹才能使其正常工作。
如果您缺少该步骤,则不会下载ML模型。
按照此处的说明为证书生成SHA:https://developers.google.com/android/guides/client-auth
并在设备项目设置中引入输出。