leap
Lifetime Exposures와 Asthma 결과 예측(LEAP) 모델용 파이썬 패키지
졸음 감지를 위해 OpenCV·TensorFlow 등으로 구현한 최종 학년 프로젝트
This is my final year project for machine learning subject where I have build a system that detects sleepyness of a person for a certain period of time using opencv, tensorflow, numpy and so on.
건강Python · JavaScriptGitHub @ApilCreate온라인운영자 미확인
써 보셨어요? 한 번만 눌러 주세요. 로그인은 필요 없어요.
아직 감지된 업데이트가 없습니다. GitHub 릴리스가 나오면 여기에 보입니다.
개인 계정의 공개 저장소 소유자는 GitHub로 로그인해 운영자를 확인하고 소개를 직접 관리할 수 있습니다. 관리자 승인은 필요하지 않습니다.
로그인한 뒤 확인 파일을 만들어 이 저장소의 기본 브랜치에 30분 안에 커밋해 주세요. 다른 브랜치나 포크의 파일은 인정하지 않습니다. 파일을 올린 뒤 아래에서 확인하면 관리자 승인 없이 관리할 수 있습니다. 자격을 유지하려면 파일을 남겨 두세요.
로그인이 필요하면 로그인 화면으로 이동합니다. 로그인 후 이곳으로 돌아와 원하는 확인 버튼을 다시 눌러 주세요.
프로젝트 폴더에서 /nomorevibe verify를 실행하면 소유권을 확인하고 소개를 직접 관리할 수 있습니다.
1분 만에 확인하기README 전체를 불러오는 중입니다. 아래는 저장된 발췌입니다.
A portfolio-ready eye-state monitor that turns a trained Keras CNN and eye geometry into a local, time-thresholded drowsiness alert.
Live demo: TODO: replace this link after deploying /web to Vercel.
TODO: add a real project screenshot or GIF under docs/ after capturing one. No demo image is included here because none has been verified.README 전문 보기 ↗A portfolio-ready eye-state monitor that turns a trained Keras CNN and eye geometry into a local, time-thresholded drowsiness alert.
Live demo: TODO: replace this link after deploying /web to Vercel.
TODO: add a real project screenshot or GIF under docs/ after capturing one. No demo image is included here because none has been verified.
This final-year machine-learning project classifies eye crops as open or closed and applies a continuous closure threshold before raising an alert. The model is a Keras CNN with 64x64x1 grayscale input, pixels scaled by /255, and class order 0 = Open, 1 = Closed as implemented in the training notebook.
The deployable version is the plain static site in web/. It requests the camera from the browser, localizes eyes with MediaPipe Face Landmarker, runs the converted TensorFlow.js model locally, plays an HTML audio alarm, and keeps session data in memory. It has no server writes and is suitable for Vercel with Root Directory = web, Framework Preset = Other, and no build command.
The original desktop workflow remains in app.py. Flask/OpenCV reads a camera attached to the local machine, Keras performs inference, Pygame plays the local alarm, and Matplotlib writes session outputs to static/charts/ and static/screenshots/.
flowchart LR
Camera --> Browser[web/: MediaPipe + TF.js]
Browser --> BrowserAlarm[HTMLAudioElement]
Browser --> Memory[In-memory report]
Camera --> Flask[app.py: local OpenCV]
Flask --> Keras[Keras CNN]
Flask --> Pygame[Pygame alarm]
Flask --> Files[static/charts + static/screenshots]
Vercel cannot run the old server-side design reliably: cloud functions have no user's camera, TensorFlow/OpenCV/Matplotlib exceed the function size budget, Pygame plays on the server rather than the user device, and global state is unsafe for stateless or multi-user functions. Vercel's filesystem is also not a durable place for generated charts or screenshots.
1.5s, adjustable from 0.5s to 3s.enumerateDevices, browser audio mute, reports, charts, and canvas screenshots.Evaluation uses a fixed, stratified 80/20 split (random_state=42) because the dataset has no separate test directory. The verified held-out results are:
| Metric | Value |
|---|---|
| Accuracy | 98.86% |
| Precision | 98.79% |
| Recall | 98.92% |
| F1 | 98.85% |
The corresponding confusion matrix is docs/confusion_matrix.png. Run:
python evaluate_model.py
This writes the reproducible values to docs/metrics.json and regenerates the confusion matrix. Training curves are not included because the original executed notebook did not preserve a complete serialised history artifact.
Low light, glasses/reflections, extreme head angles, and camera placement can reduce reliability. The Flask version uses a Haar eye cascade; it often fails to detect closed eyes, so a missing eye is deliberately recorded as unknown, not open, but this cannot recover the missed eye. The browser version improves localization with MediaPipe landmarks but is still a research prototype and not a certified safety device.
Drowsiness_Dataset/ contains 84,898 PNG images in Close_Eyes/ and Open_Eyes/, approximately 328 MB in this checkout. It is intentionally retained. TODO: add the verified dataset source, attribution, and license before redistribution. Git LFS is recommended for the dataset and model if the repository host's normal file limits are exceeded.
app.py Local Flask/OpenCV desktop version
drowsiness_model.h5 Trained Keras model
evaluate_model.py Reproducible held-out evaluation
train_model.ipynb Cleaned training/evidence notebook
convert_model.py Real Keras -> TF.js conversion script
web/ Static Vercel/browser implementation
static/alarm.wav Local and browser alarm source
static/charts/ Generated Flask charts (ignored)
static/screenshots/ Generated Flask screenshots (ignored)
docs/ Verified metrics and portfolio media (TODO)
Drowsiness_Dataset/ Retained local dataset
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python app.py
Open http://127.0.0.1:5000. Set DROWSINESS_THRESHOLD_SECONDS to change the default threshold, LOG_LEVEL for logging, and FLASK_DEBUG=1 only when debugging locally.
The converted browser model is checked in under web/model/. To reproduce the conversion, install tensorflowjs in a compatible environment and run python convert_model.py; on Windows with TensorFlow 2.19, use the isolated compatibility route documented in convert_model_colab.ipynb. Then serve the static directory (camera APIs require a secure context):
npx serve web
Open the printed URL, allow the camera, and click Start monitoring. Import the web/ folder into Vercel with no build command.
I researched dataset preparation, implemented and trained the CNN, debugged the local detection flow, and made the design decisions around preprocessing, timing, browser privacy, and dual signals. Assistance and code suggestions were used during development, but claims in this README are limited to behavior and evidence that can be inspected in this repository.
MIT. See LICENSE.