Fix representations_<model>.pkl not being created

This commit is contained in:
slashtechno 2023-10-22 16:20:57 -05:00
parent 2cf945feec
commit 4f1f253c6c
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
6 changed files with 67 additions and 7 deletions

4
.gitignore vendored
View File

@ -2,9 +2,9 @@
config/ config/
using_yolov8.ipynb using_yolov8.ipynb
yolov8n.pt yolov8n.pt
.venv/ *venv/
__pycache__/ __pycache__/
faces/* faces/*
!faces/.gitkeep !faces/.gitkeep
dist/ dist/
draft-commit-message.txt test.txt

3
.vscode/launch.json vendored
View File

@ -10,7 +10,8 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"module": "wyzely_detect", "module": "wyzely_detect",
"justMyCode": true // "justMyCode": true
"justMyCode": false
} }
] ]
} }

View File

@ -49,7 +49,7 @@
" # We could use Path to get the parent directory of the image to use as the identity\n", " # We could use Path to get the parent directory of the image to use as the identity\n",
" print(f'Most likely identity: {Path(pd_dataframe.iloc[0][\"identity\"]).parent.name}')\n", " print(f'Most likely identity: {Path(pd_dataframe.iloc[0][\"identity\"]).parent.name}')\n",
" # Get the most likely identity's confidence\n", " # Get the most likely identity's confidence\n",
" print(f'Confidence: {pd_dataframe.iloc[0][\"model_name=\"ArcFace\", detector_backend=\"opencv\")\"]}')\n", " print(f'Confidence: {pd_dataframe.iloc[0][\"ArcFace_cosine\"]}')\n",
"\n", "\n",
"# uuid_path.unlink()" "# uuid_path.unlink()"
] ]
@ -69,6 +69,60 @@
"source": [ "source": [
"DeepFace.stream(db_path=\"faces\", model_name=\"ArcFace\", detector_backend=\"opencv\")" "DeepFace.stream(db_path=\"faces\", model_name=\"ArcFace\", detector_backend=\"opencv\")"
] ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Stream normal frame by frame"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from deepface import DeepFace\n",
"import cv2\n",
"from pathlib import Path\n",
"import uuid\n",
"import pandas as pd\n",
"\n",
"def main():\n",
" cap = cv2.VideoCapture(0)\n",
" while True:\n",
" ret, frame = cap.read()\n",
" dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=False, silent=False, model_name=\"ArcFace\", detector_backend=\"opencv\")\n",
" for i, pd_dataframe in enumerate(dfs):\n",
" print(f'On dataframe {i}')\n",
" print(pd_dataframe)\n",
" print(f'Most likely identity: {Path(pd_dataframe.iloc[0][\"identity\"]).parent.name}')\n",
" print(f'Confidence: {pd_dataframe.iloc[0][\"ArcFace_cosine\"]}')\n",
" cv2.imshow(\"frame\", frame)\n",
" if cv2.waitKey(1) & 0xFF == ord(\"q\"):\n",
" break\n",
" cap.release()\n",
" cv2.destroyAllWindows()\n",
" \n",
"\n",
"\n",
"main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Other functions\n"
]
} }
], ],
"metadata": { "metadata": {

2
poetry.lock generated
View File

@ -3627,4 +3627,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = ">=3.10, <3.12" python-versions = ">=3.10, <3.12"
content-hash = "952e41ab099f9d1c7055465d5a3c228df677c422d20dea8ff8d558d2e4d8f2be" content-hash = "6712094a7e402c4587037939b7a33ad4c2463a545c222374bc471925c33242d9"

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "wyzely-detect" name = "wyzely-detect"
version = "0.1.0" version = "0.1.9"
description = "Recognize faces/objects in a video stream (from a webcam or a security camera) and send notifications to your devices" description = "Recognize faces/objects in a video stream (from a webcam or a security camera) and send notifications to your devices"
authors = ["slashtechno <77907286+slashtechno@users.noreply.github.com>"] authors = ["slashtechno <77907286+slashtechno@users.noreply.github.com>"]
license = "MIT" license = "MIT"
@ -29,6 +29,7 @@ tensorflow-io-gcs-filesystem = "0.31.0"
deepface = "^0.0.79" deepface = "^0.0.79"
tensorflow = "^2.14.0"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
black = "^23.9.1" black = "^23.9.1"

View File

@ -115,8 +115,12 @@ def recognize_face(
face_dataframes = DeepFace.find( face_dataframes = DeepFace.find(
run_frame, run_frame,
db_path=str(path_to_directory), db_path=str(path_to_directory),
enforce_detection=True, # enforce_detection=True,
# Seems this works?
enforce_detection=False,
silent=True, silent=True,
# Could use VGG-Face, but whilst fixing another issue, ArcFace seemed to be slightly faster
# I read somewhere that opencv is the fastest (but not as accurate). Could be changed later, but opencv seems to work well
model_name="ArcFace", detector_backend="opencv" model_name="ArcFace", detector_backend="opencv"
) )
except ValueError as e: except ValueError as e: