Historically, running machine learning required sending user data over HTTP to a centralized cloud server. Today, modern client devices (laptops, iPhones, Androids) possess powerful GPUs and Neural Processing Units (NPUs). Client-Side Machine Learning executes models directly inside the user's web browser using TensorFlow.js and ONNX Runtime Web.
Browsers execute client-side machine learning at near-native speeds by compiling matrix operations directly to GPU hardware shaders:
<!DOCTYPE html>
<html>
<head>
<title>In-Browser AI Classifier</title>
<!-- Load TensorFlow.js and MobileNet vision model -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"></script>
</head>
<body>
<h3>Instant In-Browser Computer Vision (Zero Server Cost)</h3>
<img id="userImage" src="dog.jpg" width="300" crossOrigin="anonymous"/>
<div id="status">Loading AI model into WebGL memory...</div>
<script>
async function runInference() {
// 1. Load pre-trained MobileNet model directly in browser
const model = await mobilenet.load();
document.getElementById('status').innerText = 'Model Loaded! Classifying image on GPU...';
// 2. Perform zero-latency client prediction
const img = document.getElementById('userImage');
const predictions = await model.classify(img);
// 3. Display Top Predictions
console.log('Predictions:', predictions);
document.getElementById('status').innerHTML =
'<strong>Top Prediction:</strong> ' + predictions[0].className +
' (' + (predictions[0].probability * 100).toFixed(1) + '% confidence)';
}
window.onload = runInference;
</script>
</body>
</html>
Broaden your foundational and advanced Machine Learning knowledge across our curriculum:
Convert PyTorch and Scikit-Learn models for browser deployment.
Architectural comparison: Zero server cost vs centralized computing.
Real-time webcam computer vision using TensorFlow.js.
Master full-stack machine learning techniques.