Software Mansion Przemyslaw Weglik

Software Mansion's On-Device AI/ML in React Native

Original post On-Device AI/ML in React Native

Article Summary

Przemyslaw Weglik from Software Mansion shows how to run real-time AI models directly on mobile devices using React Native. No server calls, no latency, just pure on-device inference.

This hands-on tutorial demonstrates building a background blur feature using on-device machine learning in React Native. The implementation combines react-native-vision-camera with TensorFlow Lite to process video frames in real-time, running a segmentation model entirely on the phone.

Key Takeaways

Critical Insight

Modern mobile phones can run real-time computer vision models locally, enabling features like background blur without sending data to servers.

Continue reading

What This Article Covers

Problem

When developers applied segmentation masks at 256x256 resolution, the boundaries between the sharp foreground and blurred background looked pixelated and rough. This required extra post-processing work to fix.

Solution

Software Mansion used Skia ImageFilter techniques to smooth out the mask edges. They applied erosion with a 7x7 kernel, followed by a 5x5 blur kernel, before blending the layers together.

Impact

The erosion and blur filters created smooth, natural transitions between the foreground portrait and the blurred background. The pixelated look that appeared in earlier versions was gone.

The article reveals a critical performance issue with RAM consumption in debug mode that developers need to watch out for.

This page summarizes “On-Device AI/ML in React Native” by Software Mansion, published Jun 24, 2024. All credit for the original work goes to the authors.

Read the original on blog.swmansion.com (opens in new tab)

AI tools for React Native

Browse all AI tools →