Skip to content
30 changes: 12 additions & 18 deletions examples/criteria1_partial_faces.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"loading data from : lbfmodel.yaml\n"
]
}
],
"outputs": [],
"source": [
"# model = FaceAlignmentWrapper(model=FaceAlignment(LandmarksType.TWO_D, device=device, flip_input=False))\n",
"model = OpenCVWrapper()\n",
Expand All @@ -69,7 +61,7 @@
" <p>Description: Mean of normalised mean Euclidean distances across images</p>\n",
" <p>Metric: <b>0.0383</b> (threshold = 1)</p>\n",
" \n",
" <p>Prediction time: 0.71 s.</p>\n",
" <p>Prediction time: 0.34 s.</p>\n",
" "
],
"text/plain": [
Expand All @@ -78,7 +70,7 @@
" Description: Mean of normalised mean Euclidean distances across images\n",
" Metric: 0.0383 (threshold = 1)\n",
" \n",
" Prediction time: 0.71 s.\n",
" Prediction time: 0.34 s.\n",
" "
]
},
Expand Down Expand Up @@ -117,7 +109,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/rak/Documents/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n",
"/Users/bazire/Work/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n",
" mes = np.nanmean(es, axis=1)\n"
]
}
Expand Down Expand Up @@ -159,8 +151,10 @@
"squares = []\n",
"chosen_idx = 1\n",
"image, _, _ = ds[chosen_idx]\n",
"image = image[0]\n",
"for rel_margin in rel_margins:\n",
" img, marks, meta = ds[chosen_idx]\n",
" img, marks, meta = img[0], marks[0], meta[0]\n",
" h, w, _ = img.shape\n",
" margins = np.array([w, h]) * rel_margin\n",
" cropped_mark = crop_mark(marks, facial_part)\n",
Expand Down Expand Up @@ -211,7 +205,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/rak/Documents/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n",
"/Users/bazire/Work/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n",
" mes = np.nanmean(es, axis=1)\n"
]
},
Expand All @@ -223,7 +217,7 @@
" <p>Description: Mean of normalised mean Euclidean distances across images</p>\n",
" <p>Metric: <b>0.5774</b> (threshold = 1)</p>\n",
" Prediction fail rate: 0.6\n",
" <p>Prediction time: 0.82 s.</p>\n",
" <p>Prediction time: 0.41 s.</p>\n",
" "
],
"text/plain": [
Expand All @@ -232,7 +226,7 @@
" Description: Mean of normalised mean Euclidean distances across images\n",
" Metric: 0.5774 (threshold = 1)\n",
" Prediction fail rate: 0.6\n",
" Prediction time: 0.82 s.\n",
" Prediction time: 0.41 s.\n",
" "
]
},
Expand Down Expand Up @@ -261,7 +255,7 @@
" <p>Description: Standard deviation of normalised Mean Euclidean distances across images</p>\n",
" <p>Metric: <b>0.0532</b> (threshold = 1)</p>\n",
" Prediction fail rate: 0.6\n",
" <p>Prediction time: 0.65 s.</p>\n",
" <p>Prediction time: 0.43 s.</p>\n",
" "
],
"text/plain": [
Expand All @@ -270,7 +264,7 @@
" Description: Standard deviation of normalised Mean Euclidean distances across images\n",
" Metric: 0.0532 (threshold = 1)\n",
" Prediction fail rate: 0.6\n",
" Prediction time: 0.65 s.\n",
" Prediction time: 0.43 s.\n",
" "
]
},
Expand Down Expand Up @@ -307,7 +301,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
100 changes: 94 additions & 6 deletions examples/ex1_draw_landmarks.ipynb

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions examples/ex2_draw_partial_landmarks.ipynb

Large diffs are not rendered by default.

49 changes: 41 additions & 8 deletions examples/ex3_calculate_euc_dists.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -19,28 +19,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"array([4. , 1. , 2.23606798, 2.23606798])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_min_b = A - B\n",
"np.sqrt(np.einsum(\"ij,ij->i\", a_min_b, a_min_b))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"array([4. , 1. , 2.23606798, 2.23606798])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linalg.norm(A - B, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"array([4. , 1. , 2.23606798, 2.23606798])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d_all = np.sqrt(np.einsum(\"ij->i\", (A - B) ** 2))\n",
"d_all"
Expand All @@ -63,7 +96,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
93 changes: 83 additions & 10 deletions examples/ex4_tests_and_metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": false,
"jupyter": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -51,9 +51,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'cpu'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import torch\n",
"\n",
Expand All @@ -75,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -89,23 +100,85 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"\n",
" <h4><span style=\"color:green;\">✓</span> Test \"NME_mean\" succeeded</h4>\n",
" <p>Description: Mean of normalised mean Euclidean distances across images</p>\n",
" <p>Metric: <b>0.0623</b> (threshold = 1)</p>\n",
" \n",
" <p>Prediction time: 13.1 s.</p>\n",
" "
],
"text/plain": [
"\n",
" Test \"NME_mean\" succeeded\n",
" Description: Mean of normalised mean Euclidean distances across images\n",
" Metric: 0.0623 (threshold = 1)\n",
" \n",
" Prediction time: 13.1 s.\n",
" "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Test(metric=NMEMean, threshold=1).run(model, ds)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/bazire/Work/loreal-poc/.venv/lib/python3.11/site-packages/face_alignment/api.py:147: UserWarning: No faces were detected.\n",
" warnings.warn(\"No faces were detected.\")\n",
"/Users/bazire/Work/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n",
" mes = np.nanmean(es, axis=1)\n"
]
},
{
"data": {
"text/html": [
"\n",
" <h4><span style=\"color:green;\">✓</span> Test \"NME_mean\" succeeded</h4>\n",
" <p>Description: Mean of normalised mean Euclidean distances across images</p>\n",
" <p>Metric: <b>0.3962</b> (threshold = 1)</p>\n",
" Prediction fail rate: 0.4\n",
" <p>Prediction time: 18.74 s.</p>\n",
" "
],
"text/plain": [
"\n",
" Test \"NME_mean\" succeeded\n",
" Description: Mean of normalised mean Euclidean distances across images\n",
" Metric: 0.3962 (threshold = 1)\n",
" Prediction fail rate: 0.4\n",
" Prediction time: 18.74 s.\n",
" "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from loreal_poc.marks.facial_parts import FacialParts\n",
"from loreal_poc.dataloaders.wrappers import CroppedDataLoader, CachedDataLoader\n",
Expand All @@ -132,7 +205,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
Loading