Create Artistic Effect by Stylizing Image Background — Part 3: Android Implementation

  • Combination of different TensorFlow ML models inside an android application.
  • TensorFlow Support library for bitmap loading.
  • TensorFlow Task library for Segmentation procedure.
  • ML Binding for Style Transfer operation.
  • It is backwards compatible till Android 5.0 / Lollipop (API 21) and it works with at least 90% devices in the market.
  • Under the hood, it uses and leverages the Camera 2 APIs. It basically provides the same consistency as Camera 1 API via Camera 2 Legacy layer and it fixes a lot of issues across the device.
  • It also has a lot of awesome advanced features like Portrait, HDR, Night mode etc (provided your Device supports that).
  • CameraX has also introduced use cases which allow you to focus on the task you need to get it done and not waste your time with specific devices. Few of them are Preview, Image Analysis, Image Capture.
  • CameraX doesn’t have specific call/stop methods in onResume() and onPause() but it binds to the lifecycle of the View with the help of CameraX.bindToLifecycle().
  • Create a Video Recorder App using CameraX.
  • Use Image Analysis to perform Computer Vision, ML. So it implements the Analyzer method to run on each and every frame.
  • First make sure the TensorFlow Lite model contains metadata.
  • Create assets folder under the app module, and place the .tflite model file there. In our case “lite-model_deeplabv3_1_metadata_2.tflite”.
  • Then add gradle dependency:
implementation ‘org.tensorflow:tensorflow-lite-task-vision:0.0.0-nightly’
val tensorImage = TensorImage.fromBitmap(bitmap)            
val results: List<Segmentation>= imageSegmenter.segment(tensorImage)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
George Soloupis

George Soloupis

I am a pharmacist turned android developer and machine learning engineer. Right now I’m a senior android developer at Invisalign and a ML GDE.