ML Kit Vision 设备端文本识别未下载模型:正在等待文本识别模型下载。请稍候。

10

我知道有许多类似的问题(这里这里这里),但即使我已按照建议的指示操作,仍然遇到了同样的问题。

尽管我的项目配置看起来是正确的,但 Firebase ML Kit 似乎有问题无法下载设备上的文本识别模型,导致出现以下异常:

com.google.firebase.ml.common.FirebaseMLException: 等待下载文本识别模型。请稍等。

该项目似乎已按照要求进行了配置,在清单中的“DEPENDENCIES”元数据中设置了下载依赖项以在打开应用程序(或从 Play 商店下载)时下载:

<meta-data
   android:name="com.google.firebase.ml.vision.DEPENDENCIES"
   android:value="ocr" />

除了访问互联网和摄像头的权限:

 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.INTERNET" />

:app Gradle中包含了ML Kit Vision的实现方式: implementation 'com.google.firebase:firebase-ml-vision:24.0.1' 我还尝试了以下方法:
1.删除Google Play Services的所有数据:设置->应用->Google Play Services->存储空间->管理空间->清除全部数据
2.更新Google Play Services,重新启动并打开Google Play Store 15分钟。已安装版本:20.09.13 (120408-298964066)
3.检查可用存储空间(有13GB的可用空间)。
4.将相机权限授予应用程序和Google Play Services或者撤销该权限。
尝试使用库的代码在这里(是接口的实现):
@SuppressLint("UnsafeExperimentalUsageError")
    override fun analyze(imageProxy: ImageProxy) {
        Log.d(LOG_TAG, "Trying to detect something")
        val mediaImage = imageProxy.image
        val imageRotation = degreesToFirebaseRotation(imageProxy.imageInfo.rotationDegrees)
        if (mediaImage != null) {
            val firebaseImage = FirebaseVisionImage.fromMediaImage(mediaImage, imageRotation)
            val detector = FirebaseVision.getInstance().onDeviceTextRecognizer
            val result = detector.processImage(firebaseImage)
                .addOnSuccessListener { firebaseVisionText ->
                    // Task completed successfully
                    Log.d(LOG_TAG, "Text detected! ${firebaseVisionText.text}")

                    // Close img for next use
                    imageProxy.close()
                }
                .addOnFailureListener { e ->
                    // Task failed with an exception
                    Log.e(LOG_TAG, e.toString())
                    e.printStackTrace()

                    // Close img for next use
                    imageProxy.close()
                }
        }
    }

这篇文章是按照官方指南 这里 编写的。

这是全部输出内容:

W/izadi.explorat: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:0
E/Vision: Error loading module com.google.android.gms.vision.ocr optional module true: com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
E/OcrAnalyzer: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.
W/System.err: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.
W/System.err:     at com.google.android.gms.internal.firebase_ml.zzsc.zzd(com.google.firebase:firebase-ml-vision@@24.0.1:21)
        at com.google.android.gms.internal.firebase_ml.zzsc.zza(com.google.firebase:firebase-ml-vision@@24.0.1:39)
        at com.google.android.gms.internal.firebase_ml.zzpj.zza(com.google.firebase:firebase-ml-common@@22.0.1:31)
        at com.google.android.gms.internal.firebase_ml.zzpl.call(Unknown Source:8)
        at com.google.android.gms.internal.firebase_ml.zzpf.zza(com.google.firebase:firebase-ml-common@@22.0.1:32)
        at com.google.android.gms.internal.firebase_ml.zzpe.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at com.google.android.gms.internal.firebase_ml.zze.dispatchMessage(com.google.firebase:firebase-ml-common@@22.0.1:6)
        at android.os.Looper.loop(Looper.java:227)
        at android.os.HandlerThread.run(HandlerThread.java:67)



有什么想法吗?

是否有人对我缺少或如何解决它有任何想法? 它在我的设备(小米Mi 8-Android 10)和虚拟设备(Nexus 5X-Android 10 + Play Store)中都会出现。

3个回答

5
感谢您的反馈!
您现在使用的Google Play服务版本号为20.09.13,但该版本不在我们目前支持的可选模块下载列表中。理论上,我们应该支持所有当前生产环境中的版本,自19.8.31以后(当新版本发布时,此规则可能会改变)。
我将与我的同事核实,看看为什么您得到的是20.08.13而不是当前提供的最新版本。
同时,您可以尝试再次更新Google Play服务,以查看是否能够获取新版本。
谢谢!

7
你的回答暗示你与某些东西有关联(例如,说“在我们当前支持的列表中”),但你在这个回答、你的其他回答或你的个人资料中都没有提到你的从属关系。如果你在你的回答和/或个人资料中提到从属关系,将有助于理解这个回答和你的其他回答。鉴于你没有链接或推广任何东西,这并非必须要这样做,但这样做肯定会使你的回答更容易理解。此外,“感谢您的反馈”这个称谓在Stack Overflow上确实不准确/恰当。 - Makyen
我的 Google Play 服务已自动更新至 20.12.16,但我仍然遇到相同的错误 :/ - Izadi Egizabal
你好,之前的版本20.09.13已经重新发布以修复一些错误(这些错误与可选模块无关)。可选模块下载路径中存在一个错误,如果Google Play服务版本从不支持的版本更新到新版本,则需要重新启动设备才能使可选模块下载工作。您在Google Play服务版本更新后是否重新启动了设备?您可以尝试重新启动设备以查看是否有所帮助。同时,当修复重新启动要求的问题时,我会在这里进行更新。 - Chenxi Song
1
你好,我在之前的回复中提到的修复已经在20.12.16版本中推出。文本的可选模块下载通常需要几分钟时间。如果您仍然无法使用,请发送一个bug报告给我们,以帮助我们进一步调查故障。谢谢! - Chenxi Song
1
嗨@ChenxiSong,最终我成功让可选模块运行了。我没有将Google Play服务作为系统应用程序,这似乎阻止了可选模块的下载。在将Play服务安装到系统级别后,问题得到解决。无论如何,感谢您的帮助! - Izadi Egizabal

5
最终,在不同设备上尝试后,我意识到问题似乎与设备中安装的Google Play服务有关。在最初的测试设备上,Google Play服务被安装为用户应用程序,这显然阻止了可选模块的下载。将Play服务安装在系统级别后,问题得到了解决。
简而言之,需要安装在系统级别的Google Play服务,才能下载可选模块。

1
什么是“系统级别”? - user2137020
1
@user2137020 我的意思是 Google Apps 需要被安装在 /system 目录下,而不是直接从 APK 安装为用户应用程序。通过位于 /system 目录,它们可以访问更高权限的权限,在这种情况下似乎需要这些权限。更多信息请参见:https://android.stackexchange.com/questions/17871/what-are-the-differences-between-a-system-app-and-user-app - Izadi Egizabal

0
尝试添加这些依赖项:
// ML Kit dependencies
implementation 'com.google.firebase:firebase-ml-vision:24.0.1'
// Barcode detection model.
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2'
implementation 'com.google.firebase:firebase-ml-model-interpreter:22.0.1'

还有请查看这个链接:Android Studio ML kit无法加载OCR模块


1
谢谢您的回复,但它没有起作用。它仍然给我同样的错误 :'(。 只是为了检查,我将 onDeviceTextRecognizer 更改为 onDeviceImageLabeler,它完美地工作了,所以我真的不知道文本识别器出了什么问题。 - Izadi Egizabal
2
Firebase ML Vision已被弃用。 - Kashif Mehmood

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接