modules
Evalify main module used for creating the verification experiments.
Creates experiments with embedding pairs to compare for face verification tasks including positive pairs, negative pairs and metrics calculations using a very optimized einstein sum. Many operations are dispatched to canonical BLAS, cuBLAS, or other specialized routines. Extremely large arrays are split into smaller batches, every batch would consume the roughly the maximum available memory.
Typical usage example:
1 2 |
|
Experiment
¶
Defines an experiment for evalifying.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
Union[str, Sequence[str]]
|
The list of metrics to use. Can be one or more of the following:
|
'cosine_similarity'
|
same_class_samples
|
StrOrInt
|
|
'full'
|
different_class_samples
|
StrIntSequence
|
|
'minimal'
|
seed
|
Optional[int]
|
Optional random seed for reproducibility. |
None
|
Notes
same_class_samples
: If the provided number is greater than the achievable for the class, the maximum possible combinations are used.different_class_samples
: If the provided number is greater than the achievable for the class, the maximum possible combinations are used. (N, M) can also be ('full', 'full') but this will calculate all possible combinations between all posibile negative samples. If the dataset is not small this will probably result in an extremely large array!.
Source code in evalify/evalify.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
|
eer()
¶
Calculates the Equal Error Rate (EER) for each metric.
Returns:
Name | Type | Description |
---|---|---|
OrderedDict |
OrderedDict
|
A dictionary containing the EER value and threshold for each |
OrderedDict
|
metric. The metrics are sorted in ascending order based on the EER values. Example: {'metric1': {'EER': 0.123, 'threshold': 0.456}, ...} |
Source code in evalify/evalify.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
evaluate_at_threshold(threshold, metric)
¶
Evaluate performance at specific threshold Args: threshold: Cut-off threshold. metric: Metric to use.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dict ontaining all evaluation metrics. |
Source code in evalify/evalify.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
find_optimal_cutoff()
¶
Finds the optimal cutoff threshold for each metric based on the ROC curve.
This function calculates the optimal threshold for each metric by finding the point on the Receiver Operating Characteristic (ROC) curve where the difference between the True Positive Rate (TPR) and the False Positive Rate (FPR) is minimized.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary with metrics as keys and their corresponding optimal |
dict
|
threshold as values. |
Source code in evalify/evalify.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
get_binary_prediction(metric, threshold)
¶
Binary classification prediction based on the given metric and threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
str
|
Metric name for the desired prediction. |
required |
threshold
|
float
|
Cut off threshold. |
required |
Returns:
Type | Description |
---|---|
Series
|
pd.Series: Binary predictions. |
Source code in evalify/evalify.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
predicted_as_similarity(metric)
¶
Convert distance metrics to a similarity measure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
str
|
distance metric to convert to similarity. If a similarity metric is passed, It gets returned unchanged. |
required |
Returns:
Type | Description |
---|---|
Series
|
pd.Series: Converted distance to similarity. |
Source code in evalify/evalify.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
|
roc_auc()
¶
Find ROC AUC for all the metrics used.
Returns:
Name | Type | Description |
---|---|---|
OrderedDict |
OrderedDict
|
An OrderedDict with AUC for all metrics. |
Source code in evalify/evalify.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
run(X, y, batch_size='best', shuffle=False, return_embeddings=False, p=3)
¶
Runs an experiment for face verification
Args:
X: Embeddings array
y: Targets for X as integers
batch_size:
- 'best': Let the program decide based on available memory such that
every batch will fit into the available memory. (Default)
- int: Manually decide the batch_size.
- None: No batching. All experiment and intermediate results must fit
entirely into memory or a MemoryError will be raised.
shuffle: Shuffle the returned experiment dataframe. Default: False.
return_embeddings: Whether to return the embeddings instead of indexes.
Default: False
p:
The order of the norm of the difference. Should be p >= 1
, Only valid
with minkowski_distance as a metric. Default = 3.
Returns:
Type | Description |
---|---|
DataFrame
|
pandas.DataFrame: A DataFrame representing the experiment results. |
Raises:
Type | Description |
---|---|
ValueError
|
An error occurred with the provided arguments. |
Source code in evalify/evalify.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
tar_at_far(far_values)
¶
Calculates TAR at specified FAR values for each metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
far_values
|
List[float]
|
A list of False Accept Rates (FAR) to get TAR values for. |
required |
Returns:
Name | Type | Description |
---|---|---|
OrderedDict |
OrderedDict
|
A dictionary with keys as metrics and values as dictionaries |
OrderedDict
|
of FAR:TAR pairs. |
Raises:
Type | Description |
---|---|
ValueError
|
If any FAR in far_values is not between 0 and 1. |
Source code in evalify/evalify.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
|
threshold_at_fpr(fpr)
¶
Find the threshold at a specified False Positive Rate (FPR) for each metric.
The function calculates the threshold at the specified FPR for each metric by using the Receiver Operating Characteristic (ROC) curve. If the desired FPR is 0 or 1, or no exact match is found, the closest thresholds are used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpr
|
float
|
Desired False Positive Rate. Must be between 0 and 1. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary where keys are the metrics and values are dictionaries |
dict
|
containing FPR, TPR, and threshold at the specified FPR. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided |
Source code in evalify/evalify.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|