Skip to main content

Description

Retrieves metrics tracked in a DVC repository. Without arguments, this function retrieves all metrics from all tracked metrics files for the current working tree. Metrics are typically stored in JSON, YAML, or other structured formats and tracked in dvc.yaml. This function provides programmatic access to these metrics for analysis, comparison, and reporting.

Signature

Parameters

str
default:"None"
Names of the metric files to retrieve metrics from (positional arguments).
  • If no targets are provided, all metric files tracked in dvc.yaml will be used
  • Targets don’t necessarily have to be defined in dvc.yaml
  • Can specify multiple files
str
default:"None"
Location of the DVC repository.
  • Defaults to the current project (found by walking up from current working directory)
  • Can be a URL or a file system path
  • Both HTTP and SSH protocols are supported for online Git repos
str
default:"None"
Name of the Git revision to retrieve metrics from.
  • Defaults to None (current working tree)
  • Can be a branch name, tag name, commit hash, or DVC experiment name
  • If repo is not a Git repo, this option is ignored
dict
default:"None"
Config dictionary to be passed through to the DVC project.

Returns

dict
A dictionary containing the metrics. The structure depends on the metrics files:
  • Single file: Returns the metrics directly
  • Multiple files with unique keys: Merges metrics from all files
  • Multiple files with conflicting keys: Prefixes keys with filename:key

Examples

Basic Usage - All Metrics

From Specific Git Revision

Specific Metrics Files

Remote Repository

Compare Metrics Across Branches

Compare Against Baseline

Track Model Performance Over Time

Automated Performance Check

Export Metrics to CSV

Handle Multiple Metrics Files

Error Handling

Use Cases

Model Evaluation

Retrieve and compare model performance metrics across experiments.

CI/CD Integration

Automate quality checks based on metrics in deployment pipelines.

Performance Tracking

Track model performance over time across different versions.

Experiment Analysis

Analyze and compare metrics from multiple experiments.

Metrics File Formats

Return Value Structure

When retrieving metrics from a single file, the structure matches the file content:
When metric keys are unique across files, they’re merged:
When keys conflict, they’re prefixed with the filename:

Configuring Metrics in dvc.yaml

Best Practices

Store metrics in JSON or YAML for easy access:
Always compare new metrics against established baselines:
Track comprehensive metrics, not just accuracy:
Use .get() with defaults:

Integration Examples

MLflow Integration

Weights & Biases Integration

Slack Notification

params_show()

Retrieve parameters values

exp_show()

Show experiments with metrics

read()

Read any tracked file