Skip to content

AI-powered πŸ“Έ Smart Attendance System with 99%+ 🎯 face recognition πŸ€–, real-time processing ⚑, and automated CSV πŸ“Š reporting.

License

Notifications You must be signed in to change notification settings

sourcecodeRTX/Smart_Attendance_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Attendance System with InsightFace

πŸ”₯ Features

  • Professional Grade Accuracy: 99%+ face recognition using InsightFace technology
  • Dual Recognition System: InsightFace (primary) with OpenCV fallback
  • Student Registration: Upload student photos with name and roll number
  • Advanced Face Embeddings: 512-dimensional face embeddings for superior accuracy
  • Group Photo Processing: Upload classroom photos to mark attendance for multiple students
  • Confidence Scoring: Real-time confidence scores for each recognition
  • Automated Attendance: AI-powered face detection and matching with timestamps
  • CSV Reports: Download detailed attendance records with confidence scores
  • Responsive Web Interface: Bootstrap-powered modern UI
  • Real-time Processing: Instant results with detailed feedback

πŸ“‚ Project Structure

Smart_Attendance_System/
β”œβ”€β”€ app.py                          # Main Flask application with InsightFace
β”œβ”€β”€ requirements.txt                # Essential Python dependencies
β”œβ”€β”€ README.md                       # Complete project documentation
β”œβ”€β”€ templates/                      # HTML templates
β”‚   β”œβ”€β”€ base.html                   # Base template with navigation
β”‚   β”œβ”€β”€ index.html                  # Homepage with system status
β”‚   β”œβ”€β”€ register.html               # Student registration page
β”‚   β”œβ”€β”€ attendance.html             # Attendance marking page
β”‚   β”œβ”€β”€ attendance_result.html      # Results with confidence scores
β”‚   β”œβ”€β”€ students.html               # Registered students database
β”‚   β”œβ”€β”€ records.html                # Attendance records list
β”‚   └── view_attendance.html        # Individual record viewer
β”œβ”€β”€ static/                         # Static files
β”‚   └── uploads/                    # Uploaded photos storage
β”œβ”€β”€ database/                       # Face data storage
β”‚   β”œβ”€β”€ face_embeddings_insightface.pkl  # InsightFace embeddings
β”‚   └── face_data_opencv.pkl             # OpenCV fallback data
└── attendance/                     # CSV attendance files
    └── attendance_YYYY-MM-DD.csv   # Daily attendance records

οΏ½ Virtual Environment Setup (Recommended)

Using a virtual environment is highly recommended to avoid dependency conflicts and keep your system Python clean.

Option 1: Using venv (Built-in Python)

Windows:

# Create virtual environment
python -m venv attendance_env

# Activate virtual environment
attendance_env\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

# Deactivate when done
deactivate

macOS/Linux:

# Create virtual environment
python3 -m venv attendance_env

# Activate virtual environment
source attendance_env/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

# Deactivate when done
deactivate

Option 2: Using conda (If you have Anaconda/Miniconda)

# Create conda environment
conda create -n attendance_env python=3.9

# Activate environment
conda activate attendance_env

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

# Deactivate when done
conda deactivate

Option 3: Using virtualenv (Third-party)

# Install virtualenv if not already installed
pip install virtualenv

# Create virtual environment
virtualenv attendance_env

# Activate (Windows)
attendance_env\Scripts\activate

# Activate (macOS/Linux)
source attendance_env/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

# Deactivate when done
deactivate

πŸš€ Quick Start

1. Setup Virtual Environment (Recommended)

Follow the virtual environment setup instructions above, then continue with the steps below.

2. Install Dependencies

pip install -r requirements.txt

3. Run the Application

python app.py

4. Access the System

Open your browser and go to: http://localhost:5000

The system will automatically detect if InsightFace is available and display the recognition method being used.

5. First Time Setup

  • The application will automatically create necessary folders (static/uploads, database, attendance)
  • Register a few students first before trying to mark attendance
  • Test with good quality, well-lit photos for best results

