|
22 | 22 | COLORS = list(ImageColor.colormap.values())
|
23 | 23 | FONT_SCALE = 35
|
24 | 24 | LINE_WIDTH_SCALE = 250
|
| 25 | +ERROR_BAR_BASE_COLOR = "indianred" |
| 26 | +ERROR_BAR_COMPARE_COLOR = "lightseagreen" |
25 | 27 |
|
26 | 28 |
|
27 | 29 | def decode_segmap(labels, dataset="cityscapes"):
|
@@ -370,3 +372,127 @@ def rotation_plot(df, x, y, z=None, max_samples=None, title=None, **kwargs):
|
370 | 372 | )
|
371 | 373 | )
|
372 | 374 | return fig
|
| 375 | + |
| 376 | + |
| 377 | +def model_performance_comparison_box_plot( |
| 378 | + title=None, |
| 379 | + mean_ap_base=None, |
| 380 | + mean_ap_50_base=None, |
| 381 | + mean_ar_base=None, |
| 382 | + mean_ap_new=None, |
| 383 | + mean_ap_50_new=None, |
| 384 | + mean_ar_new=None, |
| 385 | + range=[0, 1.0], |
| 386 | + **kwargs, |
| 387 | +): |
| 388 | + """Create a box plot for a base and new model performance |
| 389 | + Args: |
| 390 | + title (str): title of the plot |
| 391 | + mean_ap_base (list): a list of base mAP |
| 392 | + mean_ap_50_base (list): a list of base mAP |
| 393 | + mean_ar_base (list): a list of base mAP |
| 394 | + mean_ap_new (list): a list of base mAP |
| 395 | + mean_ap_50_new (list): a list of base mAP |
| 396 | + mean_ar_new (list): a list of base mAP |
| 397 | + range (list): the range of y axis. Defaults to [0, 1.0] |
| 398 | +
|
| 399 | + Returns: |
| 400 | + A plotly.graph_objects.Figure containing the box plot |
| 401 | + """ |
| 402 | + fig = go.Figure( |
| 403 | + layout=go.Layout(title=go.layout.Title(text=title), **kwargs) |
| 404 | + ) |
| 405 | + fig.update_yaxes(range=range) |
| 406 | + _fig_add_trace( |
| 407 | + fig, |
| 408 | + mean_ap_base, |
| 409 | + name="baes mAP", |
| 410 | + base=True, |
| 411 | + color=ERROR_BAR_BASE_COLOR, |
| 412 | + ) |
| 413 | + _fig_add_trace( |
| 414 | + fig, |
| 415 | + mean_ap_new, |
| 416 | + name="new mAP", |
| 417 | + base=False, |
| 418 | + color=ERROR_BAR_COMPARE_COLOR, |
| 419 | + ) |
| 420 | + _fig_add_trace( |
| 421 | + fig, |
| 422 | + mean_ap_50_base, |
| 423 | + name="base mAP50", |
| 424 | + base=True, |
| 425 | + color=ERROR_BAR_BASE_COLOR, |
| 426 | + ) |
| 427 | + _fig_add_trace( |
| 428 | + fig, |
| 429 | + mean_ap_50_new, |
| 430 | + name="new mAP50", |
| 431 | + base=False, |
| 432 | + color=ERROR_BAR_COMPARE_COLOR, |
| 433 | + ) |
| 434 | + _fig_add_trace( |
| 435 | + fig, |
| 436 | + mean_ar_base, |
| 437 | + name="base mAR", |
| 438 | + base=True, |
| 439 | + color=ERROR_BAR_BASE_COLOR, |
| 440 | + ) |
| 441 | + _fig_add_trace( |
| 442 | + fig, |
| 443 | + mean_ar_new, |
| 444 | + name="new mAR", |
| 445 | + base=False, |
| 446 | + color=ERROR_BAR_COMPARE_COLOR, |
| 447 | + ) |
| 448 | + |
| 449 | + return fig |
| 450 | + |
| 451 | + |
| 452 | +def model_performance_box_plot( |
| 453 | + title=None, |
| 454 | + mean_ap=None, |
| 455 | + mean_ap_50=None, |
| 456 | + mean_ar=None, |
| 457 | + range=[0, 1.0], |
| 458 | + **kwargs, |
| 459 | +): |
| 460 | + """Create a box plot for one model performance |
| 461 | + Args: |
| 462 | + title (str): title of the plot |
| 463 | + mean_ap (list): a list of base mAP |
| 464 | + mean_ap_50 (list): a list of base mAP |
| 465 | + mean_ar (list): a list of base mAP |
| 466 | + range (list): the range of y axis. Defaults to [0, 1.0] |
| 467 | +
|
| 468 | + Returns: |
| 469 | + A plotly.graph_objects.Figure containing the box plot |
| 470 | + """ |
| 471 | + fig = go.Figure( |
| 472 | + layout=go.Layout(title=go.layout.Title(text=title), **kwargs) |
| 473 | + ) |
| 474 | + fig.update_yaxes(range=range) |
| 475 | + _fig_add_trace(fig, mean_ap, name="mAP") |
| 476 | + _fig_add_trace(fig, mean_ap_50, name="mAP@IOU50") |
| 477 | + _fig_add_trace(fig, mean_ar, name="mAR") |
| 478 | + |
| 479 | + return fig |
| 480 | + |
| 481 | + |
| 482 | +def _fig_add_trace( |
| 483 | + fig=None, data=[], name="", base=True, color=ERROR_BAR_BASE_COLOR |
| 484 | +): |
| 485 | + """Add box plot in figure |
| 486 | + Args: |
| 487 | + fig (go.Figure): figure you want to add box plot in |
| 488 | + data (list): metric values |
| 489 | + name (str): name of the added box plot |
| 490 | + base (bool): whether is a base metric. Defaults to true |
| 491 | + color (str): color for box plot |
| 492 | +
|
| 493 | + Returns: |
| 494 | + A plotly.graph_objects.Figure containing the box plot |
| 495 | + """ |
| 496 | + if not data: |
| 497 | + return |
| 498 | + fig.add_trace(go.Box(y=data, name=name, marker_color=color)) |
0 commit comments