Azure-Samples / cognitive-services-android-customvision-sample

Sample Anroid app for image classification using a TensorFlow model exported from Microsoft Cognitive Services Custom Vision
58 stars 57 forks source link

OutofMemory error occurs in the default class of Vision Skills Manager #35

Open ArunShi opened 4 years ago

ArunShi commented 4 years ago

Please provide us with the following information:

we have noted that OutofMemory error occurs in the default class of Vision Skills Manager. We could not able to edit this class because by default its comes from MS Cognitive library. Attached the log file for your reference

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Step 1: Do a ML scanning for multiple times repeatedly.

Any log messages given by the failure

Non-fatal Exception: ai.customvision.visionskills.VisionSkillsException {"NativeRuntimeError":"Skill[ObjectDetector] Build Exception <JNIWrapperException: Failed to load model; Model name = <numplate-tflite/cvexport.manifest>; details: java.lang.OutOfMemoryError: Failed to allocate a 67107856 byte allocation with 6291456 free bytes and 41MB until OOM, max allowed footprint 500119960, growth limit 536870912>"} ai.customvision.visionskills.VisionSkillsManager.throwIfJNIFailed

ai.customvision.visionskills.VisionSkillsManager.throwIfJNIFailed (VisionSkillsManager.java:24) ai.customvision.visionskills.VisionSkillsManager.SkillConfigurationBuild_orThrow (VisionSkillsManager.java:553) ai.customvision.visionskills.VisionSkillsManager.skillConfigurationBuild (VisionSkillsManager.java:309) ai.customvision.visionskills.ConfigurationBase.build (ConfigurationBase.java:41) ai.customvision.visionskills.CVSObjectDetector$Configuration.build (CVSObjectDetector.java:66) com.example.crajava.mldc.MSCognitiveServicesCustomVisionObjectDetector. (MSCognitiveServicesCustomVisionObjectDetector.java:78) com.example.crajava.mldc.ObjectDetectorActivity.onCreate (ObjectDetectorActivity.java:123) android.app.Activity.performCreate (Activity.java:7136) android.app.Activity.performCreate (Activity.java:7127) android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1271) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2926) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3081) android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:78) android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108) android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1838) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:193) android.app.ActivityThread.main (ActivityThread.java:6715) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:911)

Expected/desired behavior

It should scan without any memory exception

OS and Version?

Android

Versions

9.1

Mention any other details that might be useful


Thanks! We'll be in touch soon.

shmisra commented 4 years ago

Mr. Arun opened a ticket with MS. However I wanted to know if "Vision Skills Manager" is a Microsoft class or a custom Java library implementation. The error java.lang.OutOfMemoryError: Failed to allocate a 67107856 byte allocation with 6291456 free bytes and 41MB until OOM, max allowed footprint 500119960, growth limit 536870912>"} ai.customvision.visionskills.VisionSkillsManager.throwIfJNIFailed

does not appear from a Microsoft library. Can someone comment more on it?

amjad-twalo commented 4 years ago

Thanks @ArunShi for reporting this issue. We tried to reproduce this error with no luck so far. Could you please share some more info with us?

dwaw18 commented 3 years ago

I was able to reproduce this issue on my 2 Android devices: Samsung Galaxy S8 (Android 9) and Huawei MediaPad M5 lite (also Android 9).

I'm developing an app which is using multiple models for object detection. For now I'm using this example project to load models and detect objects with newest source code from this repository.

In my app each model is loaded by creating new MSCognitiveServicesCustomVisionObjectDetector() classifier, which constructor takes path to model.

Loading the model approx. 4-7 times (depends on device and probably on avaiable memory) results in an OutOfMemoryException inside a ai.customvision.visionskills.VisionSkillsException. This exception occurs also when loading the same model many times. It's also reproducible using example cats and dogs model provided in this project.

It occurs at this section of MSCognitiveServicesCustomVisionObjectDetector class constructor

       // Build a config object for ImageClassifier
        ai.customvision.tflite.ObjectDetector.Configuration config = ai.customvision.tflite.ObjectDetector.ConfigurationBuilder()
                .setModelFile(modelManifestPath).build();

Whole stack trace is basically the same as provided above.