A web application that uses a Convolutional Neural Network (CNN) to classify stain images and provide cleaning recommendations.
Use the built-in scraper to download stain images:
Windows:
cd scraper
download.batOr manually:
cd scraper
pip install -r requirements.txt
python scraper.py # Download all stain types
python scraper.py ketchup chocolate # Download specific types only
python scraper.py --num 200 # Download 200 images per typeOr add your own stain images to the folders inside model/data/:
model/data/
├── ketchup/ ← Add ketchup stain images
├── chocolate/ ← Add chocolate stain images
├── dirt/ ← Add dirt/mud stain images
├── grass/ ← Add grass stain images
├── coffee/ ← Add coffee/tea stain images
├── wine/ ← Add wine stain images
├── ink/ ← Add ink stain images
└── oil/ ← Add oil/grease stain images
Tip: Aim for at least 50-100 images per category for good results.
Windows:
cd model
train.batOr manually:
cd model
pip install -r requirements.txt
python train_model.pyThis will:
- ✅ Load and preprocess all images
- ✅ Train the CNN model using transfer learning (MobileNetV2)
- ✅ Save the model in Keras format
- ✅ Convert it to TensorFlow.js format for the web app
cd web-app
npm install
npm run devOpen http://localhost:5173 in your browser.
Machine Learning Manchas/
├── scraper/ # Image download tool
│ ├── scraper.py # Main scraper script
│ ├── download.bat # Windows launcher
│ ├── requirements.txt
│ └── README.md
│
├── model/ # ML model training
│ ├── data/ # Training images (organized by category)
│ │ ├── ketchup/
│ │ ├── chocolate/
│ │ ├── dirt/
│ │ ├── grass/
│ │ ├── coffee/
│ │ ├── wine/
│ │ ├── ink/
│ │ └── oil/
│ ├── saved_model/ # Trained Keras model (after training)
│ ├── train_model.py # Training script
│ ├── train.bat # Windows training launcher
│ ├── train.sh # Linux/Mac training launcher
│ └── requirements.txt # Python dependencies
│
├── web-app/ # React frontend
│ ├── public/
│ │ └── model/ # TensorFlow.js model (after training)
│ ├── src/
│ │ ├── components/
│ │ │ ├── ImageUploader.jsx # Drag & drop image upload
│ │ │ ├── ResultDisplay.jsx # Classification results
│ │ │ ├── CleaningTips.jsx # Cleaning recommendations
│ │ │ └── ModelStatus.jsx # Model loading status
│ │ ├── data/
│ │ │ └── cleaningTips.json # Cleaning tips database
│ │ ├── utils/
│ │ │ └── modelLoader.js # TensorFlow.js model loader
│ │ ├── App.jsx # Main application
│ │ ├── main.jsx # Entry point
│ │ └── index.css # Tailwind styles
│ ├── package.json
│ ├── vite.config.js
│ ├── tailwind.config.js
│ └── postcss.config.js
│
└── README.md
-
Transfer Learning: The model uses MobileNetV2 (pre-trained on ImageNet) as a base, then adds custom layers for stain classification. This allows good accuracy even with limited training data.
-
Data Augmentation: Training images are automatically augmented (rotated, flipped, zoomed) to improve model robustness.
-
Browser-based Inference: The trained model is converted to TensorFlow.js format, allowing classification to run entirely in the browser - no server required!
-
Privacy: Images never leave your device - all processing happens locally in the browser.
-
Create a new folder in
model/data/with the stain name:model/data/blood/ -
Add training images to the folder (50+ recommended)
-
Add cleaning tips in
web-app/src/data/cleaningTips.json:"blood": { "name": "Blood", "icon": "🩸", "color": "#991b1b", "description": "Blood stains from cuts or injuries", "tips": [...], "products": [...], "warnings": [...] }
-
Re-train the model:
cd model python train_model.py
| Component | Technology |
|---|---|
| Model Training | Python, TensorFlow/Keras, MobileNetV2 |
| Web Framework | React 18, Vite |
| ML in Browser | TensorFlow.js |
| Styling | Tailwind CSS |
| Image Upload | react-dropzone |
After training, you'll see metrics like:
- Training Accuracy: How well the model learns from training data
- Validation Accuracy: How well it generalizes to new images
A good model should have validation accuracy > 80%. If accuracy is low:
- Add more training images
- Ensure images are clear and well-lit
- Check that images are correctly categorized
- Make sure you've trained the model first (
python train_model.py) - Check that files exist in
web-app/public/model/
- Add more training images (100+ per category recommended)
- Ensure good image quality and variety
- Check for mislabeled images
- This is normal for first run (downloading MobileNetV2)
- Consider using a GPU for faster training
- Reduce
epochsintrain_model.pyfor quick testing
MIT License - feel free to use and modify for your projects!