A deep dive into deploying a U-Net-based neural network on Android using TensorFlow Lite (LiteRT) for real-time image segmentation in medical applications.

Introduction

In this exercise, we explored the integration of a machine learning model — U-Net — into an Android application for segmenting medical images in real time. Using TensorFlow Lite (LiteRT), we optimized the trained model for mobile devices, ensuring performance, low latency, and offline availability.

What is U-Net?

U-Net is a convolutional neural network architecture designed for semantic segmentation tasks, particularly in biomedical imaging. It consists of:

  • Encoder: Extracts image features using Conv2D and MaxPooling.
  • Decoder: Reconstructs image resolution via upsampling.
  • Skip Connections: Preserve spatial detail by connecting encoder and decoder layers at matching levels.

Key Concepts Explored

  • Training U-Net using TensorFlow (on Google Colab).
  • Exporting the model to .tflite using TFLiteConverter.
  • Optimizing the model using quantization, pruning, and clustering.
  • Integrating the model in an Android app as an asset.
  • Running real-time inference using the Interpreter API.

Examples Implemented

  • Training a U-Net model for object segmentation using MobileNetV2 as encoder.
  • Exporting and saving the model as model.tflite.
  • Loading the TFLite model into an Android app and preprocessing input images.
  • Segmenting camera images and overlaying mask on the original input.

Code Examples

Full code and model training scripts are available in my GitHub repository. These include:

  • U-Net model architecture and training notebook (Colab).
  • LiteRT model conversion and optimization.
  • Android code for loading and running the model with camera input.

Reflection

This project highlighted the real-world application of deep learning in mobile health technology. By integrating a U-Net model into an Android app using LiteRT, we achieved on-device, privacy-preserving image segmentation — a key enabler in modern medical diagnostics. This experience has deepened my understanding of ML deployment workflows and mobile optimization.