Create Deepface Jupyter Notebook
This commit is contained in:
parent
556a90da3c
commit
3c6919d2c6
|
@ -2,5 +2,7 @@
|
||||||
config/
|
config/
|
||||||
using_yolov8.ipynb
|
using_yolov8.ipynb
|
||||||
yolov8n.pt
|
yolov8n.pt
|
||||||
|
.venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
faces/*
|
||||||
|
!faces/.gitkeep
|
|
@ -0,0 +1,93 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Take pictures"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Take a picture using opencv with <uuid>.jpg\n",
|
||||||
|
"# Then delete it after\n",
|
||||||
|
"cap = cv2.VideoCapture(0)\n",
|
||||||
|
"ret, frame = cap.read()\n",
|
||||||
|
"cap.release()\n",
|
||||||
|
"uuid_str = str(uuid.uuid4())\n",
|
||||||
|
"uuid_path = Path(uuid_str + \".jpg\")\n",
|
||||||
|
"cv2.imwrite(str(uuid_path), frame)\n",
|
||||||
|
"dfs = DeepFace.find(img_path=str(uuid_path), db_path = \"faces\")\n",
|
||||||
|
"\n",
|
||||||
|
"# Get the identity of the person\n",
|
||||||
|
"for i, pd_dataframe in enumerate(dfs):\n",
|
||||||
|
" # Sort the dataframe by confidence\n",
|
||||||
|
" # inplace=True means that the dataframe is modified so we don't need to assign it to a new variable\n",
|
||||||
|
" pd_dataframe.sort_values(by=['VGG-Face_cosine'], inplace=True, ascending=False)\n",
|
||||||
|
" print(f'On dataframe {i}')\n",
|
||||||
|
" print(pd_dataframe)\n",
|
||||||
|
" # Get the most likely 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: {pd_dataframe.iloc[0][\"identity\"]}')\n",
|
||||||
|
" # Get the most likely identity's confidence\n",
|
||||||
|
" print(f'Confidence: {pd_dataframe.iloc[0][\"VGG-Face_cosine\"]}')\n",
|
||||||
|
"\n",
|
||||||
|
"uuid_path.unlink()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Stream"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"DeepFace.stream(db_path=\"faces\")"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": ".venv",
|
||||||
|
"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.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -8,51 +8,29 @@ readme = "README.md"
|
||||||
packages = [{include = "set-detect-notify"}]
|
packages = [{include = "set-detect-notify"}]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
# python = "^3.10"
|
||||||
|
python = ">=3.10, <3.12"
|
||||||
python-dotenv = "^1.0.0"
|
python-dotenv = "^1.0.0"
|
||||||
httpx = "^0.25.0"
|
httpx = "^0.25.0"
|
||||||
opencv-python = "^4.8.1.78"
|
opencv-python = "^4.8.1.78"
|
||||||
ultralytics = "^8.0.190"
|
ultralytics = "^8.0.190"
|
||||||
hjson = "^3.1.0"
|
hjson = "^3.1.0"
|
||||||
numpy = "^1.23.2"
|
numpy = "^1.23.2"
|
||||||
# torch = [
|
|
||||||
# { version = "^2.0.0+cu118", source = "torch_cu118", markers = "extra=='cuda'" },
|
# https://github.com/python-poetry/poetry/issues/6409
|
||||||
# { version = "^2.0.0+cpu", source = "torch_cpu", markers = "extra!='cuda'" },
|
|
||||||
# ]
|
|
||||||
# torchaudio = [
|
|
||||||
# { version = "^2.0.0+cu118", source = "torch_cu118", markers = "extra=='cuda'" },
|
|
||||||
# { version = "^2.0.0+cpu", source = "torch_cpu", markers = "extra!='cuda'" },
|
|
||||||
# ]
|
|
||||||
# torchvision = [
|
|
||||||
# { version = "^0.15+cu118", source = "torch_cu118", markers = "extra=='cuda'" },
|
|
||||||
# { version = "^0.15+cpu", source = "torch_cpu", markers = "extra!='cuda'" },
|
|
||||||
# ]
|
|
||||||
torch = "^2.1.0"
|
torch = "^2.1.0"
|
||||||
|
|
||||||
|
tensorflow-io-gcs-filesystem = "0.31.0"
|
||||||
|
deepface = "^0.0.79"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
black = "^23.9.1"
|
black = "^23.9.1"
|
||||||
ruff = "^0.0.291"
|
ruff = "^0.0.291"
|
||||||
ipykernel = "^6.25.2"
|
ipykernel = "^6.25.2"
|
||||||
|
nbconvert = "^7.9.2"
|
||||||
|
|
||||||
|
|
||||||
# [[tool.poetry.source]]
|
|
||||||
# name = "torch_cpu"
|
|
||||||
# url = "https://download.pytorch.org/whl/cpu"
|
|
||||||
# priority = "supplemental"
|
|
||||||
#
|
|
||||||
# [[tool.poetry.source]]
|
|
||||||
# name = "torch_cu118"
|
|
||||||
# url = "https://download.pytorch.org/whl/cu118"
|
|
||||||
# priority = "supplemental"
|
|
||||||
#
|
|
||||||
# [tool.poetry.extras]
|
|
||||||
# cuda = []
|
|
||||||
#
|
|
||||||
# [[tool.poetry.source]]
|
|
||||||
# name = "PyPI"
|
|
||||||
# priority = "primary"
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
Loading…
Reference in New Issue