The simple android app for trying CameraX and PyTorch Mobile or TensorFlow Lite inference
This app requires a pre-trained model supporting mobile devices of PyTorch or TensorFlow.
Available input shapes of each ML Library are as follows:
- PyTorch - (N, H, W, C)
- TensorFlow - (N, C, H, W)
The sample pre-trained model is contained already (only TensorFlow).
- Clone this project to your local environment.
- Open MLModule.kt and comment out either one PyTorch or TensorFlow.
If you want to use TensorFlow, the code is like below.
fun provideMLImageConverter(
@ApplicationContext context: Context
): MLImageConverter =
// comment out either one you want to use
MLImageConverterTF(context)
// MLImageConverterPytorch(context)
}
The following 3rd and 4th steps differ depending on a ML Library selected.
- Create Assets Folder and put your model there.
Click onFile
, thenNew
>Folder
>Assets Folder
. - Modify the model path in MLImageConverterPytorch.kt.
// private const val MODEL_PATH = "GANModel.ptl"
private const val MODEL_PATH = "MyModel.ptl"
If you would like to use the sample model contained in the project already, skip these steps and take the 5th step.
- Import your TensorFlow Lite Model.
Click onFile
, thenNew
>Other
>TensorFlow Lite Model
. - Modify the code that instantiating an imported model in MLImageConverterTF.kt.
// private val model = LiteModelEsrganTf21.newInstance(context, option)
private val model = "MyModel.newInstance(context, option)"
- Open GlobalConfig.kt, modify each number of pixels in the height and the width of an input image.
- Run the app.