SmartphonePi

Repurposing an Old Android Phone as an Edge AI Device

Abstract

An old smartphone already has everything an edge AI prototype needs: a camera, a microphone, sensors, a battery and a capable multi-core ARM CPU. In most drawers it does nothing. SmartphonePi repurposes it as a small edge-AI and media device, playing the role a single-board computer such as a Raspberry Pi would normally play.

The toolkit runs on Termux and needs no root. It runs ONNX models locally on the phone, captures camera and audio data through the Termux APIs, monitors battery and sensors, and serves small web UIs over the network. The same scripts also run on Linux (Raspberry Pi or desktop) through V4L2 cameras.

Inference Pipeline

flowchart LR
    C1[Phone camera<br/>termux-camera-photo] --> F[Frame]
    C2[USB / CSI camera<br/>V4L2 on Linux] --> F
    F --> P[Preprocessing<br/>resize · normalize · CHW]
    P --> O[ONNX Runtime<br/>XNNPACK or CPU]
    O --> K[Predicted class]
    K --> W[Flask web UI]

The ONNX Runtime session adapts to the device: it detects the number of CPU cores, prefers the XNNPACK execution provider when it is available and falls back to the default CPU provider otherwise.

Features

  • On-device classification with TakuNet variants (FP16, FP32 and a simplified FP32 graph), to test lightweight models on real phone hardware.
  • Benchmark script: warm-up followed by timed runs, reporting mean, median, standard deviation, p95 and p99 latency and FPS, with configurable threads and fixed seeds.
  • Web interfaces: an on-demand snapshot mode (low load, one frame per request), a continuous MJPEG stream with live classification and an optional enhancement mode, and a V4L2 stream for Linux cameras.
  • Hardware access without root through Termux:API: battery, sensors, location, camera and microphone.
  • RetroGaming: a small web app to manage ROMs and save files.

Notes

The installation guide covers the rough edges of running Python ML on Android, such as ABIs without a prebuilt onnxruntime wheel and the native libraries Pillow and NumPy need inside Termux. Model files are not stored in the repository.

Resources