🧰 Tech Stack

  • Backend: Python Flask
  • Primary Face Recognition: InsightFace (99%+ accuracy)
  • Fallback Recognition: OpenCV (60-70% accuracy)
  • Image Processing: OpenCV, Pillow
  • Data Handling: pandas, numpy
  • Frontend: HTML5, CSS3, Bootstrap 5
  • Storage: Pickle files, CSV exports
  • AI Models: ONNX Runtime for InsightFace

πŸ“– How to Use

Step 1: Register Students

  1. Navigate to Register Student page
  2. Enter student name and roll number
  3. Upload a clear, front-facing photo (JPG, JPEG, PNG)
  4. Click Register Student
  5. System generates face embeddings automatically
  6. Success message shows which recognition method was used

Step 2: Mark Attendance

  1. Go to Mark Attendance page
  2. Upload a group photo containing students
  3. Click Process Attendance
  4. System detects all faces and matches with registered students
  5. View detailed results with confidence scores
  6. Download CSV report with attendance data

Step 3: View Records & Analytics

  1. Visit Records page to see all attendance files
  2. Click View for detailed attendance reports
  3. Click Download to get CSV files
  4. Check Students page to see registered database

πŸ”§ API Endpoints

Route Method Description
/ GET Homepage with system status
/register GET, POST Student registration with photo upload
/attendance GET, POST Mark attendance from group photos
/students GET View all registered students
/records GET View all attendance records
/view_attendance/<filename> GET View specific attendance record
/download/<filename> GET Download CSV attendance file
/status GET JSON API for system status

πŸ“Š Face Recognition Technology

InsightFace (Primary Method - 99%+ Accuracy)

  • Model: Professional-grade deep learning model
  • Embeddings: 512-dimensional face vectors
  • Detection: Advanced face detection with bounding boxes
  • Matching: Cosine similarity with confidence scoring
  • Multi-face: Detects and processes multiple faces simultaneously
  • Threshold: 0.5 similarity threshold (adjustable)

OpenCV (Fallback Method - 60-70% Accuracy)

  • Model: Haar Cascade classifier
  • Detection: Basic face detection
  • Matching: Template matching with correlation
  • Threshold: 0.6 correlation threshold
  • Usage: Automatic fallback when InsightFace unavailable

Recognition Process

  1. Registration: Extract face embeddings from student photos
  2. Storage: Save embeddings with student information
  3. Detection: Find all faces in group photos
  4. Matching: Compare detected faces with stored embeddings
  5. Scoring: Calculate confidence scores for matches
  6. Reporting: Generate attendance with timestamps and confidence

🎯 Configuration

File Upload Settings

  • Max file size: 16MB
  • Allowed formats: JPG, JPEG, PNG
  • Storage location: static/uploads/
  • Naming: Secure filename handling

Recognition Settings

  • InsightFace threshold: 0.5 (cosine similarity)
  • OpenCV threshold: 0.6 (template matching)
  • Detection size: 640x640 pixels
  • Provider: CPU execution (configurable for GPU)

πŸ“ Data Storage

InsightFace Embeddings (database/face_embeddings_insightface.pkl)

{
    'embeddings': [array1, array2, ...],    # 512-d face vectors
    'names': ['Student1', 'Student2', ...], # Student names
    'roll_numbers': ['001', '002', ...]     # Roll numbers
}

Attendance CSV Format (with Confidence Scores)

Roll_Number,Name,Date,Time,Status,Confidence
001,John Doe,2025-08-02,14:30:25,Present,0.87
002,Jane Smith,2025-08-02,14:30:25,Absent,N/A
003,Bob Wilson,2025-08-02,14:30:25,Present,0.92

