Skip to content

Bug: AttributeError in Colab when using fig.canvas.set_window_title in mAP/main.py #185

@elenamarreroo

Description

@elenamarreroo

Description of the problem

When running mAP/main.py in Google Colab, the following error appears:

AttributeError: 'FigureCanvasAgg' object has no attribute 'set_window_title'

This happens because Colab uses FigureCanvasAgg, which does not implement the method set_window_title().

Affected file

mAP/main.py
Approximate line: 704

Current code:

fig.canvas.set_window_title('AP ' + class_name)

Proposed solution
Replace that line with a Colab-compatible alternative:

  # Try to set window title (works on desktop environments)
  try:
      fig.canvas.set_window_title('AP ' + class_name)
  except Exception:
      # Fallback for Colab / Jupyter / FigureCanvasAgg
      fig.canvas.manager.set_window_title('AP ' + class_name)

This ensures that:

  • The script still works in environments with a window manager.
  • Google Colab does not throw an error.
  • The figure retains a proper title.

Additional notes

This bug occurs at the end of the mAP evaluation process, right when the AP curves for each class are generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions