Skip to content

Add optional segmentation metrics plots to MetricsPlotSink.#410

Closed
Abdul-Mukit wants to merge 3 commits intoroboflow:developfrom
Abdul-Mukit:add_masks_to_MetricsPlotSink
Closed

Add optional segmentation metrics plots to MetricsPlotSink.#410
Abdul-Mukit wants to merge 3 commits intoroboflow:developfrom
Abdul-Mukit:add_masks_to_MetricsPlotSink

Conversation

@Abdul-Mukit
Copy link
Copy Markdown
Contributor

Description

Closes: #409
After completing training with RFDETRSegPreview, the plots in metrics_plot.png still only contain metrics related to BBox. Plots of segmentation metrics are missing.

Changes:

  • If RFDETRSegPreview is trained, plot the masks-related metrics.
  • If any other BBox-only models are being trained (e.g., RFDETRMedium ), plot only the BBox-related metrics.

Current behavior of MetricsPlotSink:
Even when training a RFDETRSegPreview, we only get plots for BBox metrics.
Image

Updated behavior of MetricsPlotSink:
Image

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

Tested on Google Colab for both RFDETRMedium and RFDETRSegPreview.

Any specific deployment considerations

None

Docs

None

@Abdul-Mukit
Copy link
Copy Markdown
Contributor Author

Hi @isaacrob-roboflow do you have any comments on this PR?
I am using this feature for my experiments. It would be helpful if this were part of the rfdeter repo.
Please let me know if you want any modifications. Thank you.

@Borda Borda added the enhancement New feature or request label Jan 22, 2026
@Borda Borda requested a review from isaacrob as a code owner February 11, 2026 15:57
@Borda Borda force-pushed the develop branch 4 times, most recently from 60b16c1 to 523f9df Compare February 14, 2026 06:46
@Abdul-Mukit
Copy link
Copy Markdown
Contributor Author

I'll resume this. Please let me know if not needed anymore or if it causes any conflicts with your plans.

@Borda Borda self-requested a review as a code owner March 13, 2026 15:24
@Borda Borda force-pushed the develop branch 2 times, most recently from a6e6ca0 to 0485141 Compare March 13, 2026 17:07
@Borda Borda marked this pull request as draft March 17, 2026 12:51
@Borda
Copy link
Copy Markdown
Member

Borda commented Mar 17, 2026

@Abdul-Mukit thank you for this PR, could you pls revisit the updated codebase, pls...

@Borda Borda marked this pull request as ready for review March 17, 2026 15:18
Copilot AI review requested due to automatic review settings March 17, 2026 15:18
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 83.87097% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 75%. Comparing base (63ed3d8) to head (dd90a06).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #410    +/-   ##
=======================================
  Coverage       75%    75%            
=======================================
  Files           91     92     +1     
  Lines         6836   6962   +126     
=======================================
+ Hits          5109   5215   +106     
- Misses        1727   1747    +20     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an automatic post-training metrics plot generator to RF-DETR Lightning training runs, with the goal of including segmentation metrics (when present) in metrics_plot.png.

Changes:

  • Introduces MetricsPlotCallback to parse metrics.csv and write metrics_plot.png, expanding the plot layout when segmentation metrics exist.
  • Wires MetricsPlotCallback into build_trainer()’s callback stack so it runs after training.
  • Exports the new callback from rfdetr.training.callbacks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/rfdetr/training/trainer.py Registers MetricsPlotCallback in the default PTL callback stack.
src/rfdetr/training/callbacks/metrics_plot.py New callback that reads CSVLogger output and generates bbox-only or bbox+segm plots.
src/rfdetr/training/callbacks/__init__.py Exposes MetricsPlotCallback via the callbacks package API.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/rfdetr/training/callbacks/metrics_plot.py
Comment thread src/rfdetr/training/callbacks/metrics_plot.py
Comment on lines +67 to +86
class MetricsPlotCallback(Callback):
"""Read ``metrics.csv`` written by CSVLogger and save a metrics figure.

Generates a 2×2 grid for detection-only models, or a 3×2 grid when
segmentation metrics are present in the log.

The plot is saved to ``{output_dir}/metrics_plot.png`` after training ends.
"""

def on_train_end(self, trainer: Any, pl_module: Any) -> None:
"""Save the metrics plot when training completes."""
csv_path = self._find_csv(trainer)
if csv_path is None:
return
history = self._read_csv(csv_path)
if not history:
return
output_dir = Path(trainer.default_root_dir)
self._save_plot(history, output_dir)

Comment thread src/rfdetr/training/trainer.py Outdated
Comment thread src/rfdetr/training/callbacks/metrics_plot.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Borda Borda marked this pull request as draft March 17, 2026 16:38
@Abdul-Mukit
Copy link
Copy Markdown
Contributor Author

I'll close the MR. Apologies for the delay. I saw your comment on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add segmentation metrics plots to metrics_plot.png.

3 participants