-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository contains the implementation of Bike helmet detection using YOLOv8 using Django. This project contains django web application where end user can fill a form which contains image and video to be submited at the front-end or through API end point for prediction of the bike rider, helmet and no helmet. Validation is done on both front-end and API as a result only if both the fields are submited for prediction then only detection will be done else appropriate error message are displayed. Images and Videos that submited by end users are then ran inference on by YOLO model and displayed on index page which is same page. For sending valid data via API, images and videos are processed and appropriate predicted image and videos with auto generated id is send back to end user.
Note
My mad I actually wanted to create a dev blog style wiki for this project. But, Apparently wiki for github does not work when the repository is in private mode
- Github actions workflow for test with tox.
- Unit testing test cases is done for testing modules.
- API is ceated using django-rest-framework.
- API documentation is created using markdown.
- coverage report is generated.
- For sorting imports isort is used.
- For code formating / linting black is used.
- For static type checking mypy is used (optional).
- Respective validations are done to the fields.
- Containerized with docker.
- kubernetes.yaml file to test with kubernetes in docker and minikube.
- Front end :- HTML, CSS, Bootstrap
- Backend :- Python (Django, DRF)
- Database :- Sqlite (Default)
# This are the major packages for this project
Django==5.0.1 # For Django web application development
ultralytics==8.1.9 # For running inference on YOLOv8 model and getting results.
pillow==10.2.0 # For images and videos files
# Test Coverage
coverage==7.4.3 # For generating test coverage report
# Django-rest Framework
django-filter==23.5 # Simple way to filter down a queryset based on parameters of user
djangorestframework==3.14.0 # For API development
Markdown==3.5.2 # pip install markdown # For API documentation
# Re-Structing the codebase
isort==5.13.2 # For sorting imports
black==24.3.0 # For python code formatting / linting
tox==4.14.2 # To run tests on different OS and python environments
mypy==1.9.0 # Static type checker (optional)
Bike-Helmet-Detection
βββ .git # Git file to version control
βββ .github # Github file for workflows
βΒ Β βββ ISSUE_TEMPLATE # Github issue template
βΒ Β βΒ Β βββ bug_report.yml # bug report issue form template
βΒ Β βΒ Β βββ config.yml # issue config
βΒ Β βΒ Β βββ feature_request.yml # feature request form template
βΒ Β βΒ Β βββ pull_request_template.md # custom PR template
βΒ Β βββ workflows # Github workflow to run after a PR
βΒ Β βΒ βββ main.yml
| βββΒ dependabot.yml # Github dependencies bot to check of any security issue
βββ .gitignore # Gitignore file to ignore any unncessary files by git
βββ ml_project # Django project file
βΒ Β βββ compose.yaml # Docker compose file to manage docker containers
βΒ Β βββ Dockerfile # Docker file to create a image and run using docker compose or docker build
βΒ Β βββ kubernetes.yaml # Kubernetes configuration file for kubernetes, minikube
βΒ Β βββ README.Docker.md # Docker md file
βΒ βββ .dockerignore # Docker ignore file to ignore any unnecessary files by docker
βΒ Β βββ .coverage # Hidden coverage file
βΒ Β βββ .coveragerc # Coverage configuration file to work on local
β βββ db.sqlite3 # Default database for django
β βββ deployment_req.txt # Deployment requirements for docker and any other platform
β βββ htmlcov # Generated by coverage "coverage html" command open index.html to see coverage
β βββ major_packages.txt # Major packages needed for project
β βββ manage.py # Django's command-line utility for administrative tasks
β βββ media # Media static files for django for images or videos
β β βββ images
β β β βββ bike_rider_JlJpRzO.jpg
β β β βββ bike_rider.jpg
β β β βββ BikesHelmets118.png
β β β βββ BikesHelmets8.png
β β β βββ test_image.jpg
β β βββ pred_images
β β β βββ bike_rider_0XTlKgp.jpg
β β β βββ bike_rider.jpg
β β β βββ BikesHelmets118.png
β β β βββtest_pred_image.jpg
β β βββ pred_videos
β β β βββ he2_1CjSKgu.avi
β β β βββ he2.avi
β β β βββ test_pred_image.mp4
β β β βββ test_pred_image_yiShPOt.mp4
β β βββ videos
β β βββ he2_M76GncE.mp4
β β βββ he2.mp4
β β βββ test_video_0BeuZlt.mp4
β β βββ test_video.mp4
β β βββtest_video_MqdGYhL.mp4
β βββ ml_app # Dajngo web app for this project
β β βββ admin.py # Django admin utility
β β βββ apps.py # Django app utility
β β βββ assets # Assets for testing ml_app in UI and API
β β β βββ Images
β β β β βββ bike_rider.jpg
β β β β βββ BikesHelmets64.png
β β β β βββ BikesHelmets66.png
β β β β βββ BikesHelmets6.png
β β β βββ Videos
β β β βββ he2.mp4
β β β βββ test_1.mp4
β β β βββ test_2.mp4
β β βββ credentials.py # My root username and password
β β βββ forms.py # Django form utility for rendering UI forms
β β βββ __init__.py
βΒ Β βΒ Β βββ .isort.cfg # Isort configuration file
β β βββ migrations # Generated by makemigrations and migrate command for DB
β β β βββ 0001_initial.py
β β βββ models.py # Database models
β β βββ pyproject.toml # Configuration for running tox, mypy
β β βββ serializers.py # DRF utility for serilization and deserlization
β β βββ standalone_api_test.py # Standalone test for api
β β βββ static # static files for webapp
β β β βββ ml_app
β β β βββ style.css # Custom css file
β β βββ templates
β β β βββ ml_app
β β β βββ index.html # Custom html file
β β βββ tests # Testcases packages for ml_app
β β β βββ __init__.py
β β β βββ test_assets # Test images and videos for testcases
β β β β βββ test_images
β β β β β βββ bike_rider.jpg
β β β β β βββ BikesHelmets64.png
β β β β β βββ BikesHelmets66.png
β β β β β βββ BikesHelmets6.png
β β β β βββ test_videos
β β β β βββ he2.mp4
β β β β βββ test_1.mp4
β β β β βββ test_2.mp4
β β β βββ test_forms.py # Testcase for forms
β β β βββ test_model.py # Testcase for models.py file
β β β βββ test_urls.py # Testcase for urls.py
β β β βββ test_views.py # Testcase for views.py
βΒ Β βΒ Β βββ .tox
β β βββ urls.py # Django utility for URL routing
β β βββ utils.py # Custom function for YOLOv8 model inference
β β βββ views.py # Django utility backend logic for web_app and api
βΒ Β βΒ Β βββ web_cam.py # Python script to run on local webcam
β β βββ weights # Model weights of YOLOv8
β β βββ best.pt # Best model for YOLOv8
β β βββ information.txt
β β βββ last.pt # Last model for YOLOv8
β βββ ml_project
β β βββ asgi.py
β β βββ __init__.py
β β βββ settings.py # Django settings for ml_app
β β βββ urls.py # URL routing for ml_app and api
β β βββ wsgi.py
β βββ requirements.txt # pip install -r requirements.txt command for local development
β βββ runs # Generated by ultralytics yolov8 predictions
β βββ tox.ini # tox configurations
βββ tree_all.txt # All the file tree structure including hidden files using tree -a > tree_all.txt
βββ tree.txt # File tree structure excluding hidden files using command tree > tree.txt
βββ README.md # This file itself
USERNAME = "viddesh"
PASSWORD = "!@#$%^&*()_+"
python version :- 3.10.12 (local)
Docker version :- Docker version 25.0.3, build 4debf41
minikube version :- v1.32.0
kubectl Client version :- v1.29.2
- http://127.0.0.1:8000/ --> Run's Django webapp
- http://127.0.0.1:8000/admin/ --> Django admin panel
- http://127.0.0.1:8000/api/ --> Default router root view
- http://127.0.0.1:8000/api/images/ --> End user submitted image and video list api
- http://127.0.0.1:8000/api/predimages/ --> Predicted image and videos api
python3 -m venv .venv
source .venv/bin/activate
git clone https://github.com/Viddesh1/Bike-Helmet-Detection.git
cd Bike-Helmet-Detection/
pip install -r requirements.txt
cd ml_project/
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver # web app will run on http://127.0.0.1:8000/
cd ml_project/
python3 manage.py test ml_app
cd ml_project/ml_app/
isort .
cd ml_project/ml_app/
black .
cd ml_project/
tox
OR
cd ml_project/ml_app/
tox
cd ml_project/
coverage run manage.py test ml_app
coverage report -m
coverage html # To generate html report
cd ml_project/
docker compose up
Make sure docker demon is running using docker-desktop and kubernetes is enable in docker desktop settings
cd ml_project/
kubectl config get-contexts
kubectl config use-context docker-desktop
kubectl apply -f kubernetes.yaml
kubectl get pods
cd ml_project/
kubectl config get-contexts
kubectl config use-context minikube
minikube start
minikube kubectl -- apply --filename my-deployment.yaml
minikube stop
Traffic_2.mp4



