Add tensorboard support for segmentation metrics.#412
Add tensorboard support for segmentation metrics.#412Abdul-Mukit wants to merge 1 commit intoroboflow:developfrom
Conversation
|
Hi @isaacrob-roboflow do you have any comments on this PR? |
60b16c1 to
523f9df
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds TensorBoard logging support for segmentation metrics in RF-DETR. When training segmentation models (e.g., RFDETRSegPreview), mask-related metrics (AP50_90, AP50, AR50_90) are now logged to TensorBoard alongside the existing bounding box metrics. The change also renames the bbox metric paths from "Metrics/" to "Metrics-BBox/" for clarity and consistency.
Changes:
- Added segmentation mask metrics logging to TensorBoard (test_coco_eval_masks and ema_test_coco_eval_masks)
- Renamed bbox metrics paths from "Metrics/" to "Metrics-BBox/" for better organization
- New mask metrics logged under "Metrics-Masks/" path structure
| if 'test_coco_eval_masks' in values: | ||
| coco_eval = values['test_coco_eval_masks'] | ||
| ap50_90 = safe_index(coco_eval, 0) | ||
| ap50 = safe_index(coco_eval, 1) | ||
| ar50_90 = safe_index(coco_eval, 8) | ||
| if ap50_90 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/Base/AP50_90", ap50_90, epoch) | ||
| if ap50 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/Base/AP50", ap50, epoch) | ||
| if ar50_90 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/Base/AR50_90", ar50_90, epoch) | ||
|
|
||
| if 'ema_test_coco_eval_masks' in values: | ||
| ema_coco_eval = values['ema_test_coco_eval_masks'] | ||
| ema_ap50_90 = safe_index(ema_coco_eval, 0) | ||
| ema_ap50 = safe_index(ema_coco_eval, 1) | ||
| ema_ar50_90 = safe_index(ema_coco_eval, 8) | ||
| if ema_ap50_90 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/EMA/AP50_90", ema_ap50_90, epoch) | ||
| if ema_ap50 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/EMA/AP50", ema_ap50, epoch) | ||
| if ema_ar50_90 is not None: | ||
| self.writer.add_scalar("Metrics-Masks/EMA/AR50_90", ema_ar50_90, epoch) |
There was a problem hiding this comment.
The segmentation metrics logging in MetricsTensorBoardSink is implemented correctly, but MetricsWandBSink (lines 200-267) also needs the same support for consistency. When training segmentation models with W&B logging enabled, users will not see mask metrics logged to Weights & Biases.
Consider adding the same segmentation metrics support to MetricsWandBSink with the same pattern. The implementation would be similar but using the wandb log_dict pattern instead of writer.add_scalar. This ensures feature parity across all logging backends.
| self.writer.add_scalar("Metrics-BBox/Base/AP50_90", ap50_90, epoch) | ||
| if ap50 is not None: | ||
| self.writer.add_scalar("Metrics/Base/AP50", ap50, epoch) | ||
| self.writer.add_scalar("Metrics-BBox/Base/AP50", ap50, epoch) | ||
| if ar50_90 is not None: | ||
| self.writer.add_scalar("Metrics/Base/AR50_90", ar50_90, epoch) | ||
| self.writer.add_scalar("Metrics-BBox/Base/AR50_90", ar50_90, epoch) | ||
|
|
||
| if 'ema_test_coco_eval_bbox' in values: | ||
| ema_coco_eval = values['ema_test_coco_eval_bbox'] | ||
| ema_ap50_90 = safe_index(ema_coco_eval, 0) | ||
| ema_ap50 = safe_index(ema_coco_eval, 1) | ||
| ema_ar50_90 = safe_index(ema_coco_eval, 8) | ||
| if ema_ap50_90 is not None: | ||
| self.writer.add_scalar("Metrics/EMA/AP50_90", ema_ap50_90, epoch) | ||
| self.writer.add_scalar("Metrics-BBox/EMA/AP50_90", ema_ap50_90, epoch) | ||
| if ema_ap50 is not None: | ||
| self.writer.add_scalar("Metrics/EMA/AP50", ema_ap50, epoch) | ||
| self.writer.add_scalar("Metrics-BBox/EMA/AP50", ema_ap50, epoch) | ||
| if ema_ar50_90 is not None: | ||
| self.writer.add_scalar("Metrics/EMA/AR50_90", ema_ar50_90, epoch) | ||
| self.writer.add_scalar("Metrics-BBox/EMA/AR50_90", ema_ar50_90, epoch) |
There was a problem hiding this comment.
Inconsistent metric naming between TensorBoard and W&B logging. MetricsTensorBoardSink uses "Metrics-BBox/" prefix (lines 150, 152, 154, 162, 164, 166) while MetricsWandBSink uses "Metrics/" prefix (lines 243, 245, 247, 255, 257, 259).
For consistency across logging backends, consider updating MetricsWandBSink to also use "Metrics-BBox/" instead of "Metrics/" when logging bbox metrics, matching the TensorBoard naming convention established in this PR.
Description
Closes: #411
While training RFDETRSegPreview, the plots in tensorboard still only contain metrics related to BBox. Plots of segmentation metrics are missing.
In order to support this, the class MetricsTensorBoardSink needs to be enhanced.
Expected behavior when training segmentation models:
Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Google Colab.
Any specific deployment considerations
None
Docs
None