A FastAPI-based web application for uploading images, labeling them, and training a local Convolutional Neural Network (CNN) for image classification. Features include automatic label creation from uploaded images, database integration with MySQL, and a React frontend for seamless image uploads and predictions.
- Image Upload & Labeling: Drag-and-drop interface with automatic or manual labeling
- CNN Model Training: Train custom image classification models locally with real-time progress
- Smart Predictions: Test models with confidence scores and similarity matching
- Image Carousel Viewer: Browse training images with single/multi-image modal display
- Advanced Search & Filtering: Search models by name, path, classes, or status
- Authentication System: User login/signup with profile management and avatar support
- Interactive Documentation: Built-in API documentation with responsive sidebar navigation
- Real-time Status: Live training progress tracking with polling updates
- Toast Notifications: Comprehensive feedback system with close controls
- Responsive Design: Mobile-friendly interface with skeleton loading states
- Modular Backend: Clean separation of concerns with services and routes
- Database Integration: MySQL with trained/uploaded data management
- RESTful API: FastAPI with automatic OpenAPI documentation
- Modern Frontend: React 19 with TypeScript, Tailwind CSS, and Framer Motion
local-vision-ml-image-classifier/
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI/CD
βββ backend/
β βββ app/
β β βββ __init__.py
β β βββ main.py # FastAPI app setup (22 lines)
β β βββ config.py # Centralized configuration
β β βββ db.py # Database operations
β β βββ predict.py # Model prediction logic
β β βββ image_matcher.py # Image matching system
β β βββ services/ # Business logic layer
β β β βββ __init__.py
β β β βββ file_service.py # File handling operations
β β β βββ training_service.py # ML training logic
β β βββ routes/ # API endpoint modules
β β βββ __init__.py
β β βββ upload_routes.py # Image upload endpoints
β β βββ prediction_routes.py # Inference endpoints
β β βββ training_routes.py # Training management
β β βββ data_routes.py # Data retrieval endpoints
β βββ dataset/
β β βββ train/ # Training images directory
β βββ model/ # Trained models storage
β βββ uploads/ # Temporary uploads
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend Docker configuration
β βββ .env # Environment variables
β βββ .gitignore
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ UploadForm.tsx # Image upload with preview
β β β βββ PredictForm.tsx # Model testing component
β β β βββ ModelsList.tsx # Advanced model management
β β β βββ Navbar.tsx # Navigation component
β β β βββ LoginForm.tsx # User authentication
β β β βββ SignupForm.tsx # User registration
β β β βββ UserAvatar.tsx # Profile dropdown
β β β βββ ProfilePage.tsx # User profile management
β β β βββ SettingsPage.tsx # Application settings
β β β βββ SkeletonLoader.tsx # Loading states
β β βββ pages/
β β β βββ Home.tsx # Animated landing page
β β β βββ Documentation.tsx # API documentation
β β βββ utils/
β β β βββ toast.ts # Enhanced toast system
β β βββ App.tsx # Main React application
β β βββ main.tsx # React entry point
β βββ package.json # Node.js dependencies
β βββ tsconfig.json # TypeScript configuration
β βββ vite.config.ts # Vite configuration
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ Dockerfile # Frontend Docker configuration
β βββ .gitignore
βββ docker-compose.yml # Docker Compose configuration
βββ .prettierrc # Prettier configuration
βββ .editorconfig # Editor configuration
βββ trained_data_table.sql # Database schema
βββ README.md
- Python 3.8+
- Node.js 18+
- MySQL 8.0+
- Git
-
Clone the repository
git clone <repository-url> cd automation-microservice-image-recognition
-
Set up Python virtual environment
cd backend python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Python dependencies
pip install -r requirements.txt
-
Configure environment variables
cp .env.example .env # Edit .env with your database credentials -
Set up MySQL database
CREATE DATABASE image_recognition; -- Run the SQL commands from trained_data_table.sql
-
Start the FastAPI server
uvicorn app.main:app --reload --port 8001
-
Navigate to frontend directory
cd frontend -
Install Node.js dependencies
npm install
-
Start the development server
npm run dev
Create the required tables using the provided SQL schema:
-- Run the commands from trained_data_table.sql
CREATE TABLE images (
id INT AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL,
filepath VARCHAR(500) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE labels (
id INT AUTO_INCREMENT PRIMARY KEY,
image_id INT,
label VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE
);
-- Additional tables for trained data...-
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:8001
- Interactive Docs: http://localhost:8001/docs
-
User Authentication (Optional)
- Sign up or login with demo credentials:
user/user123 - Access profile settings and personalized experience
- Sign up or login with demo credentials:
-
Upload Training Images
- Navigate to Upload page or use "Start Classifying" button
- Drag and drop images or click to browse
- Add labels for your images (auto-generated from filename)
- Preview images before upload
-
Manage Training Data
- Go to Models page to view uploaded and trained data
- Click eye icon or image thumbnails to view full image carousel
- Use search and filters to find specific models
- Select labels for training with visual preview
-
Train Custom Models
- Click "Train New Model" and select desired labels
- Monitor real-time training progress with status updates
- View training completion notifications
-
Test & Predict
- Navigate to Predict page
- Upload test images with drag-and-drop
- View predictions with confidence scores
- See similar training images with similarity matching
- Documentation & API
- Access built-in documentation via "Read the Docs" button
- Browse comprehensive API reference with code examples
- Test endpoints directly from the interactive documentation
DB_HOST=localhost
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=image_recognitionPOST /upload- Upload training imagesPOST /predict- Make predictionsPOST /predict-with-match- Predict with training data matchingPOST /train- Start model trainingGET /models- List trained modelsGET /training-status- Get training progressGET /labels- Get available labelsGET /training-data- Get training dataset info
- 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
-
Database Connection Error
- Verify MySQL is running
- Check database credentials in .env file
- Ensure database exists
-
Model Training Fails
- Check if training images exist in dataset/train/
- Verify sufficient training data (minimum 2 images per class)
- Check Python dependencies are installed
-
Frontend Build Issues
- Clear node_modules and reinstall:
rm -rf node_modules && npm install - Check Node.js version compatibility
- Clear node_modules and reinstall:
# Clone and start all services
git clone <repository-url>
cd automation-microservice-image-recognition
docker-compose up --build# Backend only
docker-compose up backend mysql
# Frontend only
docker-compose up frontend- Framework: FastAPI with modular route structure
- Language: Python 3.8+ with type hints
- ML Framework: TensorFlow 2.x / Keras for CNN training
- Database: MySQL 8.0+ with connection pooling
- Image Processing: PIL, OpenCV for preprocessing
- Architecture: Clean separation with services and routes
- Framework: React 19 with TypeScript 5.9+
- Styling: Tailwind CSS with custom components
- Build Tool: Vite for fast development
- Animations: Framer Motion for smooth transitions
- State Management: React hooks with localStorage persistence
- UI Components: Custom skeleton loaders and modals
- API Documentation: Swagger/OpenAPI with interactive docs
- Containerization: Docker with multi-stage builds
- Code Quality: Prettier, EditorConfig, TypeScript strict mode
- CI/CD: GitHub Actions for automated testing
- Authentication: JWT-based user management
- Real-time Updates: WebSocket-like polling for training status