An interactive web application for training custom image classification models directly in your browser. Built with ml5.js and MobileNet, this tool allows you to upload your own images, train a model, and classify new images in real-timeβno backend or installation required.
- Custom Training - Upload and label your own images across three customizable classes
- Real-time Preview - See your training data with thumbnail previews as you upload
- Dynamic Labels - Rename classes on-the-fly with automatic heading updates
- Visual Training Progress - Animated progress bar showing model training status
- Instant Classification - Classify new images immediately after training completes
- Complete Reset - Clear all data and start fresh with one click
- Fully Client-side - Runs entirely in the browser, no data leaves your machine
- A modern web browser (Chrome, Firefox, Safari, or Edge)
- JavaScript enabled
- Internet connection (for loading ml5.js CDN)
- Clone or download this repository:
git clone https://github.com/AlexChulo/POC
cd POC-
Open
index.htmlin your web browser:- Double-click the file, or
- Right-click β Open with β Your browser, or
- Drag and drop into your browser window
-
That's it! No build process, no dependencies to install.
POC/
βββ index.html # Main application structure
βββ script.js # ML5.js functionality and logic
βββ style.css # Styling and responsive layout
βββ README.md # This file
For each class you want to classify:
- Enter a descriptive label (e.g., "Apple", "Banana", "Orange")
- Click the π€ Upload Images button
- Select multiple images from your device (minimum 2 images recommended)
- Watch as thumbnails appear showing your training data
Requirements:
- At least 2 classes with uploaded images
- Minimum 4 total images across all classes
- Images should be clear and representative of the class
Tips for Best Results:
- Upload 5-10 images per class for better accuracy
- Use varied angles, lighting conditions, and backgrounds
- Ensure images clearly show the object you want to classify
- Keep images reasonably sized (large images will be processed but may take longer)
- Once you've uploaded enough images, the π Train Model button will activate
- Click the button to begin training
- Watch the progress bar as the model learns from your images
- Training typically completes in 5-15 seconds depending on the number of images
The model uses transfer learning with MobileNet, meaning it leverages a pre-trained neural network and adapts it to your specific classes.
- After training completes, the prediction section appears
- Click Choose Image to Classify
- Select an image you want to classify
- View the results:
- Predicted Label: Which class the model thinks the image belongs to
- Confidence: Percentage indicating the model's certainty (0-100%)
Click π Reset All to:
- Clear all uploaded images
- Reset all labels to defaults
- Remove the trained model
- Start over with fresh data
This tool can be used for various classification tasks:
- Fruit Recognition - Distinguish between different types of fruits
- Object Sorting - Classify tools, toys, or household items
- Educational Demonstrations - Teach machine learning concepts interactively
- Prototype Testing - Quickly test if objects can be visually distinguished
- Pet Classification - Identify different animals or breeds
- Product Categorization - Sort items by type, color, or category
- Base Model: MobileNet (pre-trained on ImageNet)
- Technique: Transfer Learning with custom classification layer
- Library: ml5.js v0.12.2
- Processing: 100% client-side (browser-based)
- Data Storage: In-memory only (no persistence)
- Feature Extraction: MobileNet extracts high-level features from each uploaded image
- Model Training: A new classification layer learns to map these features to your custom labels
- Prediction: New images are processed through the same feature extractor and classified using your trained model
Tested and working on:
- Google Chrome (recommended)
- Mozilla Firefox
- Safari
- Microsoft Edge
To add a fourth class or more:
- In
index.html, duplicate a class section:
<div class="class-section">
<h3 id="headingD">Class D</h3>
<input type="text" id="labelD" placeholder="Enter your label" value="" oninput="updateHeading('D')">
<input type="file" id="fileD" accept="image/*" multiple onchange="handleFiles('D')">
<label for="fileD" class="file-label">π€ Upload Images</label>
<div class="image-count" id="countD">Images: 0</div>
<div class="preview-container" id="previewD"></div>
</div>- In
script.js, update the data structures:
let counts = { A: 0, B: 0, C: 0, D: 0 };
let trainingImages = { A: [], B: [], C: [], D: [] };- Update the options:
const options = {
numLabels: 4 // Change to match your number of classes
};All visual styling is in style.css. You can easily modify:
- Color scheme: Change gradient backgrounds and button colors
- Layout: Adjust grid spacing and container widths
- Typography: Modify fonts and sizes
- Spacing: Adjust padding and margins
Example - Change the main gradient:
body {
background: linear-gradient(135deg, #your-color-1 0%, #your-color-2 100%);
}- Check internet connection - ml5.js loads from a CDN
- Verify browser console - Press F12 to check for errors
- Try refreshing - Sometimes the CDN needs a retry
- Upload more images - Need at least 2 classes with images
- Check total count - Minimum 4 images required across all classes
- Verify file format - Only image files (jpg, png, gif, webp) are accepted
- Add more training images - 5-10 per class is recommended
- Improve image quality - Use clear, well-lit photos
- Increase variety - Include different angles and backgrounds
- Check class similarity - Very similar objects may be harder to distinguish
- Reduce image sizes - Large images take longer to process
- Close other tabs - Free up browser memory
- Use Chrome - Generally offers best performance for ML tasks
- This is normal - Model may genuinely be uncertain
- Add more training data - More examples improve confidence
- Check image quality - Blurry or unclear images reduce confidence
- Verify class distinctiveness - Similar-looking classes are harder to separate
- Consistent lighting - Try to maintain similar lighting across training images
- Varied backgrounds - Include different backgrounds to improve generalization
- Multiple angles - Capture objects from different perspectives
- Clear subjects - Ensure the object of interest is clearly visible
- Balanced classes - Upload similar numbers of images for each class
- Test progressively - Start with very different objects, then try more similar ones
- No data collection - All processing happens locally in your browser
- No uploads - Images never leave your device
- No tracking - No analytics or monitoring
- Session-only storage - Data is cleared when you close the browser tab
To learn more about the technologies used:
- ml5.js - Friendly machine learning for the web
- MobileNet - Efficient CNN architecture
- HTML5 - Structure and semantics
- CSS3 - Styling and animations
- Vanilla JavaScript - Logic and interactivity
This project is available for personal and educational use.
Alex
- GitHub: @AlexChulo
If you encounter issues or have questions:
- Check the troubleshooting section above
- Review the browser console for error messages (F12)
- Ensure you're using a modern, updated browser
- Verify your internet connection for CDN access
Happy Classifying! π