labelImg下载标注常见报错

报错一:

  File "E:\apps\anaconda3\envs\label\Lib\site-packages\labelImg\labelImg.py", line 1557, in load_yolo_txt_by_filename
    t_yolo_parse_reader = YoloReader(txt_path, self.image)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\yolo_io.py", line 112, in __init__
    self.parse_yolo_format()
  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\yolo_io.py", line 143, in parse_yolo_format
    label, x_min, y_min, x_max, y_max = self.yolo_line_to_shape(class_index, x_center, y_center, w, h)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\yolo_io.py", line 125, in yolo_line_to_shape
    label = self.classes[int(class_index)]

解决方法:

        在...\envs\label\Lib\site-packages\libs\yolo_io.py文件中124行添加下方代码:

# 在 yolo_io.py 文件中
def yolo_line_to_shape(self, class_index, x_center, y_center, w, h):
    # 添加调试信息
    if int(class_index) >= len(self.classes):
        print(f"Error: class_index {class_index} is out of range for classes list of length {len(self.classes)}")
        raise IndexError("class_index is out of range")
    
    label = self.classes[int(class_index)]
    # ... 其他代码 ...

报错二:

  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\yolo_io.py", line 148, in parse_yolo_format
    label, x_min, y_min, x_max, y_max = self.yolo_line_to_shape(class_index, x_center, y_center, w, h)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\yolo_io.py", line 128, in yolo_line_to_shape
    raise IndexError("class_index is out of range")
IndexError: class_index is out of rang

解决方法:        

        检查标签.txt文件和存标签的文件夹中classes.txt内容是否一致,不一致则更正为一致的。

报错三:

  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\shape.py", line 131, in paint
    painter.drawText(min_x, min_y, self.label)
TypeError: arguments did not match any overloaded call:
  drawText(self, p: Union[QPointF, QPoint], s: Optional[str]): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRectF, flags: int, text: Optional[str]): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRect, flags: int, text: Optional[str]): argument 1 has unexpected type 'float'
  drawText(self, rectangle: QRectF, text: Optional[str], option: QTextOption = QTextOption()): argument 1 has unexpected type 'float'
  drawText(self, p: QPoint, s: Optional[str]): argument 1 has unexpected type 'float'
  drawText(self, x: int, y: int, width: int, height: int, flags: int, text: Optional[str]): argument 1 has unexpected type 'float'
  drawText(self, x: int, y: int, s: Optional[str]): argument 1 has unexpected type 'float'

解决方法:

        找到...\envs\label\Lib\site-packages\libs\shape.py文件,第131行,改为下方代码:

def paint(self, painter):
    # ... existing code ...
    painter.drawText(int(min_x), int(min_y), self.label)  # 转换为整数
    # ... existing code ...

报错三:

Traceback (most recent call last):
  File "E:\apps\anaconda3\envs\label\Lib\site-packages\labelImg\labelImg.py", line 965, in scroll_request
    bar.setValue(bar.value() + bar.singleStep() * units)
TypeError: setValue(self, a0: int): argument 1 has unexpected type 'float'

解决方案:

        找到...\envs\label\Lib\site-packages\labelImg\labelImg.py文件,第965行,参照下方代码改正:

def scroll_request(self, units):
    # ... existing code ...
    bar.setValue(int(bar.value() + bar.singleStep() * units))  # 转换为整数
    # ... existing code ...

报错四:

  File "E:\apps\anaconda3\envs\label\Lib\site-packages\libs\canvas.py", line 530, in paintEvent
    p.drawLine(self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())
TypeError: arguments did not match any overloaded call:
  drawLine(self, l: QLineF): argument 1 has unexpected type 'float'
  drawLine(self, line: QLine): argument 1 has unexpected type 'float'
  drawLine(self, x1: int, y1: int, x2: int, y2: int): argument 1 has unexpected type 'float'
  drawLine(self, p1: QPoint, p2: QPoint): argument 1 has unexpected type 'float'
  drawLine(self, p1: Union[QPointF, QPoint], p2: Union[QPointF, QPoint]): argument 1 has unexpected type 'float'

解决方法:

        找到...\anaconda3\envs\label\Lib\site-packages\libs\canvas.py文件,第526、530、531行,分别按照以下代码更正:

def paintEvent(self, event):

    # ... existing code ...
    p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))  # 转换为整数
    # ... existing code ...

    p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))  # 转换为整数
    # ... existing code ...

    p.drawLine(0, int(self.prev_point.y()), int(self.pixmap.width()), int(self.prev_point.y()))  # 转换为整数
    # ... existing code ...

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值