> For the complete documentation index, see [llms.txt](https://docs.rhinofcp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rhinofcp.com/creating-and-running-code-objects/visualizing-and-measuring-machine-learning-model-performance-with-tensorboard.md).

# Visualizing and Measuring Machine Learning Model Performance with Tensorboard

To help you improve a machine learning model, you can visualize and monitor performance metrics like accuracy and loss on various datasets, such as the training and test sets. Rhino FCP integrates Tensorboard, which is an industry-standard tool for visualization. Tensorboard lets you compare different model versions to select the best-performing candidate, debug poor performance by identifying potential hyperparameter issues, and monitor the training process in real-time to decide when to halt a training run, such as when the model fails to converge over a long period.

With Tensorboard you can:

* Track and visualize metrics such as loss and accuracy
* View model graphs
* Examine histograms of weights, biases, or other tensors
* Display images, text, and audio data

You can securely visualize data from a single Rhino FCP client, from multiple clients, and from the server. You can also view aggregated data from multiple training runs.

### Prerequisites

You will need to the following view Tensorboard on FCP:

* Access to the workgroup
* Access to the project
* Permission to view the analytics of code runs

{% stepper %}
{% step %}

### Specify What Data To Display in Tensorboard

To specify what you want to appear in Tensorboard, you'll need to add a few lines to your code. Typically, we recommend that you import SummaryWriter from the tensorboardX library because it is lightweight, provides only tools for writing TensorBoard logs, and does not require that you install TensorFlow.

{% hint style="info" %}
NOTE: If you are coding NVFlare, it has built-in support for Tensorboard logs (as well as MLFlow and Weights and Biases), so you will not need to complete these steps. Since NVFlare's implementation sends logs to an external server, and Rhino FCP considers the data in these logs to be potentially sensitive, so it is stored locally and is protected by our Secure Access features. For an example of how to specify data to display using NVFlare, see our example in the user resources in the Rhino FCP NVFlare (MIMIC CXR NVFLARE for versions 2.3, 2.4, and 2.5).
{% endhint %}

For an example of how to use SummaryWriter from tensorboardX in your library, see the following.

{% stepper %}
{% step %}
Define a writer that points to the folder where you want the logs to be written, like this.

```auto
from tensorboardX import SummaryWriter

def __init__():
   #add this additional line
   self.tb_writer = SummaryWriter("/tb-logs")
```

{% endstep %}

{% step %}
Add the items you want to see on TensorBoard using the summary writer. In the following example, the items are added using the writer's add\_scalar function.

```auto
def model_training_function():
   #add logging during training for each epoch, and optionally flush at the end of training
   for epoch in range(self._epochs):
      self.tb_writer.add_scalar("local_train_loss_per_epoch", running_loss / images_count,
   self.epoch_global)
   self.tb_writer.flush()

def model_validation_function():
   #add logging for specific model validation metric, e.g.,
   self.tb_writer.add_scalar("global_model_test_loss_per_round", average_loss, current_round)
```

{% endstep %}

{% step %}
Finally, run the code, using one of the following instructions for running a code object: [Python](/creating-and-running-code-objects/creating-and-running-a-python-code-object.md), [Generalized Compute](/creating-and-running-code-objects/creating-and-running-a-new-generalized-compute-code-object.md), [Interactive Container](/creating-and-running-code-objects/creating-and-running-interactive-container-code.md).

For a more comprehensive guide, see this [Tensorboardx Tutorial.](https://tensorboardx.readthedocs.io/en/latest/tutorial.html)
{% endstep %}
{% endstepper %}
{% endstep %}

{% step %}

### Use Tensorboard to View Data from Code Runs

After you've run the code successfully, complete the following steps to view the results on Tensorboard.

{% stepper %}
{% step %}
Create a code object and run the code. Use the guide for your code type.
{% endstep %}

{% step %}
After the code run is completed, select Code Runs from the menu on the left. See one of the following instructions for running a code object: [Python](/creating-and-running-code-objects/creating-and-running-a-python-code-object.md), [Generalized Compute](/creating-and-running-code-objects/creating-and-running-a-new-generalized-compute-code-object.md), [Interactive Container](/creating-and-running-code-objects/creating-and-running-interactive-container-code.md). [Running a Code Object](broken://spaces/ydySyCBmy6F7NnGn4bPa/pages/431e7a0d75a3d7b5e8ccbeea32a5a0e48cfe8695) for more information.

![](/files/fc82fe86c8313ce565fcbedd9879622db52fd6e6)
{% endstep %}

{% step %}
Select the Open Tensorboard button on the upper right corner of the page. The Tensorboard page opens. It might take a few seconds for the dashboard to appear.

![](/files/c57b6860de112a00a42c4460dd7ca310886faaae)
{% endstep %}

{% step %}
There are two different dashboards that you can choose.

* **Time Series** - Displays metrics in each iteration. Choose Time Series if you want to analyze and compare multiple time series data.
* **Scalars** - Displays information at the end of each epoch. Choose Scalars if you need to monitor individual scalar metrics.
  {% endstep %}

{% step %}
Select the code runs you want to review from the options on the left. The top-most option allows you to select all of them at once.
{% endstep %}

{% step %}
Choose whether you want to see scalars, images, or histograms (or some combination of the three.) If you want to see all of them, select All.
{% endstep %}

{% step %}
For more information on individual options, see the [Tensorboard Guide](https://www.tensorflow.org/tensorboard/get_started).
{% endstep %}

{% step %}
Note that the connection to the Rhino FCP Tensorboard is available for two hours after the last time that you interact with it.
{% endstep %}
{% endstepper %}
{% endstep %}
{% endstepper %}
