A lightning fast bitmap to tensor conversion library for Android.
In time-critical scenarios, per-pixel normalization and channel reordering can determine whether a computer-vision pipeline runs in real time. Tensor Bolt accelerates these operations by performing them in parallel using NEON or SSE intrinsics.
Designed to work seamlessly with the most popular mobile machine-learning frameworks, this lightweight library delivers up to 10× faster bitmap-to-tensor conversions, helping you optimize performance in ML-powered apps with minimal overhead.
import com.laoluani.tensorbolt.TensorBolt
import android.graphics.Bitmap
private val rgbConverter = TensorBolt.rgbFloat32Converter(WIDTH, HEIGHT)
val bitmap: Bitmap = // Your bitmap
val tensorBuffer: ByteBuffer = rgbConverter.convert(bitmap)
// Convert buffer into native type for respective ML framework
// For max performance use a zero copy conversion methodYou need to build the AAR for this library locally and then add the build artifact a as a local dependency
-
Clone repo Tensor Bolt repo
git clone git@github.com:laoluani/tensor-bolt.git
-
Build Tensor Bolt AAR
cd tensor-bolt ./gradlew tensor-bolt:assembleRelease -
Copy build artifact into your projects local dependencies folder, artifact can be found in
tensor-bolt/tensor-bolt/build/outputs/aar/tensor-bolt-release.aar -
Now in your Android project add Tensor Bolt as a local dependency
dependencies { implementation(files("libs/tensor-bolt-release.aar")) } -
Sync and build your project
| Framework / Toolkit | Android Support |
|---|---|
| TensorFlow Lite | ✅ Supported |
| PyTorch Mobile | ✅ Supported |
| ONNX Runtime Mobile | ✅ Supported |
| Lite RT | ✅ Supported |
| ExecuTorch | ✅ Supported |
Min SDK Android 21 (Lollipop)
- Bitmap to float32 normalisation
- Bitmap to gray scale