morphoclass.report.xai module

XAI report creation.

class morphoclass.report.xai.XAIReport(output_dir: Union[str, os.PathLike])

Bases: object

XAI report manager.

add_figure(fig: matplotlib.figure.Figure, name: str)pathlib.Path

Add a new figure to the report.

The figure will be kept in memory until the write() call. It is only when write() is called that the figures will be written to disk together with the actual report.

This method returns a path that can be used to reference the figure image file on disk.

Parameters
  • fig – A matplotlib figure.

  • name – The name of the figure. This will be used as the file name of the image file saved to disk. The name should not contain a file extension - it will be added automatically.

Returns

The path under which the image will be stored on disk. This path is relative to the base directory for reproducibility reasons and can be used to refer to the figure image file in HTML blocks.

Return type

pathlib.Path

add_section(title: str, _id: str, section_html: str)None

Add a new XAI section to the report.

write(file_stem: str)None

Render and write the XAI report to disk.

morphoclass.report.xai.populate_report(training_log: morphoclass.training.training_log.TrainingLog, xai_report: morphoclass.report.xai.XAIReport)morphoclass.report.xai.XAIReport

Generate XAI report.

GradCam and GradShap are available for the morphoclass models only. SHAP is available for ML models (sklearn).

The report will store the explanation plots for the best and worst class representatives based on the prediction probability.

Parameters
  • training_log – The training log with the data and model information.

  • xai_report – The XAI report to populate.

Returns

The generated XAI report.

Return type

XAIReport