Authors: Andrew Catoiu, RJ Livelo
Goal
In this project, we gathered images of faces. Some were of our own, and the rest were of random faces on the internet. Our goal is to authenticate device users my detecting their face on the computer webcam using Roboflow and OpenCV.
Roboflow
We trained a Roboflow model using various images as our dataset. First, create a new project inside of a Roboflow workspace. Next, upload a folder of images to the working dataset. You can test this on your own by downloading the ./faces in our repository. Since we are doing facial recognition to authenticate a specific user, we will annotate the images of the user's face by labeling with their name. The non-user face images can be labeled as "Other", "Unauthorized", etc. So if the valid user of our program is RJ, the images of RJ's face should be labeled with his name. Additionally, if we want Andrew to be another valid user, then we would label his images by his name as well.
Train the model and wait 10-15 minutes for the email confirmation. After receiving the email, navigate to the "Hosted Image Inference" deployment wihtin the "Deployments" tab. Here, you obtain your API key (in the code snippet) and the project name (example: 'test-z8tjn') in the model dropdown menu.
YOLOv8
After training, we obtained the deployment information (API key, version number, and project name) so that we can pass them as function arguments into the online YOLOv8 colab notebook:
https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov8-object-detection-on-custom-dataset.ipynb#scrollTo=BSd93ZJzZZKt
Follow instructions and run all the commands in the colab notebook to download a trained model of the images. When you get to "Step 5: Exporting dataset", make sure to pass the deployment information you obtained into the functions into the kernel. After running all commands, locate the custom model file in the {HOME}/runs/detect/train/weights path within the colab file manager. The model file name should be weights/best.pt, you can now download that file to your local machine.
OpenCV
Copy the path to the custom model file that you downloaded. Open test.py. To initialize our custom model to our program, pass the path of the file as a YOLO function argument.
Roboflow:
pip install roboflow
OpenCV:
pip install opencv-python
Ultralytics:
pip install ultralytics
To test our object detection program, run the following in the correct directory:
python test.pyYou can press q to quit the program.
Your final output will be a computer webcam detecting desired objects from the model. In this case, we are detecting faces. If Andrew is present in front of the webcam, there will be a green box surrounding his face. He will have to remain still for a fixed amount of time to verify that it is indeed the correct face (or authorized, valid, etc). The class name label associated with any trained images of Andrew will be displayed as well. If it is another user (not Andrew, or even RJ) then the user's face will be surrounded by a red box and will be "Unauthorized".