The largest portion of the code in this repository originates from a project that was part of the 2023 edition of the "Deep Learning Lab" at the Computer Vision Chair [1] (Computer Science Chair 13) at RWTH Aachen University.
This repository includes a training and especially an inference script, for the detection of motorcycles and motorcycle helmets, using a two-stage approach inspired by [2]. In each stage a YOLOv8 model [3] is applied, first to detect motorcycles, and then to detect heads that do or do not wear motorcycle helmets in each motorcycle patch. Furthermore, motorcycles are tracked through subsequent frames using a tracking algorithm adapted from [4]. This enables the per motorcycle detection of traffic rule violations, either due to a too large number of passengers, or because at least one of the passengers does not wear a helmet. This project was motivated by the idea of constructing a system to improve traffic safety in regions were motorcycles are an especially prominent form of transportation.
Inference:
- Place trained models into src/inference/stage1 and src/inference/stage2 respectively, and data into the data directory.
- Consider src/inference/inference_config.py for the different modes, sources, image sizes, etc.
- run 'python3 src/inference/inference.py'
Training yolo models: run 'python3 src/train/yolov8.py'
![no_helmet](https://private-user-images.githubusercontent.com/95368554/326562343-0ff7c305-d82e-41f9-9059-4c4d0f19a2bb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxMDYzNzUsIm5iZiI6MTcyNDEwNjA3NSwicGF0aCI6Ii85NTM2ODU1NC8zMjY1NjIzNDMtMGZmN2MzMDUtZDgyZS00MWY5LTkwNTktNGM0ZDBmMTlhMmJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDIyMjExNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg5YTc0NDkxODg5M2E3MmFmNTE2ZTQzMzAyODBlODkyODkzM2QyOWEzOGEwNGY3NDI1MjA1MDkxYmU5YjVmZDkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.pLiQ-RvQv-1N47BoGqYzIX_0_Hx3x4SVBlyetpIPWtM)
![helmet](https://private-user-images.githubusercontent.com/95368554/326562313-7ad24547-a751-4ca3-85ed-8d3732039b63.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxMDYzNzUsIm5iZiI6MTcyNDEwNjA3NSwicGF0aCI6Ii85NTM2ODU1NC8zMjY1NjIzMTMtN2FkMjQ1NDctYTc1MS00Y2EzLTg1ZWQtOGQzNzMyMDM5YjYzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDIyMjExNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVhNDYzMGUxYjk2Mzc3YmJmOTZjYmNmNDk1ZjRkMGRhZjI2YjVkOTVmZTVlMmM1NWExYzU2MzU2ODEyMDU1MzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2hxQfkz3R7neH2RN6UmZuqM6GeAD5aApZVx5yFyzFCI)
These Screenshots show the tracking mode, which indicates tracks and bounding boxes for the detected motorcycles, together with a label "violation" (with reason, e.g. H for no helmet) or "legal", depending on the number of detected passengers and helmets. Additionally, the currently achieved frames per second are displayed on the top right.
We thank Tristan Höfer and Syed Ayaz, with whom we worked on the Deep Learning Lab project, which this repository originates from.
[1] https://www.vision.rwth-aachen.de/
[2] Jia, W., Xu, S., Liang, Z., Zhao, Y., Min, H., Li, S., & Yu, Y. (2021). Real‐time automatic helmet detection of motorcyclists in urban traffic using improved YOLOv5 detector. IET Image Processing, 15(14), 3623-3637.
[3] Jocher, G., Chaurasia, A., & Qiu, J. (2023). Ultralytics YOLO (Version 8.0.0) [Computer software]. https://github.com/ultralytics/ultralytics
[4] Wojke, N., Bewley, A., & Paulus, D. (2017, September). Simple online and realtime tracking with a deep association metric. In 2017 IEEE international conference on image processing (ICIP) (pp. 3645-3649). IEEE.