我正在按照 Codelab 进行操作:https://codelabs.developers.google.com/codelabs/mlkit-android-custom-model/#0。操作按照原始设置可以正常进行,但是当我删除提供的本地模型以强制使用云模型时,就会出现一个不明确的错误。
我与 codelab 不同之处在于:
// manager.registerLocalModelSource(localModelSource)
manager.registerCloudModelSource(cloudSource)
return FirebaseModelOptions.Builder()
.setCloudModelName(HOSTED_MODEL_NAME)
// .setLocalModelName("asset")
.build()
将“local”模型配置注释掉,以便强制项目使用托管的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)
我尝试了一些方法:
- 我的项目具有互联网权限,并且Firebase Analytics正常工作,因为我可以在DebugView中看到事件。
- 本地模型与ML Kit中托管的模型相同。
- 模型名称正确。
在已root的模拟器上运行并导航到应用程序数据文件夹,我可以找到命名为以下内容的模型文件夹:
/data/data/work.beltran.mlkitcustommodelcodelab/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MTo2ODI2MzU4OTg3OTY6YW5kcm9pZDozMGYwZDA3MmQ5NDBjODEx/mobilenet
然而,该文件夹为空
我唯一的猜测:由于某种原因,Firebase决定不下载该模型,但无法找出原因。