Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from LimaoC/mitch-deepface-deps
Browse files Browse the repository at this point in the history
build,feat: added dependencies for deepface and test notebook
  • Loading branch information
MitchellJC authored Aug 24, 2024
2 parents a1c531e + 5fcddbd commit 1959cde
Show file tree
Hide file tree
Showing 3 changed files with 1,445 additions and 281 deletions.
183 changes: 183 additions & 0 deletions notebooks/explore-deepface.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[autoreload of cv2.gapi failed: Traceback (most recent call last):\n",
" File \"c:\\Users\\mitch\\miniconda3\\envs\\garden\\lib\\site-packages\\IPython\\extensions\\autoreload.py\", line 276, in check\n",
" superreload(m, reload, self.old_objects)\n",
" File \"c:\\Users\\mitch\\miniconda3\\envs\\garden\\lib\\site-packages\\IPython\\extensions\\autoreload.py\", line 475, in superreload\n",
" module = reload(module)\n",
" File \"c:\\Users\\mitch\\miniconda3\\envs\\garden\\lib\\importlib\\__init__.py\", line 169, in reload\n",
" _bootstrap._exec(spec, module)\n",
" File \"<frozen importlib._bootstrap>\", line 619, in _exec\n",
" File \"<frozen importlib._bootstrap_external>\", line 883, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 241, in _call_with_frames_removed\n",
" File \"c:\\Users\\mitch\\miniconda3\\envs\\garden\\lib\\site-packages\\cv2\\gapi\\__init__.py\", line 323, in <module>\n",
" cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline\n",
"AttributeError: module 'cv2.gapi' has no attribute 'wip'\n",
"]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'tensorflow'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mcv2\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mdeepface\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m DeepFace\n",
"File \u001b[1;32mc:\\Users\\mitch\\miniconda3\\envs\\garden\\lib\\site-packages\\deepface\\DeepFace.py:15\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m---> 15\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtensorflow\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mtf\u001b[39;00m\n\u001b[0;32m 17\u001b[0m \u001b[38;5;66;03m# package dependencies\u001b[39;00m\n\u001b[0;32m 18\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mdeepface\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcommons\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m package_utils, folder_utils\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'tensorflow'"
]
}
],
"source": [
"import cv2\n",
"from deepface import DeepFace"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"ENTER_ASCII = 13\n",
"\n",
"\n",
"def take_photo(photo_name):\n",
" capture = cv2.VideoCapture(0)\n",
" while True:\n",
" success, frame = capture.read()\n",
" if not success:\n",
" continue\n",
"\n",
" cv2.imshow(\"Camera Preview: Press enter to take photo\", frame)\n",
"\n",
" if cv2.waitKey(1) & 0xFF == ENTER_ASCII:\n",
" cv2.imwrite(photo_name, frame)\n",
"\n",
" break\n",
"\n",
" capture.release()\n",
" cv2.destroyAllWindows()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Take two photos. Press enter to confirm photo.\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"take_photo(\"photo1.png\")\n",
"take_photo(\"photo2.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Verify that photos are of same person.\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'verified': True,\n",
" 'distance': 0.21787509303712116,\n",
" 'threshold': 0.65,\n",
" 'model': 'GhostFaceNet',\n",
" 'detector_backend': 'opencv',\n",
" 'similarity_metric': 'cosine',\n",
" 'facial_areas': {'img1': {'x': 284,\n",
" 'y': 117,\n",
" 'w': 195,\n",
" 'h': 195,\n",
" 'left_eye': (422, 195),\n",
" 'right_eye': (346, 191)},\n",
" 'img2': {'x': 282,\n",
" 'y': 120,\n",
" 'w': 189,\n",
" 'h': 189,\n",
" 'left_eye': (421, 197),\n",
" 'right_eye': (346, 191)}},\n",
" 'time': 0.9}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"DeepFace.verify(\"photo1.png\", \"photo2.png\", model_name=\"GhostFaceNet\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "deco3801",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 1959cde

Please sign in to comment.