Source: dvc/api/show.py:35-153
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 indvc.yaml. This function provides programmatic access to these metrics for analysis, comparison, and reporting.
Signature
Parameters
Names of the metric files to retrieve metrics from (positional arguments).
- If no targets are provided, all metric files tracked in
dvc.yamlwill be used - Targets don’t necessarily have to be defined in
dvc.yaml - Can specify multiple files
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
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
repois not a Git repo, this option is ignored
Config dictionary to be passed through to the DVC project.
Returns
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
- JSON
- YAML
- TOML
- Plain Text
Return Value Structure
Single metrics file
Single metrics file
When retrieving metrics from a single file, the structure matches the file content:
Multiple files (unique keys)
Multiple files (unique keys)
When metric keys are unique across files, they’re merged:
Multiple files (conflicting keys)
Multiple files (conflicting keys)
When keys conflict, they’re prefixed with the filename:
Configuring Metrics in dvc.yaml
Best Practices
Use structured formats
Use structured formats
Store metrics in JSON or YAML for easy access:
Compare against baselines
Compare against baselines
Always compare new metrics against established baselines:
Track multiple metrics
Track multiple metrics
Track comprehensive metrics, not just accuracy:
Handle missing metrics gracefully
Handle missing metrics gracefully
Use
.get() with defaults:Integration Examples
MLflow Integration
Weights & Biases Integration
Slack Notification
Related Functions
params_show()
Retrieve parameters values
exp_show()
Show experiments with metrics
read()
Read any tracked file