> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/user-interface/project/network/network-mapping/create-a-mapping-deprecated/metric-node.md).

# Metric Node

The Tensorleap platform allows you to add metrics to be computed in each model evaluation&#x20;

These Metrics are divided into two types:

* Default metrics
  * MeanSquaredError&#x20;
  * MeanSquaredLogarithmicError
  * MeanAbsoluteError
  * MeanAbsolutePercentageError
  * Accuracy
  * BinaryAccuracy
  * MeanIOU
* Custom metrics

{% hint style="success" %}
It is highly recommended to use your own custom metrics in the [integration script](/tensorleap-integration/writing-integration-code.md). This would allow you to test results in your[ local development environment](/tensorleap-integration/integration-test.md) before you upload the model to Tensorleap.  This helps to ensure the metrics return the expected values before the integration
{% endhint %}

### Custom Metric Example

Adding the following metric in your code:

```python
@tensorleap_custom_metric("cost")
def cost(pred80,pred40,pred20,gt):
    gt=np.squeeze(gt,axis=0)
    d={}
    d["bboxes"] = torch.from_numpy(gt[...,:4])
    d["cls"] = torch.from_numpy(gt[...,4])
    d["batch_idx"] = torch.zeros_like(d['cls'])
    y_pred_torch = [torch.from_numpy(s) for s in [pred80,pred40,pred20]]
    _,loss_parts= criterion(y_pred_torch, d)
    return {"box":loss_parts[0].unsqueeze(0).numpy(),"cls":loss_parts[1].unsqueeze(0).numpy(),"dfl":loss_parts[2].unsqueeze(0).numpy()}
```

Would result in the following metric in selectable from the menu:

<figure><img src="/files/nENdOASPiFmrWQyjwxVI" alt=""><figcaption><p>Metric Block</p></figcaption></figure>

{% hint style="info" %}
In order to add a **Custom metric** it must be added to the dataset script and parsed first as described in the&#x20;
{% endhint %}

## Setup

The **Metric** node have several properties:

* **Selected Metric**: a dropdown from which a custom or default metric can be selected. The list would include all registered [custom metrics](/tensorleap-integration/writing-integration-code/custom-metrics.md) from your [integration script](/tensorleap-integration/writing-integration-code.md).
* **Name**: The name of the selected visualizer.
* **Labels**: The expected arguments for your visualizer.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tensorleap.ai/user-interface/project/network/network-mapping/create-a-mapping-deprecated/metric-node.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
