EDGE FDE
IntermediatePyTorch to Android with LiteRT
Train a small Fashion-MNIST clothing classifier on a Mac. Use MPS if you have it, or CPU if you do not. Then export the model, convert it to LiteRT/TFLite, and show clothing labels in a Kotlin Android app.
For someone who can write Python and Kotlin and is new to LiteRT. Convert on Linux. The official LiteRT Torch converter currently says it supports Linux. Android is where the finished app runs.
Lessons
Key concepts
- Train a Fashion-MNIST clothing classifier on a Mac with MPS or CPU. No CUDA.
- Convert on Linux with
litert-torchintoclothing.tflite. - Ship the
.tflitefile in an Android APK and run LiteRTCompiledModel. - One contract: NCHW
[1, 1, 28, 28]float32 in,[1, 10]logits out, ten fixed labels.
Takeaways
- You can train on a Mac, convert on Linux, and show a clothing label in Kotlin.
- You use
CompiledModel, not the olderInterpreter, for new code. - You can keep the same
ClothingCNNcontract as the Core AI course on a different device.
Agent briefs
FAQ
Can I train on a Mac then run on Android?
Yes. Train the Fashion-MNIST clothing classifier on a Mac with MPS or CPU (no CUDA). Convert on Linux with litert-torch to clothing.tflite, then run LiteRT CompiledModel in a Kotlin Android app.
Why convert on Linux?
The official LiteRT Torch converter currently says it supports Linux. Android is where the finished app runs.
Should I use Interpreter or CompiledModel?
Use CompiledModel, not the older Interpreter, for new code.
Is the model contract the same as the Core AI course?
Yes. One contract: NCHW [1, 1, 28, 28] float32 in, [1, 10] logits out, ten fixed labels. Same ClothingCNN on a different device.
Where does Core AI fit?
Core AI is the Apple sibling path โ see PyTorch to Core AI in Xcode.