doc-ai / tensorio-android

TensorIO for Android
2 stars 6 forks source link

Convert to mutlimodule project #159

Closed phildow closed 4 years ago

phildow commented 4 years ago

Check it out @RohanJahagirdar

See https://jitpack.io/docs/BUILDING/#multi-module-projects

Right now we have a module tensorio exporting the package ai.doc.tensorio with a number of subpackages, including the TIOTFLiteData and TIOTFLiteModel subpackages.

The structure looks like:

tensorio
  ai.doc.tensorio
    TIOData
    TIOLayerInterface
    TIOModel
    TIOTFLiteData
    TIOTFLiteModel
    TIOUtilities

This is currently imported into a project using Jitpack as follows:

implementation 'com.github.doc-ai:tensorio-android:0.9.6'

Right now the exported package assumes we're using a TF Lite backend, but we'd like to support multiple backends for tensor/io in a modular manner, including specifically a full TensorFlow backend. How can we do that?

The first thought is to continue to contain everything in a single module and organize multiple backends into subpackages, so:

tensorio
  ai.doc.tensorio
    core
      ...
    tflite
      ...
    tensorflow
      ...

But with this structure there is no way to only import say only the tflite code and exclude the tensorflow code, or vice versa, since they are subpackages underneath the single root package exported by the module, and Jitpack imports the whole module.

In fact we can't even move the packages to the root level for the same reason, i.e.:

tensorio
  ai.doc.tensoriocore
  ai.doc.tensoriotflite
  ai.doc.tensoriotensorflow

But if I understand Jitpacks documentation at Multi-module Projects correctly then we can have the single repository export multiple modules and then target those modules separately in gradle. The structure now looks like:

tensoriocore
  ai.doc.tensoriocore
    TIOData
    ...

tensoriotflite
  ai.doc.tensoriotflite
    TIOTFLiteModel
    TIOTFLiteData

tensoriotensorflow
  ai.doc.tensoriotensorflow
    TIOTensorFlowModel
    ...

We would have to be sure that we can explicitly define dependencies among the modules, but then we can target them in gradle with:

implementation 'com.github.doc-ai:tensorio-android:tensoriocore:0.9.6'
implementation 'com.github.doc-ai:tensorio-android:tensoriotflite:0.9.6'
phildow commented 4 years ago

And I was just reading that although you can't publish the same package from two modules you can publish subpackages, since the names are independent of one another, so we might be able to do:

tensoriocore
  ai.doc.tensorio.core
    TIOData
    ...

tensoriotflite
  ai.doc.tensorio.tflite
    TIOTFLiteModel
    TIOTFLiteData

tensoriotensorflow
  ai.doc.tensorio.tensorflow
    TIOTensorFlowModel
    ...

Which is nice. I'm going to create a test project and see if I can actually get this working, since I'd like to have this structure in place prior to the 1.0 tag

phildow commented 4 years ago

Oh man, even better I can keep the module names super simple since they are namespaced to the project, and then I'll update the individual filenames to drop the TIO prefix, so we end up with:

core
  ai.doc.tensorio.core
    Data
    ...

tflite
  ai.doc.tensorio.tflite
    Model
    Data

tensorflow
  ai.doc.tensorio.tensorflow
    Model

Oh yeah. That's it. And then gradle imports are:

implementation 'com.github.doc-ai:tensorio-android:tflite:0.9.6'
phildow commented 4 years ago

@RohanJahagirdar ^^^^ Multimodule project, how to