hms-ml-demo icon indicating copy to clipboard operation
hms-ml-demo copied to clipboard

Using two offline MLTextAnalyser at same time doesn't work

Open minkiapps opened this issue 3 years ago • 7 comments

I have this weird case that as sonn as I try to use more than on offline MLTextAnalyser, they stop scanning any text. If I use one only, it works.

    private val enTextRecognizer : MLTextAnalyzer by lazy {
        MLAnalyzerFactory.getInstance().localTextAnalyzer
    }

    private val cnTextRecognizer : MLTextAnalyzer by lazy {
        val setting = MLLocalTextSetting.Factory()
            .setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
            .setLanguage("zh")
            .create()
        MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting)
    }
val mlText1 = Tasks.await(enTextRecognizer.asyncAnalyseFrame(MLFrame.fromBitmap(bitmap))) //works
val mlText2 = Tasks.await(cnTextRecognizer.asyncAnalyseFrame(MLFrame.fromBitmap(bitmap))) //doesn't work, and after that enTextRecognizer also stops working

minkiapps avatar Aug 21 '20 11:08 minkiapps

Please check whether you have loaded Chinese model or not.

implementation ‘com.huawei.hms : ml-computer-vision-ocr-cn-model : 2.0.2.200.013’

Mike-mei avatar Aug 24 '20 08:08 Mike-mei

I have

    implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.1.300'
    implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.1.300'
    implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.1.300'

minkiapps avatar Aug 31 '20 10:08 minkiapps

We plan to release new 2.0.3.300 version on 10th September, and this issue will be fixed

Mike-mei avatar Sep 01 '20 08:09 Mike-mei

please tell me as soon as they are released

minkiapps avatar Sep 10 '20 07:09 minkiapps

I updated the version to implementation 'com.huawei.hms:ml-computer-translate:2.0.3.300'

code is opensource, find it here now I face the issue again with translation model download failed, here the log:

E/MLInitializerProvider: MLInitializerProvider Done
E/ML_CountryCodeHelper: getVendorCountry=eu
E/ML_CountryCodeHelper: getVendorCountry equals eu or la ,not reliable
E/ML_CountryCodeHelper: getSimCountryCode by not enableNetwork, countryCode=it
E/.livetranslato: Invalid ID 0x00000000.
E/CountryCodeBean: getVendorCountry=eu
E/CountryCodeBean: getVendorCountry equals eu or la ,not reliable
E/CountryCodeBean: getSimCountryCode by not enableNetwork, countryCode=it
E/ML_TTS_SpeakerProvider: Response error! errcode=[7010] retMsg=[Token is invalid or expired]
E/ML_TTS_SpeakerProvider: Use default List; Voice list parse error.[{"retCode":"7010","retMsg":"Token is invalid or expired"}]
E/AbstractInitializer: huawei_module_mlkit_translate -> isForce = false, isCreatorClassRemote = true, isLocalExisted = true
E/AbstractInitializer: huawei_module_mlkit_translate -> The context of the dynamic module belongs to REMOTE
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: initlizeHaSdk APK mode,BUILD_MODE=APK
E/HaLogProvider: GrsApi.synGetGrsUrl=https://metrics2.data.hicloud.com:6447,BuildConfig.HIA_MODE=com.huawei.cloud.mlkithianalytics
E/CountryCodeBean: getVendorCountry=eu
E/CountryCodeBean: getVendorCountry equals eu or la ,not reliable
E/CountryCodeBean: getSimCountryCode by not enableNetwork, countryCode=it
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/AbstractInitializer: huawei_module_mlkit_translate -> Something wrong, need to switch context, current is REMOTE
E/AbstractInitializer: huawei_module_mlkit_translate -> Switch the context of the dynamic module to LOCAL
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: initlizeHaSdk APK mode,BUILD_MODE=APK
E/HaLogProvider: GrsApi.synGetGrsUrl=https://metrics2.data.hicloud.com:6447,BuildConfig.HIA_MODE=com.huawei.cloud.mlkithianalytics
E/CountryCodeBean: getVendorCountry=eu
E/CountryCodeBean: getVendorCountry equals eu or la ,not reliable
E/CountryCodeBean: getSimCountryCode by not enableNetwork, countryCode=it
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/HaLogProvider: forbiddenHiLog.getVenderCountry=UNKNOWN
E/HaLogProvider: forbiddenHiLog openHa = true
E/AbstractInitializer: huawei_module_mlkit_translate -> Something wrong, need to switch context, current is LOCAL
E/CountryCodeBean: getVendorCountry=eu
E/CountryCodeBean: getVendorCountry equals eu or la ,not reliable
E/CountryCodeBean: getSimCountryCode by not enableNetwork, countryCode=it
E/MainViewModel: Failed to download language models
    java.util.concurrent.ExecutionException: com.huawei.hms.mlsdk.common.MLException: Download model failed
        at com.huawei.hmf.tasks.a.j.a(Unknown Source:17)
        at com.huawei.hmf.tasks.Tasks.await(Unknown Source:33)
        at com.minkiapps.livetranslator.MainViewModel.downloadModel(MainViewModel.kt:60)
        at com.minkiapps.livetranslator.MainViewModel.access$downloadModel(MainViewModel.kt:15)
        at com.minkiapps.livetranslator.MainViewModel$initModels$2$chinesModelAvailableTask$1.invokeSuspend(MainViewModel.kt:41)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
     Caused by: com.huawei.hms.mlsdk.common.MLException: Download model failed
        at com.huawei.hms.mlsdk.model.download.p.s.a(RemoteDownloadManager.java:162)
        at com.huawei.hms.mlsdk.model.download.p.s.a(RemoteDownloadManager.java:33)
        at com.huawei.hms.mlsdk.model.download.p.u.a(TranslateModelManagerDelegate.java:31)
        at com.huawei.hms.mlsdk.model.download.p.e.a(ModelDownloadManagerDelegate.java:13)
        at com.huawei.hms.mlsdk.model.download.MLLocalModelManager$b.call(MLLocalModelManager.java:3)
        at com.huawei.hmf.tasks.a.j$1.run(Unknown Source:4)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)

minkiapps avatar Sep 27 '20 11:09 minkiapps

Hello @minkiapps
As is shown in the log, "Token is invalid or expired", the cause of "model download failed" maybe is Token is empty or invalid.

E/ML_TTS_SpeakerProvider: Response error! errcode=[7010] retMsg=[Token is invalid or expired]

We find your code is that:

MLApplication.getInstance().apiKey = config.getString("client/api_key")

The agc file has been set right? please see the wiki

Mike-mei avatar Oct 16 '20 08:10 Mike-mei

Hey, I found out my app id in json file had a space in the middle, sorry on my side.

Nevertheless, my original error still persists after updating the dependency.. see first my first post. checkout my branch, as soon as I try to use the second ocr model, it stops recognising anything..

minkiapps avatar Oct 18 '20 13:10 minkiapps