videokit-ai / videokit

Low-code, cross-platform media SDK for Unity Engine. Register at https://videokit.ai
https://videokit.ai
Apache License 2.0
107 stars 14 forks source link

Fatal Exception: java.lang.Exception ArgumentException : Failed to create MLModel from graph data #57

Closed LoopIssuer closed 1 year ago

LoopIssuer commented 1 year ago

Hi I am using Natml VideoKit + NatML Meet sample. Only on Android 9 I get an issue (sometimes crash), that there is no camera image. I get this crash stack trace:

Fatal Exception: java.lang.Exception
ArgumentException : Failed to create MLModel from graph data

NatML.MLEdgeModel.Create (NatML.API.Types.Tag tag, NatML.MLEdgeModel+Configuration configuration, System.String accessKey) (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
Assets.Scripts.Presentation.VideoCall.VideoCallScene.VideoCall.NatMlMeetBackgroundRemover.Start () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) (at <00000000000000000000000000000000>:0)
NatML.MLEdgeModel.Create (NatML.API.Types.Tag tag, NatML.MLEdgeModel+Configuration configuration, System.String accessKey) (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <00000000000000000000000000000000>:0)

I use this code:

        public async void Start()
        {
            _segmentationTextureBlackWhite.Release();
            _segmentationImageFinal.Release();
            _model = await MLEdgeModel.Create("@natml/meet");
            _predictor = new MeetPredictor(_model);
            _cameraManager.OnCameraFrame.AddListener(OnCameraFrame);
        }

Please help I use
"ai.natml.videokit": "0.0.13", "ai.natml.vision.meet": "1.0.6",

olokobayusuf commented 1 year ago

Hey @LoopIssuer , can you share the full, unfiltered logs from logcat? The underlying reason for the exception will get logged before this exception. And just to confirm, it only happens on Android 9?

LoopIssuer commented 1 year ago

Debug.txt verbose.txt I confirm that it is only on Android 9 - tested on 2 phones: Samsung Galaxy S8 and Red mi note 5.

olokobayusuf commented 1 year ago

Can you try running only on the CPU?

var configuration = new MLEdgeModel.Configuration();
configuration.computeTarget = MLEdgeModel.ComputeTarget.CPU;
var predictor = await MeetPredictor.Create(configuration);
LoopIssuer commented 1 year ago

@olokobayusuf It works on Samsung Galaxy S8. But on Red mi note 5 - still no camera image.

LoopIssuer commented 1 year ago

This is log from Red mi note 5, where there is no camera image. I can see this in log: Access denied finding property "vendor.camera.aux.packagelist" and double-checked that camera permission was granted.

verbose xiaomi.txt

olokobayusuf commented 1 year ago

This is log from Red mi note 5, where there is no camera image. I can see this in log: Access denied finding property "vendor.camera.aux.packagelist" and double-checked that camera permission was granted.

verbose xiaomi.txt

This seems to be a device-specific issue, from the logs:

W/System.err: java.lang.RuntimeException: Fail to connect to camera service
W/System.err:     at android.hardware.Camera.<init>(Camera.java:629)
W/System.err:     at android.hardware.Camera.open(Camera.java:451)
W/System.err:     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
W/System.err:     at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
W/System.err:     at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:201)

Since the original issue is fixed, I'm closing this out.

LoopIssuer commented 1 year ago

@olokobayusuf Just one question: by "device-specific issue" you mean: a) this specific device is sth wrong with camera as a hardware b) this device model could have sth wrong with camera as a hardware c) this device model has sth weird with camera, that is stopping to work with NatML

I am asking, because the same device has a camera working in the another Unity apps.

olokobayusuf commented 1 year ago

I think it's the specific device you're testing on, not the device model. You could try restarting the device to see if that helps.

LoopIssuer commented 1 year ago

Ok, thanks, we will try (device is at our tester only). Really last question - are there any cons of this configuration with MLEdgeModel.ComputeTarget.CPU? Like performance or quality drop? I'm wondering whether to add a condition like if AndroidOs=9.

LoopIssuer commented 1 year ago

This change MLEdgeModel.ComputeTarget.CPU We tested now with restarting on xiaomi - still no camera image.

In the other applications like Meets, Messanger, our application with previous implementation of background cropping (homuler's Mediapipe Unity plugin) - camera is working ok.

Also tested with Huawei P20 Lite Android 9 - camera image is ok.

olokobayusuf commented 1 year ago

@LoopIssuer can you open a new issue for the camera issue on the Redmi Note 5?