|
11 | 11 | },
|
12 | 12 | {
|
13 | 13 | "cell_type": "code",
|
14 |
| - "execution_count": 1, |
| 14 | + "execution_count": 2, |
15 | 15 | "metadata": {},
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
|
30 | 30 | },
|
31 | 31 | {
|
32 | 32 | "cell_type": "code",
|
33 |
| - "execution_count": 9, |
| 33 | + "execution_count": 3, |
34 | 34 | "metadata": {},
|
35 | 35 | "outputs": [],
|
36 | 36 | "source": [
|
37 | 37 | "dl = DataLoader300W(dir_path=\"300W/sample\")\n",
|
38 | 38 | "chosen_idx = 4\n",
|
39 |
| - "image, ground_truth_landmarks, _ = ds[chosen_idx]" |
| 39 | + "image, ground_truth_landmarks, _ = dl[chosen_idx]" |
40 | 40 | ]
|
41 | 41 | },
|
42 | 42 | {
|
43 | 43 | "cell_type": "code",
|
44 |
| - "execution_count": 10, |
| 44 | + "execution_count": 4, |
45 | 45 | "metadata": {},
|
46 | 46 | "outputs": [
|
47 | 47 | {
|
|
50 | 50 | "'cpu'"
|
51 | 51 | ]
|
52 | 52 | },
|
53 |
| - "execution_count": 10, |
| 53 | + "execution_count": 4, |
54 | 54 | "metadata": {},
|
55 | 55 | "output_type": "execute_result"
|
56 | 56 | }
|
|
64 | 64 | },
|
65 | 65 | {
|
66 | 66 | "cell_type": "code",
|
67 |
| - "execution_count": 11, |
| 67 | + "execution_count": 5, |
68 | 68 | "metadata": {},
|
69 | 69 | "outputs": [
|
70 | 70 | {
|
71 | 71 | "name": "stdout",
|
72 | 72 | "output_type": "stream",
|
73 | 73 | "text": [
|
74 |
| - "File exists\n", |
75 |
| - "File exists\n", |
76 | 74 | "loading data from : lbfmodel.yaml\n"
|
77 | 75 | ]
|
78 | 76 | }
|
|
84 | 82 | },
|
85 | 83 | {
|
86 | 84 | "cell_type": "code",
|
87 |
| - "execution_count": 12, |
88 |
| - "metadata": {}, |
89 |
| - "outputs": [ |
90 |
| - { |
91 |
| - "data": { |
92 |
| - "text/html": [ |
93 |
| - "\n", |
94 |
| - " <h4><span style=\"color:green;\">✓</span> Test \"NME_mean\" succeeded</h4>\n", |
95 |
| - " <p>Description: Mean of normalised mean Euclidean distances across images</p>\n", |
96 |
| - " <p>Metric: <b>0.0414</b> (threshold = 1)</p>\n", |
97 |
| - " \n", |
98 |
| - " <p>Prediction time: 0.54 s.</p>\n", |
99 |
| - " " |
100 |
| - ], |
101 |
| - "text/plain": [ |
102 |
| - "\n", |
103 |
| - " Test \"NME_mean\" succeeded\n", |
104 |
| - " Description: Mean of normalised mean Euclidean distances across images\n", |
105 |
| - " Metric: 0.0414 (threshold = 1)\n", |
106 |
| - " \n", |
107 |
| - " Prediction time: 0.54 s.\n", |
108 |
| - " " |
109 |
| - ] |
110 |
| - }, |
111 |
| - "execution_count": 12, |
112 |
| - "metadata": {}, |
113 |
| - "output_type": "execute_result" |
114 |
| - } |
115 |
| - ], |
116 |
| - "source": [ |
117 |
| - "Test(metric=NMEMean, threshold=1).run(model=opencv_model, dataloader=dl)" |
118 |
| - ] |
119 |
| - }, |
120 |
| - { |
121 |
| - "cell_type": "code", |
122 |
| - "execution_count": 14, |
| 85 | + "execution_count": 6, |
123 | 86 | "metadata": {},
|
124 | 87 | "outputs": [
|
125 | 88 | {
|
126 | 89 | "data": {
|
127 |
| - "text/html": [ |
128 |
| - "\n", |
129 |
| - " <h4><span style=\"color:green;\">✓</span> Test \"NME_mean\" succeeded</h4>\n", |
130 |
| - " <p>Description: Mean of normalised mean Euclidean distances across images</p>\n", |
131 |
| - " <p>Metric: <b>0.0623</b> (threshold = 1)</p>\n", |
132 |
| - " \n", |
133 |
| - " <p>Prediction time: 37.83 s.</p>\n", |
134 |
| - " " |
135 |
| - ], |
136 | 90 | "text/plain": [
|
137 |
| - "\n", |
138 |
| - " Test \"NME_mean\" succeeded\n", |
139 |
| - " Description: Mean of normalised mean Euclidean distances across images\n", |
140 |
| - " Metric: 0.0623 (threshold = 1)\n", |
141 |
| - " \n", |
142 |
| - " Prediction time: 37.83 s.\n", |
143 |
| - " " |
| 91 | + "{'test_name': 'Test',\n", |
| 92 | + " 'metric_name': 'NME_mean',\n", |
| 93 | + " 'metric_value': 0.04136279942306024,\n", |
| 94 | + " 'threshold': 1,\n", |
| 95 | + " 'passed': True,\n", |
| 96 | + " 'facial_part': 'entire face',\n", |
| 97 | + " 'model_name': 'OpenCV',\n", |
| 98 | + " 'dataloader_name': '300W'}" |
144 | 99 | ]
|
145 | 100 | },
|
146 |
| - "execution_count": 14, |
| 101 | + "execution_count": 6, |
147 | 102 | "metadata": {},
|
148 | 103 | "output_type": "execute_result"
|
149 | 104 | }
|
150 | 105 | ],
|
151 | 106 | "source": [
|
152 |
| - "Test(metric=NMEMean, threshold=1).run(model=facealignment_model, dataloader=dl)" |
| 107 | + "test = Test(metric=NMEMean, threshold=1).run(model=opencv_model, dataloader=dl)\n", |
| 108 | + "\n", |
| 109 | + "test.to_dict()" |
153 | 110 | ]
|
154 | 111 | },
|
155 | 112 | {
|
156 | 113 | "cell_type": "code",
|
157 |
| - "execution_count": 8, |
| 114 | + "execution_count": 7, |
158 | 115 | "metadata": {},
|
159 | 116 | "outputs": [
|
160 | 117 | {
|
161 | 118 | "name": "stderr",
|
162 | 119 | "output_type": "stream",
|
163 | 120 | "text": [
|
164 |
| - "/home/bazire/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n", |
| 121 | + "/Users/rak/Documents/loreal-poc/loreal_poc/tests/performance.py:47: RuntimeWarning: Mean of empty slice\n", |
165 | 122 | " mes = np.nanmean(es, axis=1)\n"
|
166 | 123 | ]
|
167 | 124 | },
|
168 | 125 | {
|
169 | 126 | "data": {
|
170 |
| - "text/html": [ |
171 |
| - "\n", |
172 |
| - " <h4><span style=\"color:green;\">✓</span> Test \"NME_mean\" succeeded</h4>\n", |
173 |
| - " <p>Description: Mean of normalised mean Euclidean distances across images</p>\n", |
174 |
| - " <p>Metric: <b>0.6623</b> (threshold = 1)</p>\n", |
175 |
| - " Prediction fail rate: 0.4\n", |
176 |
| - " <p>Prediction time: 0.54 s.</p>\n", |
177 |
| - " " |
178 |
| - ], |
179 | 127 | "text/plain": [
|
180 |
| - "\n", |
181 |
| - " Test \"NME_mean\" succeeded\n", |
182 |
| - " Description: Mean of normalised mean Euclidean distances across images\n", |
183 |
| - " Metric: 0.6623 (threshold = 1)\n", |
184 |
| - " Prediction fail rate: 0.4\n", |
185 |
| - " Prediction time: 0.54 s.\n", |
186 |
| - " " |
| 128 | + "{'test_name': 'TestDiff',\n", |
| 129 | + " 'metric_name': 'NME_mean',\n", |
| 130 | + " 'metric_value': 0.3984345106345805,\n", |
| 131 | + " 'threshold': 1,\n", |
| 132 | + " 'passed': True,\n", |
| 133 | + " 'facial_part': 'left half',\n", |
| 134 | + " 'model_name': 'OpenCV',\n", |
| 135 | + " 'dataloader_name': '300W'}" |
187 | 136 | ]
|
188 | 137 | },
|
189 |
| - "execution_count": 8, |
| 138 | + "execution_count": 7, |
190 | 139 | "metadata": {},
|
191 | 140 | "output_type": "execute_result"
|
192 | 141 | }
|
|
196 | 145 | "\n",
|
197 | 146 | "facial_part = FacialParts.left_half\n",
|
198 | 147 | "\n",
|
199 |
| - "TestDiff(metric=NMEMean, threshold=1).run(\n", |
| 148 | + "test_diff = TestDiff(metric=NMEMean, threshold=1).run(\n", |
200 | 149 | " model=opencv_model, dataloader=dl, dataloader_ref=CroppedDataLoader(dl, part=facial_part), facial_part=facial_part\n",
|
201 |
| - ")" |
| 150 | + ")\n", |
| 151 | + "test_diff.to_dict()" |
202 | 152 | ]
|
203 | 153 | },
|
204 | 154 | {
|
205 | 155 | "cell_type": "code",
|
206 |
| - "execution_count": 9, |
| 156 | + "execution_count": 8, |
207 | 157 | "metadata": {},
|
208 | 158 | "outputs": [
|
209 | 159 | {
|
210 | 160 | "name": "stderr",
|
211 | 161 | "output_type": "stream",
|
212 | 162 | "text": [
|
213 |
| - "/home/bazire/loreal-poc/loreal_poc/tests/performance.py:85: RuntimeWarning: Mean of empty slice\n", |
214 |
| - " return np.nanmean(NMEs.get(prediction_result, marks))\n", |
215 |
| - "/home/bazire/loreal-poc/.venv/lib/python3.10/site-packages/face_alignment/api.py:147: UserWarning: No faces were detected.\n", |
216 |
| - " warnings.warn(\"No faces were detected.\")\n" |
| 163 | + "/Users/rak/Documents/loreal-poc/loreal_poc/tests/performance.py:85: RuntimeWarning: Mean of empty slice\n", |
| 164 | + " return np.nanmean(NMEs.get(prediction_result, marks))\n" |
217 | 165 | ]
|
218 | 166 | }
|
219 | 167 | ],
|
220 | 168 | "source": [
|
221 |
| - "from dataclasses import fields\n", |
| 169 | + "# from dataclasses import fields\n", |
| 170 | + "def report(models, dataloader, tests, facial_parts):\n", |
| 171 | + " results = []\n", |
| 172 | + " for model in models:\n", |
| 173 | + " # for __facial_part in fields(FacialParts):\n", |
| 174 | + " # _facial_part = __facial_part.default\n", |
| 175 | + " for facial_part in facial_parts:\n", |
| 176 | + " for test_cls in tests:\n", |
| 177 | + " test_result = test_cls(metric=NMEMean, threshold=1).run(\n", |
| 178 | + " model=model,\n", |
| 179 | + " dataloader=CroppedDataLoader(dataloader, part=facial_part),\n", |
| 180 | + " dataloader_ref=dl,\n", |
| 181 | + " facial_part=facial_part,\n", |
| 182 | + " )\n", |
| 183 | + " results.append(test_result.to_dict())\n", |
| 184 | + " return results\n", |
| 185 | + "\n", |
222 | 186 | "\n",
|
223 |
| - "results = {\"OpenCV\": {\"model\": opencv_model}, \"FaceAlignment\": {\"model\": facealignment_model}}\n", |
224 |
| - "for model_name, _model in results.items():\n", |
225 |
| - " model = _model[\"model\"]\n", |
226 |
| - " for __facial_part in fields(FacialParts):\n", |
227 |
| - " _facial_part = __facial_part.default\n", |
228 |
| - " test = TestDiff(metric=NMEMean, threshold=1).run(\n", |
229 |
| - " model=model,\n", |
230 |
| - " dataloader=dl,\n", |
231 |
| - " dataloader_ref=CroppedDataLoader(dl, part=_facial_part),\n", |
232 |
| - " facial_part=_facial_part,\n", |
233 |
| - " )\n", |
234 |
| - " results[model_name][_facial_part.name] = test.metric" |
| 187 | + "report = report([opencv_model], dl, [TestDiff], [FacialParts.bottom_half, FacialParts.upper_half])" |
235 | 188 | ]
|
236 | 189 | },
|
237 | 190 | {
|
238 | 191 | "cell_type": "code",
|
239 |
| - "execution_count": 10, |
| 192 | + "execution_count": 9, |
240 | 193 | "metadata": {},
|
241 | 194 | "outputs": [
|
242 | 195 | {
|
243 | 196 | "data": {
|
| 197 | + "text/html": [ |
| 198 | + "<div>\n", |
| 199 | + "<style scoped>\n", |
| 200 | + " .dataframe tbody tr th:only-of-type {\n", |
| 201 | + " vertical-align: middle;\n", |
| 202 | + " }\n", |
| 203 | + "\n", |
| 204 | + " .dataframe tbody tr th {\n", |
| 205 | + " vertical-align: top;\n", |
| 206 | + " }\n", |
| 207 | + "\n", |
| 208 | + " .dataframe thead th {\n", |
| 209 | + " text-align: right;\n", |
| 210 | + " }\n", |
| 211 | + "</style>\n", |
| 212 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 213 | + " <thead>\n", |
| 214 | + " <tr style=\"text-align: right;\">\n", |
| 215 | + " <th></th>\n", |
| 216 | + " <th>test_name</th>\n", |
| 217 | + " <th>metric_name</th>\n", |
| 218 | + " <th>metric_value</th>\n", |
| 219 | + " <th>threshold</th>\n", |
| 220 | + " <th>passed</th>\n", |
| 221 | + " <th>facial_part</th>\n", |
| 222 | + " <th>model_name</th>\n", |
| 223 | + " <th>dataloader_name</th>\n", |
| 224 | + " </tr>\n", |
| 225 | + " </thead>\n", |
| 226 | + " <tbody>\n", |
| 227 | + " <tr>\n", |
| 228 | + " <th>0</th>\n", |
| 229 | + " <td>TestDiff</td>\n", |
| 230 | + " <td>NME_mean</td>\n", |
| 231 | + " <td>NaN</td>\n", |
| 232 | + " <td>1</td>\n", |
| 233 | + " <td>False</td>\n", |
| 234 | + " <td>bottom half</td>\n", |
| 235 | + " <td>OpenCV</td>\n", |
| 236 | + " <td>300W cropped on bottom half</td>\n", |
| 237 | + " </tr>\n", |
| 238 | + " <tr>\n", |
| 239 | + " <th>1</th>\n", |
| 240 | + " <td>TestDiff</td>\n", |
| 241 | + " <td>NME_mean</td>\n", |
| 242 | + " <td>0.040216</td>\n", |
| 243 | + " <td>1</td>\n", |
| 244 | + " <td>True</td>\n", |
| 245 | + " <td>upper half</td>\n", |
| 246 | + " <td>OpenCV</td>\n", |
| 247 | + " <td>300W cropped on upper half</td>\n", |
| 248 | + " </tr>\n", |
| 249 | + " </tbody>\n", |
| 250 | + "</table>\n", |
| 251 | + "</div>" |
| 252 | + ], |
244 | 253 | "text/plain": [
|
245 |
| - "{'OpenCV': {'model': <loreal_poc.models.wrappers.OpenCVWrapper at 0x7f75e93bf910>,\n", |
246 |
| - " 'entire face': 0.031593074968095824,\n", |
247 |
| - " 'face contour': 0.0524161528719839,\n", |
248 |
| - " 'left eyebrow': nan,\n", |
249 |
| - " 'right eyebrow': nan,\n", |
250 |
| - " 'nose': nan,\n", |
251 |
| - " 'left eye': nan,\n", |
252 |
| - " 'right eye': nan,\n", |
253 |
| - " 'mouth': nan,\n", |
254 |
| - " 'bottom half': nan,\n", |
255 |
| - " 'upper half': 0.04021610184657019,\n", |
256 |
| - " 'left half': 0.662329401666445,\n", |
257 |
| - " 'right half': 0.9675771331137769},\n", |
258 |
| - " 'FaceAlignment': {'model': <loreal_poc.models.wrappers.FaceAlignmentWrapper at 0x7f75e93bc370>,\n", |
259 |
| - " 'entire face': 0.06824182183674955,\n", |
260 |
| - " 'face contour': 0.13120804359950317,\n", |
261 |
| - " 'left eyebrow': nan,\n", |
262 |
| - " 'right eyebrow': nan,\n", |
263 |
| - " 'nose': nan,\n", |
264 |
| - " 'left eye': 2.2704133968712634,\n", |
265 |
| - " 'right eye': nan,\n", |
266 |
| - " 'mouth': nan,\n", |
267 |
| - " 'bottom half': 8.182222629236117e-05,\n", |
268 |
| - " 'upper half': 0.22317472213175207,\n", |
269 |
| - " 'left half': 0.6372027526669263,\n", |
270 |
| - " 'right half': 0.3839864768052418}}" |
| 254 | + " test_name metric_name metric_value threshold passed facial_part \\\n", |
| 255 | + "0 TestDiff NME_mean NaN 1 False bottom half \n", |
| 256 | + "1 TestDiff NME_mean 0.040216 1 True upper half \n", |
| 257 | + "\n", |
| 258 | + " model_name dataloader_name \n", |
| 259 | + "0 OpenCV 300W cropped on bottom half \n", |
| 260 | + "1 OpenCV 300W cropped on upper half " |
271 | 261 | ]
|
272 | 262 | },
|
273 |
| - "execution_count": 10, |
| 263 | + "execution_count": 9, |
274 | 264 | "metadata": {},
|
275 | 265 | "output_type": "execute_result"
|
276 | 266 | }
|
277 | 267 | ],
|
278 | 268 | "source": [
|
279 |
| - "results" |
| 269 | + "import pandas as pd\n", |
| 270 | + "\n", |
| 271 | + "pd.DataFrame(report)" |
280 | 272 | ]
|
281 | 273 | }
|
282 | 274 | ],
|
|
296 | 288 | "name": "python",
|
297 | 289 | "nbconvert_exporter": "python",
|
298 | 290 | "pygments_lexer": "ipython3",
|
299 |
| - "version": "3.10.12" |
| 291 | + "version": "3.11.6" |
300 | 292 | }
|
301 | 293 | },
|
302 | 294 | "nbformat": 4,
|
|
0 commit comments