Skip to content

The simple android app for trying CameraX and PyTorch Mobile or TensorFlow Lite inference

Notifications You must be signed in to change notification settings

ryu38/camerax-pytorch-tflite

Repository files navigation

camerax-pytorch-tflite

The simple android app for trying CameraX and PyTorch Mobile or TensorFlow Lite inference

Screenshots

Getting Started

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).

Instructions

  1. Clone this project to your local environment.
  2. 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.

PyTorch

  1. Create Assets Folder and put your model there.
    Click on File, then New > Folder > Assets Folder.
  2. Modify the model path in MLImageConverterPytorch.kt.
// private const val MODEL_PATH = "GANModel.ptl"
private const val MODEL_PATH = "MyModel.ptl"

TensorFlow

If you would like to use the sample model contained in the project already, skip these steps and take the 5th step.

  1. Import your TensorFlow Lite Model.
    Click on File, then New > Other > TensorFlow Lite Model.
  2. 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)"

  1. Open GlobalConfig.kt, modify each number of pixels in the height and the width of an input image.
  2. Run the app.

About

The simple android app for trying CameraX and PyTorch Mobile or TensorFlow Lite inference

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages