Is there any way to develop project by using Kotlin Multiplateform and tensor flow lite model in the shared logic. Target is to use same tensor flow model with same kotlin code to retrieve data from it with android and iOS both. UI is desired to be developed separately with platform specific code.
I have explored many project of kotlin MPP with shared logic of kotlin to be used in android and iOS both but I have doubt about tenserflow lite model. will it work fine in shared logic of kotlin and give same data to android and iOS both?
Both iOS and Android have libraries for using TensorFlow but those libs are different libs, they are written for each platform independently (unlike TensorFlow C API which can be built for Android and iOS). So you won’t be able to use officially supported TensorFlow API in common kotlin code.
Fortunately you can divide your common logic from platform dependent TensorFlow API calls by introducing a common
interface TensorFlowNativeApi. Just add some necessary TensorFlow API methods into this interface and call them in common code. Then in apps for each platform create a class that implements this interface (using TensorFlow lib for particular platform) and pass this implementation to your common code that uses TensorFlow.
Also worth noting that the same TensorFlow Lite model can be used on both platforms, it is just must be converted from TensorFlow model using converter.