Skip to content

Commit

Permalink
Add mpiiface dataset pre-processing and visualization notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelos Ververas committed Dec 8, 2023
1 parent 5569271 commit d7eab9f
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 13 deletions.
117 changes: 117 additions & 0 deletions notebooks/mpiiface_view_dataset.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "e5b2fe72-599d-46ed-8285-25e9e0d31ffc",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import cv2\n",
"import pickle\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from pathlib import Path\n",
"\n",
"from utils import *\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1275092e-02f5-4538-b43d-33295e8d1151",
"metadata": {},
"outputs": [],
"source": [
"# data set base dir\n",
"# path_base = Path('/storage/nfs2/evangelosv/databases/EyeReconstruction/MPIIFaceGaze/')\n",
"path_base = Path('datasets/MPIIFaceGaze')\n",
"path_images = path_base / 'images'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06b70cc3-7c91-473a-942c-ac18e27872b8",
"metadata": {},
"outputs": [],
"source": [
"with open(str(path_base / 'data_for_model_2/all_gaze_eyes3D_face68.pkl'), 'rb') as f:\n",
" data = pickle.load(f)\n",
"data = {d['name']: d for d in data}\n",
"paths = list(data.keys())\n",
"print(f\"Number of samples in dataset: {len(data)}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07baab32-872f-4b1e-8bde-3448e9e5049c",
"metadata": {},
"outputs": [],
"source": [
"# Randomly loop through the data\n",
"k = np.random.randint(len(paths))\n",
"path = paths[k]\n",
"\n",
"res = data[path]\n",
"image = cv2.imread(str(path_images / path))\n",
"lms68 = res['face']['xyz68'].astype(np.float32)\n",
"eyes = {\n",
" 'left' : (res['eyes']['left']['P'] @ eyel_template_homo.T).T,\n",
" 'right': (res['eyes']['right']['P'] @ eyer_template_homo.T).T\n",
"}\n",
"gaze_vector = res['gaze']['face']['vector']\n",
"print(f\"Gaze direction: {gaze_vector}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfcb10b6-1736-41e7-8aa1-94aa60e081d5",
"metadata": {},
"outputs": [],
"source": [
"# visualize gaze direction\n",
"image_gaze = draw_gaze_from_vector(image.copy(), lms68, gaze_vector, colour=[255, 0, 0])\n",
"plt.imshow(image_gaze[:, :, [2, 1, 0]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb35015f-3e74-4f6b-a812-4424e03fd6eb",
"metadata": {},
"outputs": [],
"source": [
"# visualize 3D eyes\n",
"image_eyes = draw_eyes(image.copy(), lms68, eyes, colour=[178, 255, 102])\n",
"plt.imshow(image_eyes[:, :, [2, 1, 0]])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 3 additions & 3 deletions tools/gaze360_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ def get_path(i):
print(f"Total number of samples with headpose <= 90 degrees: train: {len(paths_train)}, test: {len(paths_test)}, all: {len(paths)}")

# Lms and Headpose ------------------------------------------------------------------------------

# tracked with insightface
print('Loading face and iris lms...')
# face lms
with open(str(path_base / 'lms68_3D_wbb.pkl'), 'rb') as f:
lms68_wbb = pickle.load(f)
with open(str(path_base / 'lms68_3D_wobb.pkl'), 'rb') as f:
lms68_wobb = pickle.load(f)
lms68_all = lms68_wbb.copy()
lms68_all.update(lms68_wobb)
print(f"face lms of images with given bboxes: {len(lms68_wbb)}, without given bboxes: {len(lms68_wobb)}, all: {len(lms68_all)}")

# iris lms
with open(str(path_base / 'lms8_all.pkl'), 'rb') as f:
lms8_all = pickle.load(f)

Expand Down
Loading

0 comments on commit d7eab9f

Please sign in to comment.