在我运行yolov5的时候程序是一直在运行,但总是报这个错误
Exception in thread Thread-607:
Traceback (most recent call last):
File "/opt/conda/envs/yolo_v5/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/conda/envs/yolo_v5/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/djtu22/wym1/yolov5-master/utils/plots.py", line 290, in plot_images
annotator.box_label(box, label, color=color)
File "/djtu22/wym1/yolov5-master/utils/plots.py", line 91, in box_label
w, h = self.font.getsize(label) # text width, height (WARNING: deprecated) in 9.2.0
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
Exception in thread Thread-608:
Traceback (most recent call last):
File "/opt/conda/envs/yolo_v5/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/conda/envs/yolo_v5/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/djtu22/wym1/yolov5-master/utils/plots.py", line 290, in plot_images
annotator.box_label(box, label, color=color)
File "/djtu22/wym1/yolov5-master/utils/plots.py", line 91, in box_label
w, h = self.font.getsize(label) # text width, height (WARNING: deprecated) in 9.2.0
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
这是因为安装了新版本的 Pillow (10),pip install tf-models-official删除了该getsize 功能
,降级到 Pillow 9.5 解决了该问题
可以尝试以下方法进行解决:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow==9.5