Skip to content

Notebook to Report Conversion

convert_to_wandb_report(filepath, wandb_project, wandb_entity, report_title='Untitled Report', description='', width='readable')

Convert an IPython Notebook to a Weights & Biases Report.

Usage:

nb2report \
    --filepath Use_WandbMetricLogger_in_your_Keras_workflow.ipynb \
    --wandb_project report-to-notebook \
    --wandb_entity geekyrakshit \
    --report_title "Use WandbMetricLogger in your Keras Workflow" \
    --description "A guide to using the WandbMetricLogger callback in your Keras and TensorFlow training worflow" \
    --width "readable"
from wandb_addons.report import convert_to_wandb_report

convert_to_wandb_report(
    filepath="Use_WandbMetricLogger_in_your_Keras_workflow.ipynb",
    wandb_project="report-to-notebook",
    wandb_entity="geekyrakshit",
    report_title="Use WandbMetricLogger in your Keras Workflow",
    description="A guide to using the WandbMetricLogger callback in your Keras and TensorFlow training worflow",
    width="readable"
)

Note

In order to include panel grids with runsets and line plots in your report, you need to include YAML metadata regarding the runsets and line plots you want to include in a panel grid in a markdown cell of your notebook in the following format:

---
panelgrid:
runsets:
- project: report-to-notebook
    entity: geekyrakshit
    name: Training-Logs
lineplots:
- x: batch/batch_step
    y: batch/accuracy
- x: batch/batch_step
    y: batch/learning_rate
- x: batch/batch_step
    y: batch/loss
- x: batch/batch_step
    y: batch/top@5_accuracy
- x: epoch/epoch
    y: epoch/accuracy
- x: epoch/epoch
    y: epoch/learning_rate
- x: epoch/epoch
    y: epoch/loss
- x: epoch/epoch
    y: epoch/top@5_accuracy
- x: epoch/epoch
    y: epoch/val_accuracy
- x: epoch/epoch
    y: epoch/val_loss
- x: epoch/epoch
    y: epoch/val_top@5_accuracy
---

Currently only line plots are supported inside panel grids.

Converting using CLI

Convert an IPython notebook to a Weights & Biases report using the nb2report CLI:

Usage: nb2report [OPTIONS]

Options:
--filepath TEXT       Path to an IPython notebook
--wandb_project TEXT  The name of the Weights & Biases project where you're
                        creating the project
--wandb_entity TEXT   The name of the Weights & Biases entity (username or
                        team name)
--report_title TEXT   The title of the report
--description TEXT    The description of the report
--width TEXT          Width of the report, one of `'readable'`, `'fixed'`,
                        or `'fluid'`
--help                Show this message and exit.

Example

Here is a report was generated for this notebook.

Parameters:

Name Type Description Default
filepath str

Path to an IPython notebook.

required
wandb_project str

The name of the Weights & Biases project where you're creating the project.

required
wandb_entity str

The name of the Weights & Biases entity (username or team name).

required
report_title Optional[str]

The title of the report.

'Untitled Report'
description Optional[str]

The description of the report.

''
width Optional[str]

Width of the report, one of "readable", "fixed", or "fluid".