πŸ›‘οΈ Security & Reliability Features

  • File type validation: Only allows image files
  • File size limits: Prevents large file uploads
  • Secure filename handling: Prevents path traversal attacks
  • Input sanitization: Validates all form inputs
  • Error handling: Comprehensive exception handling
  • Automatic fallback: Switches to OpenCV if InsightFace fails
  • Data integrity: Validates data before processing

🎨 User Interface Features

  • System Status: Shows which recognition method is active
  • Confidence Display: Real-time confidence scores for matches
  • Progress Feedback: Loading states and processing indicators
  • Flash Messages: Success/error notifications with details
  • Image Previews: Photo preview before upload
  • Responsive Design: Works on desktop, tablet, mobile
  • Modern UI: Bootstrap 5 components and styling

πŸ” Best Practices for Optimal Results

Photo Guidelines for Registration

  • Lighting: Well-lit environment, avoid shadows
  • Angle: Direct front-facing pose
  • Distance: 3-6 feet from camera
  • Background: Plain, uncluttered background
  • Expression: Neutral expression, eyes open
  • Quality: High resolution, sharp focus
  • Single Person: One person per registration photo

Group Photo Guidelines for Attendance

  • Multiple Faces: System handles multiple students
  • Classroom Setup: Works with typical classroom arrangements
  • Image Quality: Higher quality = better recognition
  • Stability: Avoid camera shake and blur
  • Lighting: Ensure all faces are well-lit
  • Size: Faces should be clearly visible (not too small)

🚨 Troubleshooting

Installation Issues

# If InsightFace installation fails
pip install --upgrade pip setuptools wheel
pip install insightface onnxruntime

# For Windows users
pip install insightface onnxruntime-win

# For macOS users
pip install insightface onnxruntime-macos

Common Issues & Solutions

  1. "InsightFace not available": Install with pip install insightface onnxruntime
  2. "No face detected": Check photo quality, lighting, and angle
  3. "Recognition failed": Ensure student is registered first
  4. "File too large": Compress image or reduce file size
  5. "Low confidence scores": Improve photo quality and lighting
  6. "Module not found": Run pip install -r requirements.txt

Performance Optimization

  • Photo Size: Use images under 5MB for faster processing
  • Registration Quality: High-quality registration photos improve accuracy
  • Group Photos: Ensure good lighting for all faces
  • Memory: Restart application if memory usage is high
  • GPU: Configure ONNX Runtime for GPU acceleration if available

πŸ“ˆ System Status & Monitoring

Check System Status

Visit /status endpoint or homepage to see:

  • InsightFace availability
  • Recognition method in use
  • Expected accuracy level
  • System configuration

Performance Metrics

  • InsightFace: 99%+ accuracy, confidence scoring
  • OpenCV Fallback: 60-70% accuracy, basic detection
  • Processing Speed: ~1-3 seconds per group photo
  • Scalability: Handles 50+ students efficiently

πŸ”§ Advanced Configuration

Adjusting Recognition Thresholds

# In app.py, modify these values:
INSIGHTFACE_THRESHOLD = 0.5  # Higher = stricter matching
OPENCV_THRESHOLD = 0.6       # Higher = stricter matching

GPU Acceleration (Optional)

# Modify in app.py for GPU support:
face_app = FaceAnalysis(providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])

πŸ“„ License

This project is open source and available under the MIT License.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Make your changes with proper testing
  4. Commit changes (git commit -am 'Add new feature')
  5. Push to branch (git push origin feature/improvement)
  6. Create a Pull Request

πŸ“ž Support & Contact

For technical support:

  • Check the troubleshooting section above
  • Review code comments in app.py
  • Test with the /status endpoint
  • Ensure all dependencies are properly installed

Smart Attendance System with InsightFace - Professional-grade automated attendance tracking using state-of-the-art AI face recognition technology. Built with Flask and modern web technologies for educational institutions requiring high accuracy and reliability.

About

AI-powered πŸ“Έ Smart Attendance System with 99%+ 🎯 face recognition πŸ€–, real-time processing ⚑, and automated CSV πŸ“Š reporting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published