Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freetype font and pillow #13498

Open
vahidajalluian opened this issue Jan 23, 2025 · 2 comments
Open

freetype font and pillow #13498

vahidajalluian opened this issue Jan 23, 2025 · 2 comments
Labels
bug Something isn't working dependencies Dependencies and packages

Comments

@vahidajalluian
Copy link

It seems in Pillow library version over 9.5 getsize method has been removed. So either change the method or limit the library to be installed to 9.5.
Here is the log I get for now.

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/vahidajalluian/yolov5-7.0/utils/plots.py", line 305, in plot_images
    annotator.box_label(box, label, color=color)
  File "/home/vahidajalluian/yolov5-7.0/utils/plots.py", line 91, in box_label
    w, h = self.font.getsize(label)  # text width, height
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
Exception in thread Thread-6 (plot_images):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/vahidajalluian/yolov5-7.0/utils/plots.py", line 305, in plot_images
    annotator.box_label(box, label, color=color)
  File "/home/vahidajalluian/yolov5-7.0/utils/plots.py", line 91, in box_label
    w, h = self.font.getsize(label)  # text width, height
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working dependencies Dependencies and packages labels Jan 23, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @vahidajalluian, thank you for bringing up this issue and for your interest in YOLOv5 🚀! It seems you’ve encountered a compatibility issue related to the getsize method in the Pillow library that's affecting the FreeTypeFont class.

Next Steps:

If this is a 🐛 Bug Report, could you please provide a minimum reproducible example (MRE) that demonstrates this issue? This will help us reproduce and debug the problem more effectively. The MRE should include:

  • The YOLOv5 version (commit hash, if possible) you are using.
  • The exact steps/commands you ran leading up to the error.
  • Your current environment details — OS, Python version, and dependencies (e.g., pip freeze output).
  • Any additional context that might help us investigate.

Temporary Workaround:

Until this issue is resolved, you may try using a specific version of Pillow (<= 9.5.0) as a workaround:

pip install Pillow==9.5.0

Requirements

Ensure your Python and dependencies match our requirements.txt:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 supports running in various environments — you can try switching environments as an alternative:

Source Code Check

To troubleshoot further, you may also review the affected file and line of code where the error is reported:

File "/home/vahidajalluian/yolov5-7.0/utils/plots.py", line 91

You can compare this to the latest version of YOLOv5's utils/plots.py to see if updates or fixes are already available.


This is an automated response to help you get started 😊! An Ultralytics engineer will review your issue and provide further assistance as soon as possible. Thank you for your patience as we work together to ensure a smooth experience with YOLOv5! 🚀

@pderrenger
Copy link
Member

@vahidajalluian thank you for bringing this to our attention! The issue arises because Pillow versions above 9.5 have removed the getsize method from the FreeTypeFont class, replacing it with getbbox. To resolve this, you can either:

  1. Downgrade Pillow to version 9.5 using pip install pillow==9.5.0.
  2. Update the affected part of the code to use getbbox instead of getsize. For example:
w, h = self.font.getbbox(label)[2:]  # text width, height

Please ensure you are using the latest YOLOv5 version as well to avoid other compatibility issues. Let us know if you need further assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Dependencies and packages
Projects
None yet
Development

No branches or pull requests

3 participants