{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:From c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\tf_keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n", "\n" ] } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "import os\n", "import shutil\n", "import tqdm\n", "from tqdm.auto import trange, tqdm\n", "import matplotlib.pyplot as plt\n", "from matplotlib import image\n", "\n", "import deepface\n", "from deepface import DeepFace\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [], "source": [ "models = ['VGG-Face', 'Facenet', 'Facenet512', 'openFace', 'DeepFace', 'DeepId', 'ArcFace', 'Dlib', 'SFace']\n", "backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']\n", "\n", "result = DeepFace.verify(\n", " img1_path = 'records/CYS-18-5884/1721675648162.jpg',\n", " img2_path = 'records/CYS-18-8479/1721675646498.jpg',\n", " model_name = models[1],\n", " distance_metric = 'cosine',\n", " enforce_detection = False,\n", " detector_backend = backends[0],\n", " align = False,\n", " threshold = .2\n", ")" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'verified': False,\n", " 'distance': 0.8278660258791868,\n", " 'threshold': 0.2,\n", " 'model': 'Facenet',\n", " 'detector_backend': 'opencv',\n", " 'similarity_metric': 'cosine',\n", " 'facial_areas': {'img1': {'x': 0,\n", " 'y': 0,\n", " 'w': 1459,\n", " 'h': 2210,\n", " 'left_eye': None,\n", " 'right_eye': None},\n", " 'img2': {'x': 0,\n", " 'y': 0,\n", " 'w': 1664,\n", " 'h': 2639,\n", " 'left_eye': None,\n", " 'right_eye': None}},\n", " 'time': 8.36}" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result" ] }, { "cell_type": "code", "execution_count": 186, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d13346d4bce04924a03b289d7ff4cd44", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/15 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c1b56cc2eaf447d4b6290aef07cae2cf", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/15 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mat_no = list()\n", "for i in tqdm(os.listdir(\"records\")):\n", " mat_no.append(\"/\".join(i.split(\"-\")))\n", "\n", "\n", "img_path = list()\n", "for i in tqdm(os.listdir(\"records\")):\n", " record_ = f\"records/{i}\"\n", " rec_ = list()\n", " for n, j in enumerate((os.listdir(record_))):\n", " rec_.append(f\"records/{i}/{j}\")\n", " img_path.append(\" \".join(rec_)) " ] }, { "cell_type": "code", "execution_count": 187, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(15, 15)" ] }, "execution_count": 187, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(img_path), len(mat_no)" ] }, { "cell_type": "code", "execution_count": 188, "metadata": {}, "outputs": [], "source": [ "records_df = pd.DataFrame(\n", " data = {\n", " \"matric number\": mat_no,\n", " \"img paths\": img_path\n", " }\n", ")\n", "records_df.head()\n", "records_df.to_csv(\"records.csv\", index=0)" ] }, { "cell_type": "code", "execution_count": 189, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matric number found in Database\n" ] } ], "source": [ "# simple python workflow\n", "\n", "mat_no_ = input(\"Input Matric No here(DEPT/YY/NNNN).....\")\n", "student_name = input(\"Input your name here.......\")\n", "\n", "df = pd.read_csv(\"records.csv\")\n", "mat_nos = [i for i in df[\"matric number\"].values]\n", "\n", "if mat_no_ in mat_nos:\n", " print(\"Matric number found in Database\")\n", " verified = True\n", "else:\n", " print(\"Student matric number not found in database\")\n", " verified = False" ] }, { "cell_type": "code", "execution_count": 190, "metadata": {}, "outputs": [], "source": [ "if verified:\n", " df_sort = df[df[\"matric number\"] == mat_no_]" ] }, { "cell_type": "code", "execution_count": 191, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | matric number | \n", "img paths | \n", "
|---|---|---|
| 0 | \n", "CYS/18/5874 | \n", "records/CYS-18-5874/1721676589154.jpg records/... | \n", "