'readable'
Source code in wandb_addons/report/notebook_convert.py
def convert_to_wandb_report(
    filepath: str,
    wandb_project: str,
    wandb_entity: str,
    report_title: Optional[str] = "Untitled Report",
    description: Optional[str] = "",
    width: Optional[str] = "readable",
):
    """Convert an IPython Notebook to a [Weights & Biases Report](https://docs.wandb.ai/guides/reports).

    **Usage:**

    === "CLI"
        ```shell
        nb2report \\
            --filepath Use_WandbMetricLogger_in_your_Keras_workflow.ipynb \\
            --wandb_project report-to-notebook \\
            --wandb_entity geekyrakshit \\
            --report_title "Use WandbMetricLogger in your Keras Workflow" \\
            --description "A guide to using the WandbMetricLogger callback in your Keras and TensorFlow training worflow" \\
            --width "readable"
        ```

    === "Python API"
        ```python
        from wandb_addons.report import convert_to_wandb_report

        convert_to_wandb_report(
            filepath="Use_WandbMetricLogger_in_your_Keras_workflow.ipynb",
            wandb_project="report-to-notebook",
            wandb_entity="geekyrakshit",
            report_title="Use WandbMetricLogger in your Keras Workflow",
            description="A guide to using the WandbMetricLogger callback in your Keras and TensorFlow training worflow",
            width="readable"
        )
        ```


    !!! note
        In order to include panel grids with runsets and line plots in your report, you need to include
        YAML metadata regarding the runsets and line plots you want to include in a panel grid in a
        markdown cell of your notebook in the following format:

        ```yaml
        ---
        panelgrid:
        runsets:
        - project: report-to-notebook
            entity: geekyrakshit
            name: Training-Logs
        lineplots:
        - x: batch/batch_step
            y: batch/accuracy
        - x: batch/batch_step
            y: batch/learning_rate
        - x: batch/batch_step
            y: batch/loss
        - x: batch/batch_step
            y: batch/top@5_accuracy
        - x: epoch/epoch
            y: epoch/accuracy
        - x: epoch/epoch
            y: epoch/learning_rate
        - x: epoch/epoch
            y: epoch/loss
        - x: epoch/epoch
            y: epoch/top@5_accuracy
        - x: epoch/epoch
            y: epoch/val_accuracy
        - x: epoch/epoch
            y: epoch/val_loss
        - x: epoch/epoch
            y: epoch/val_top@5_accuracy
        ---
        ```

        Currently only line plots are supported inside panel grids.

    !!! note "Converting using CLI"
        Convert an IPython notebook to a Weights & Biases report using the `nb2report` CLI:

        ```shell
        Usage: nb2report [OPTIONS]

        Options:
        --filepath TEXT       Path to an IPython notebook
        --wandb_project TEXT  The name of the Weights & Biases project where you're
                                creating the project
        --wandb_entity TEXT   The name of the Weights & Biases entity (username or
                                team name)
        --report_title TEXT   The title of the report
        --description TEXT    The description of the report
        --width TEXT          Width of the report, one of `'readable'`, `'fixed'`,
                                or `'fluid'`
        --help                Show this message and exit.
        ```

    !!! example "Example"
        [Here](https://wandb.ai/geekyrakshit/report-to-notebook/reports/Use-WandbMetricLogger-in-your-Keras-Workflow--Vmlldzo0Mjg4NTM2) is a report was generated for [this](https://github.com/wandb/examples/blob/master/colabs/keras/Use_WandbMetricLogger_in_your_Keras_workflow.ipynb) notebook.

    Args:
        filepath (str): Path to an IPython notebook.
        wandb_project (str): The name of the Weights & Biases project where you're creating the project.
        wandb_entity (str): The name of the Weights & Biases entity (username or team name).
        report_title (Optional[str]): The title of the report.
        description (Optional[str]): The description of the report.
        width (Optional[str]): Width of the report, one of `"readable"`, `"fixed"`, or `"fluid"`.
    """
    notebook_cells = _parse_notebook_cells(filepath)

    report = wr.Report(
        project=wandb_project,
        title=report_title,
        entity=wandb_entity,
        description=description,
        width=width,
    )

    blocks = []
    for cell in tqdm(notebook_cells, desc="Converting notebook cells to report cells"):
        if cell["type"] == "markdown":
            blocks.append(wr.MarkdownBlock(text=cell["source"]))
        elif cell["type"] == "code":
            blocks.append(wr.MarkdownBlock(text=f"```python\n{cell['source']}\n```"))
        elif cell["type"] == "panel_metadata":
            blocks.append(_convert_metadata_to_panelgrid(metadata=cell["source"]))

    report.blocks = blocks
    report.save()
    wandb.termlog(
        "Report {report_title} created successfully. "
        + f"Check list of reports at {report.url}."
    )