Skip to content
Prev Previous commit
Next Next commit
Re-organize the batching a bit
  • Loading branch information
Hartorn committed Jan 3, 2024
commit b18ec1bdf78c8d13c766dfd57de15b0ee71ee34b
136 changes: 27 additions & 109 deletions examples/criteria1_partial_faces.ipynb

Large diffs are not rendered by default.

99 changes: 93 additions & 6 deletions examples/ex1_draw_landmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,83 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LEFT_EYE\n",
"NMEMean:0.03064837061887285\n",
"NMEs:[0.03639644 0.02607136 0.02883627 0.02288638 0.0390514 ]\n",
"MEMean:6.205209482416183\n",
"MEStd:3.7323675345101868\n",
"NMEMean:0.03064837061887285\n",
"NMEStd:0.006134046369089966\n",
"Es:[[ nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" 5.4613892 1.78589613 5.436992 6.19588936 5.81028786 3.90036639\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan]\n",
" [ nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" 3.18053911 7.35603983 3.61900553 12.1698484 3.20499641 2.34261051\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan]\n",
" [ nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" 16.76414522 4.6575879 7.59055736 13.538641 9.41119509 6.31696699\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan]\n",
" [ nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" 4.09730899 2.86064765 3.59209187 5.20874284 0.60418623 4.28686925\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan]\n",
" [ nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" 11.6476298 2.34872646 6.37660105 9.59164079 10.75729009 6.04159515\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan nan nan nan nan\n",
" nan nan]]\n"
]
}
],
"source": [
"prediction = model.predict(ds, facial_part=FacialParts.LEFT_EYE.value)\n",
"marks = ds.all_marks\n",
Expand All @@ -198,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -215,14 +289,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"outputs": [
{
"ename": "UnboundLocalError",
"evalue": "cannot access local variable '_image' where it is not associated with a value",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mUnboundLocalError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdraw_marks\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[43mground_truth_landmarks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mloreal_landmarks\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mgreen\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mred\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Work/loreal-poc/loreal_poc/visualisation/draw.py:38\u001b[0m, in \u001b[0;36mdraw_marks\u001b[0;34m(image, list_of_marks, colors, with_text, squares)\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(image, np\u001b[38;5;241m.\u001b[39mndarray):\n\u001b[1;32m 37\u001b[0m _image \u001b[38;5;241m=\u001b[39m Image\u001b[38;5;241m.\u001b[39mfromarray(cv2\u001b[38;5;241m.\u001b[39mcvtColor(image, cv2\u001b[38;5;241m.\u001b[39mCOLOR_BGR2RGB))\n\u001b[0;32m---> 38\u001b[0m image_display \u001b[38;5;241m=\u001b[39m \u001b[43m_image\u001b[49m\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[1;32m 39\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m marks, color, _with_text, square \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(\n\u001b[1;32m 40\u001b[0m list_of_marks,\n\u001b[1;32m 41\u001b[0m colors \u001b[38;5;129;01mor\u001b[39;00m [\u001b[38;5;28;01mNone\u001b[39;00m] \u001b[38;5;241m*\u001b[39m \u001b[38;5;28mlen\u001b[39m(list_of_marks),\n\u001b[1;32m 42\u001b[0m with_text \u001b[38;5;129;01mor\u001b[39;00m [\u001b[38;5;28;01mNone\u001b[39;00m] \u001b[38;5;241m*\u001b[39m \u001b[38;5;28mlen\u001b[39m(list_of_marks),\n\u001b[1;32m 43\u001b[0m squares \u001b[38;5;129;01mor\u001b[39;00m [\u001b[38;5;28;01mNone\u001b[39;00m] \u001b[38;5;241m*\u001b[39m \u001b[38;5;28mlen\u001b[39m(list_of_marks),\n\u001b[1;32m 44\u001b[0m ):\n\u001b[1;32m 45\u001b[0m image_display \u001b[38;5;241m=\u001b[39m _add_marks(image_display, marks, color\u001b[38;5;241m=\u001b[39mcolor, with_text\u001b[38;5;241m=\u001b[39m_with_text, square\u001b[38;5;241m=\u001b[39msquare)\n",
"\u001b[0;31mUnboundLocalError\u001b[0m: cannot access local variable '_image' where it is not associated with a value"
]
}
],
"source": [
"draw_marks(image, [ground_truth_landmarks, loreal_landmarks], [\"green\", \"red\"])"
]
Expand Down Expand Up @@ -251,7 +338,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
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