An AI-powered web application that classifies images as cats or dogs using TensorFlow.js
π Live Demo β’ π Documentation β’ π οΈ Installation β’ π€ Contributing
This project is a modern, responsive web application that uses machine learning to classify images of cats and dogs. Built as part of the freeCodeCamp Machine Learning curriculum, it demonstrates the power of client-side AI with TensorFlow.js, providing real-time image classification without sending data to external servers.
- π§ AI-Powered: Convolutional Neural Network for accurate image classification
- π Privacy-First: All processing happens locally in your browser
- β‘ Real-Time: Instant predictions with TensorFlow.js
- π¨ Modern UI: Beautiful, responsive design with dark/light mode
- π± Mobile-Friendly: Works seamlessly across all devices
- π Fast: Built with Vite for optimal performance
| Feature | Description |
|---|---|
| πΌοΈ Image Upload | Drag & drop or click to upload images (JPG, PNG, GIF) |
| π€ AI Classification | Real-time cat vs dog prediction with confidence scores |
| π Confidence Meter | Visual confidence indicator with color-coded results |
| π Dark Mode | Beautiful dark/light theme toggle with system preference detection |
| π± Responsive Design | Optimized for desktop, tablet, and mobile devices |
| β‘ Instant Results | Client-side processing for immediate feedback |
- Intuitive Interface: Clean, modern design inspired by industry leaders
- Smooth Animations: Subtle transitions and micro-interactions
- Accessibility: WCAG compliant with proper contrast ratios
- Performance: Optimized loading and rendering
- Error Handling: Graceful error messages and recovery
- TypeScript: Full type safety and better developer experience
- Component Architecture: Modular, reusable React components
- State Management: Efficient state handling with React hooks
- Theme System: Context-based theme management
- Build Optimization: Tree-shaking and code splitting with Vite
- Node.js (v16 or higher)
- npm or yarn
# Clone the repository
git clone https://github.com/AyushSingh360/cat-dog-classifier.git
# Navigate to project directory
cd cat-dog-classifier
# Install dependencies
npm install
# Start development server
npm run devThe application will be available at http://localhost:5173
# Create production build
npm run build
# Preview production build
npm run previewcat-dog-classifier/
βββ π public/ # Static assets
βββ π src/
β βββ π components/ # React components
β β βββ Header.tsx # Navigation header
β β βββ Footer.tsx # Footer component
β β βββ ImageUploader.tsx # Image upload interface
β β βββ PredictionResult.tsx # Results display
β β βββ ModelInfo.tsx # Model information
β β βββ ThemeToggle.tsx # Dark mode toggle
β βββ π contexts/ # React contexts
β β βββ ThemeContext.tsx # Theme management
β βββ π types/ # TypeScript definitions
β β βββ index.ts # Type definitions
β βββ π utils/ # Utility functions
β β βββ modelUtils.ts # ML model utilities
β βββ App.tsx # Main application
β βββ main.tsx # Application entry point
β βββ index.css # Global styles
βββ π package.json # Dependencies and scripts
βββ π tailwind.config.js # Tailwind configuration
βββ π tsconfig.json # TypeScript configuration
βββ π vite.config.ts # Vite configuration
βββ π README.md # This file
The model uses a Convolutional Neural Network (CNN) architecture optimized for binary image classification:
Input Layer (150x150x3)
β
Conv2D (32 filters, 3x3) + ReLU
β
MaxPooling2D (2x2)
β
Conv2D (64 filters, 3x3) + ReLU
β
MaxPooling2D (2x2)
β
Conv2D (128 filters, 3x3) + ReLU
β
MaxPooling2D (2x2)
β
Flatten
β
Dense (512 units) + ReLU
β
Dense (1 unit) + Sigmoid
- Dataset: Microsoft Cats vs Dogs dataset
- Training Images: 20,000+ images with data augmentation
- Validation Accuracy: >90%
- Optimizer: Adam
- Loss Function: Binary Crossentropy
- Data Augmentation: Rotation, shifting, shearing, zooming, flipping
| Metric | Value |
|---|---|
| Accuracy | >90% |
| Precision | ~89% |
| Recall | ~91% |
| F1-Score | ~90% |
| Inference Time | <100ms |
| Theme | Primary | Secondary | Accent | Background |
|---|---|---|---|---|
| Light | #667eea |
#764ba2 |
#f59e0b |
#f8fafc |
| Dark | #667eea |
#764ba2 |
#f59e0b |
#0f172a |
- Font Family: Inter, system fonts
- Headings: 600-700 weight
- Body: 400-500 weight
- Line Height: 1.5 (body), 1.2 (headings)
Based on 8px grid system: 4px, 8px, 16px, 24px, 32px, 48px, 64px
| Technology | Version | Purpose |
|---|---|---|
| React | 18.2.0 | UI framework |
| TypeScript | 5.0.2 | Type safety |
| Vite | 4.4.5 | Build tool |
| Tailwind CSS | 3.3.3 | Styling |
| Technology | Version | Purpose |
|---|---|---|
| TensorFlow.js | 4.15.0 | ML inference |
| Canvas API | Native | Image preprocessing |
| Tool | Purpose |
|---|---|
| ESLint | Code linting |
| PostCSS | CSS processing |
| Autoprefixer | CSS vendor prefixes |
| Metric | Score |
|---|---|
| Performance | 95+ |
| Accessibility | 100 |
| Best Practices | 100 |
| SEO | 100 |
- Initial Bundle: ~500KB (gzipped)
- TensorFlow.js: ~400KB (cached)
- Application Code: ~100KB (gzipped)
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Use TypeScript for all new code
- Follow ESLint configuration
- Use Prettier for formatting
- Write meaningful commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- freeCodeCamp - For the excellent Machine Learning curriculum
- Microsoft - For the Cats vs Dogs dataset
- TensorFlow Team - For TensorFlow.js
- Pexels - For beautiful stock photos
- Lucide - For the icon library
Your Name - [@Ayush SIngh] - ayushsingh21109@gmail.com
Project Link: https://github.com/AyushSingh360/cat-dog-classifier
β Star this repository if you found it helpful!
Made with β€οΈ for the freeCodeCamp community
