This project is a YOLO (You Only Look Once) object detection system built using FastAPI. It provides real-time predictions and visualizations, leveraging the YOLO model for detecting specific activities or objects. This project is developed for a final-year academic project.
- Object Detection: Predict objects in uploaded images using a custom YOLO model (
best5.pt
). - Custom Trained Classes: Detects the following classes:
- Drinking
- Eating
- Violence
- Sleeping
- Smoking
- Walking
- Weapon
- Real-Time Prediction API: Upload images and get annotated predictions with bounding boxes and confidence scores.
- Database Storage: Stores prediction results (class name, accuracy, and timestamp) in a database.
- Data Visualization: View class-wise prediction counts in a bar chart.
- Backend Framework: FastAPI
- Model: YOLO (Ultralytics)
- Database: SQLAlchemy with SQLite
- Frontend: Jinja2 Templates, HTML, CSS, JavaScript (Bootstrap, Chart.js)
- Python 3.8+ installed.
- Install dependencies using the
requirements.txt
file.
-
Clone the repository:
git clone https://github.com/alihassanml/Yolo-Final-Year-Project.git cd Yolo-Final-Year-Project
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Linux/Mac venv\Scripts\activate # On Windows
-
Install dependencies:
pip install -r requirements.txt
-
Start the FastAPI server:
uvicorn app:app --reload
-
Open your browser and navigate to:
http://127.0.0.1:8000
-
Use the web interface to upload images and view predictions.
-
GET /
Returns the homepage. -
POST /predict
Upload an image and receive predictions with annotated bounding boxes. -
GET /predictions
Retrieve a list of all predictions stored in the database. -
GET /class-counts
Get class-wise counts of predictions for visualization.
Yolo-Final-Year-Project/
│
├── app.py # Main FastAPI application
├── model/
│ ├── best5.pt # YOLO pre-trained model weights
│ └── __init__.py # Package initialization
│
├── database.py # Database configuration
├── model.py # SQLAlchemy models
├── static/
│ ├── style.css # CSS for styling
│ ├── script.js # JavaScript functionality
│ └── uploads/ # Uploaded images folder
│
├── templates/
│ └── index.html # Jinja2 template for the frontend
│
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── .gitignore # Files to ignore in the repository
- Add video-based detection for live streams.
- Integrate a user authentication system for secure access.
- Expand the model to detect additional classes.
- Include export functionality for predictions (e.g., CSV or Excel).
This project is licensed under the MIT License. See the LICENSE file for details.
Developed by Ali Hassan. For questions or feedback, feel free to reach out.
---
### `requirements.txt`
```plaintext
fastapi==0.95.2
uvicorn==0.23.0
sqlalchemy==2.0.21
jinja2==3.1.2
pydantic==2.0.3
opencv-python==4.8.0.74
numpy==1.24.3
ultralytics==8.0.30
Pillow==9.5.0
chart.js==3.9.1
- Save the
README.md
andrequirements.txt
in the root directory of your project. - Commit and push the changes to your GitHub repository:
git add README.md requirements.txt git commit -m "Added README and requirements.txt for FastAPI-based YOLO project" git push origin main