WongKinYiu / yolov9

Implementation of paper - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
GNU General Public License v3.0
9.04k stars 1.44k forks source link

AttributeError: 'FreeTypeFont' object has no attribute 'getsize' #33

Open Hezhing opened 9 months ago

Hezhing commented 9 months ago

When I started training, I had the following problems, and then I started training normally. Is this normal?

Starting training for 100 epochs...

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
   0/99      3.01G      5.309      6.831      5.464         28        640:   0%|          | 0/3520 00:14Exception in thread Thread-7:

Traceback (most recent call last): File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 870, in run self._target(*self._args, self._kwargs) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 300, in plot_images annotator.box_label(box, label, color=color) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 86, in box_label w, h = self.font.getsize(label) # text width, height AttributeError: 'FreeTypeFont' object has no attribute 'getsize' WARNING ⚠️ TensorBoard graph visualization failure Only tensors, lists, tuples of tensors, or dictionary of tensors can be output from traced functions 0/99 3.53G 4.76 6.78 5.595 165 640: 0%| | 2/3520 00:18Exception in thread Thread-10: Traceback (most recent call last): File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 870, in run self._target(*self._args, *self._kwargs) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 300, in plot_images annotator.box_label(box, label, color=color) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 86, in box_label w, h = self.font.getsize(label) # text width, height AttributeError: 'FreeTypeFont' object has no attribute 'getsize' 0/99 3.53G 4.231 6.698 5.599 42 640: 0%| | 3/3520 00:19Exception in thread Thread-13: Traceback (most recent call last): File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/home/Users/anaconda3/envs/detr/lib/python3.8/threading.py", line 870, in run self._target(self._args, self._kwargs) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 300, in plot_images annotator.box_label(box, label, color=color) File "/home/Users/桌面/yolov9-main/utils/plots.py", line 86, in box_label w, h = self.font.getsize(label) # text width, height AttributeError: 'FreeTypeFont' object has no attribute 'getsize' 0/99 4.48G 4.757 7.121 5.501 67 640: 8%|▊ | 289/3520 03:37

WongKinYiu commented 9 months ago

You may need reinstall your Pillow, for example pip install Pillow==9.5.0.

Hezhing commented 9 months ago

Thank you, it was very useful and has been resolved

moralesja560 commented 9 months ago

Hi, I use YOLO for an industrial application, and I wanted to collaborate:

I replaced line 86 in plots.py:

w, h = self.font.getsize(label) # text width, height

I read in the PIL docs that getsize is now deprecated and was replaced by ImageFont.getbbox() and ImageFont.getlength().

In the source code of getbbox, shows that it returns 4 elements:

return 0, 0, width, height

So I did this:

unused1,unused2,w, h = self.font.getbbox(label) # text width, height

And the error was solved.

I apologize in advance if I'm commenting in a closed thread. Have a great day.

mkrupczak3 commented 8 months ago

Recommend re-opening this issue, either until a patch is merged in or requirements.txt specifies this version. If installing yolov9 with the existing requirements.txt, this error will always occur

You may need reinstall your Pillow, for example pip install Pillow==9.5.0.

mkrupczak3 commented 8 months ago

Related to PR #97

KazuhideMimura commented 1 month ago

Hi, I recommend @moralesja560 's solution rather than downgrading pillow.

When I ran the program with version 9.5.0 of pillow, it abruptly terminated without outputting any error messages. (environment: torch2.3.1, torchvision0.18.1). It seems that pilllow 9.5.0 is sometimes incompatible with new torchvision. (https://github.com/pytorch/vision/issues/7660)

marslo commented 1 week ago

+1