Description
The issue
Inside Xamarin.TensorFlow.Lite.Gpu" Version="2.12.0.1"
we are missing
CompatibilityList.BestOptionsForThisDevice
and
constructor GpuDelegate(GpuDelegate.Options options)
to be able to to implement gpu acceleration as described here:
https://www.tensorflow.org/lite/android/delegates/gpu?hl=en#enable_gpu_acceleration_2
and in .net maui like that:
var compatList = new CompatibilityList();
if (compatList.IsDelegateSupportedOnThisDevice)
{
var bestOptions = compatList.BestOptionsForThisDevice; //<- no BestOptionsForThisDevice
var gpuDelegate = new GpuDelegate(bestOptions); //<- constructor not accepting parameters
options.AddDelegate(gpuDelegate);
}
The c# code above started working for me after i implemented the solution described below.
The cause of this is that is either:
a - tensorflow-lite-gpu-api
was not included at all
b - both gpu-related aar's where processed is same project: both tensorflow-lite-gpu-api-2.13.0.aar
and tensorflow-lite-gpu-2.13.0.aar
define classes absolutely for same package tensorflow/lite/gpu
, that creates a conflict for bindings generator and it just skips one of them (tensorflow-lite-gpu-api
in our case).
This makes GpuDelegateFactory.Options
not to be available and bindings are not generated for CompatibilityList.BestOptionsForThisDevice
and the second constructor GpuDelegate(GpuDelegate.Options options)
The solution
To bind tensorflow-lite-gpu-api-2.13.0.aar
and tensorflow-lite-gpu-2.13.0.aar
in different projects, the latter would reference the first one with "-api"
https://github.com/taublast/AppoMobi.Maui.TensorFlow.Lite
Context
This was all about a .net maui 7.0 for android, trying to use
<PackageReference Include="Xamarin.TensorFlow.Lite.Gpu" Version="2.12.0.1" />