win10系统,python=3.9
1、AttributeError: Can't get attribute 'ELAN1'
这个错误消息通常发生在代码尝试反序列化在指定模块中找不到的对象或类时。在这种情况下,代码似乎正在尝试访问 models.common
模块中名为 ELAN1
的属性或类,但它在那里不存在。
这是因为下载代码时没有下载最新版,按照我平常的习惯会首选去下载发布版本的代码。
遇到这个错误到官网https://github.com/WongKinYiu/yolov9.git去重新下载新的代码就可以了。
2、TypeError: __init__() missing 1 required positional argument: 'c4'
这个错误提示表示在代码的执行过程中,某个类的构造函数(__init__()
方法)在被调用时缺少了一个必需的位置参数 c4
。
同样的原因,换上最新代码就可以解决。
3、AttributeError: ‘list‘ object has no attribute ‘view‘
尝试调用属于列表上其他数据类型的方法时,会发生错误 AttributeError: 'list' object has no attribute 'view
'。
解决办法是修改YOLOV9的模型yaml文件
DualDDetect------>Detect
或者改用val_dual.py训练文件进行训练。
train.py是无“辅助分支”训练用的脚本,train_dual.py是含有辅助训练分支用的脚本!
4、AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
这个问题出现是因为 getsize()
方法在 PIL (Pillow) 库的最新版本中已被弃用。如果报错后无法继续运行。
可以更换环境里的Pillow包
pip install Pillow==9.5
或者
将 font.getsize(text)
替换为 font.getbbox(text)
或 font.textsize(text)。
def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
# Add one xyxy box to image with label
if self.pil or not is_ascii(label):
self.draw.rectangle(box, width=self.lw, outline=color) # box
if label:
w, h = self.font.getsize(label) # text width, height
outside = box[1] - h >= 0 # label fits outside box
self.draw.rectangle(
(box[0], box[1] - h if outside else box[1], box[0] + w + 1,
box[1] + 1 if outside else box[1] + h + 1),
fill=color,
)
///
def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
# Add one xyxy box to image with label
if self.pil or not is_ascii(label):
self.draw.rectangle(box, width=self.lw, outline=color) # box
if label:
w, h = self.font.textsize(label) # text width, height
outside = box[1] - h >= 0 # label fits outside box
self.draw.rectangle(
(box[0], box[1] - h if outside else box[1], box[0] + w + 1,
box[1] + 1 if outside else box[1] + h + 1),
fill=color,
)
def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
# Add one xyxy box to image with label
if self.pil or not is_ascii(label):
self.draw.rectangle(box, width=self.lw, outline=color) # box
if label:
bbox = self.font.getbbox(label)
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1] # text width, height
outside = box[1] - h >= 0 # label fits outside box
self.draw.rectangle(
(box[0], box[1] - h if outside else box[1], box[0] + w + 1,
box[1] + 1 if outside else box[1] + h + 1),
fill=color,
)
我在运行过程中,虽然报错了,但是可以继续运行。