找回密码
 立即注册
老冷培训班汇总介绍老冷付费工具汇总介绍老鬼UI编程学院EasyClick所有产品简介EasyClick官方交流群
IOS授权价格IOS/安卓 自助提卡链接安卓-中控群控-电脑授权-购买IOSusb版投屏群控教程IOS脱机版激活教程
IOS脱机版wifi局域网脚本中控教程IOS脱机版wifi局域网群控投屏教程远程调试frp,兼容安卓/IOS热更新工具,兼容安卓/IOS脱机版老冷网盘
查看: 324|回复: 0

[解决方法] 【YOLO】labeling第二次打开闪退解决方法

[复制链接] |主动推送

1129

主题

151

回帖

4万

积分

管理员

【导师】

积分
42522
最后登录
2025-3-29
在线时间
1839 小时

兔年勋章金牌银牌铜牌导师微信认证热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老QQ认证EC VIP学员

发表于 2025-3-10 16:14:04 | 显示全部楼层 |阅读模式

马上注册,解锁更多高级玩法

您需要 登录 才可以下载或查看,没有账号?立即注册

×
原文:https://www.daowuya.love/yolov8% ... %e6%96%b9%e6%a1%88/

报错1:
[Shell] 纯文本查看 复制代码
Traceback (most recent call last):
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 738, in file_item_double_clicked
self.load_file(filename)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1111, in load_file
self.show_bounding_box_from_annotation_file(file_path)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1144, in show_bounding_box_from_annotation_file
self.load_yolo_txt_by_filename(txt_path)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1557, in load_yolo_txt_by_filename
t_yolo_parse_reader = YoloReader(txt_path, self.image)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\libs\yolo_io.py", line 101, in __init__
self.classes = classes_file.read().strip('\n').split('\n')
UnicodeDecodeError: 'gbk(或者utf-8)' codec can't decode byte 0x9e in position 18: illegal multibyte sequence


原因:
labelimg在每次更新classes后,我注意观察了下,即使你刚开始的classes.txt是utf-8编码的,但是在更新后都会变成ANSI编码的。
解决方式:
①打开现有的classes.txt,并另存为ANSI编码的。
②进入labelimg的源代码目录,定位到报错的文件位置
[Shell] 纯文本查看 复制代码
C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\libs\yolo_io.py



报错的代码
[Python] 纯文本查看 复制代码
classes_file = open(self.class_list_path, 'r')
self.classes = classes_file.read().strip('\n').split('\n')


修改成以ANSI编码打开文件
[Python] 纯文本查看 复制代码
with open(self.class_list_path, 'r', encoding='ANSI') as classes_file:
        self.classes = classes_file.read().strip('\n').split('\n')


报错2
[Shell] 纯文本查看 复制代码
Traceback (most recent call last):
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1376, in open_next_image
self.load_file(filename)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1111, in load_file
self.show_bounding_box_from_annotation_file(file_path)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1144, in show_bounding_box_from_annotation_file
self.load_yolo_txt_by_filename(txt_path)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\labelImg\labelImg.py", line 1557, in load_yolo_txt_by_filename
t_yolo_parse_reader = YoloReader(txt_path, self.image)
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\libs\yolo_io.py", line 115, in __init__
self.parse_yolo_format()
File "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\libs\yolo_io.py", line 146, 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 "C:\Users\daowuya\.conda\envs\labelimg\lib\site-packages\libs\yolo_io.py", line 128, in yolo_line_to_shape
label = self.classes[int(class_index)]
IndexError: list index out of range


原因:
这种情况正常打开查看标注情况是没有任何问题的,但是只要是修改或者增加了标注,此时再点击查看下一张图的标注情况就会发生闪退。这是因为在你更新数据后,classes.txt的数据会被重写,重写为上一张图里的所有class,所以一旦你的下一张图里原本标注的class不存在于classes.txt内,就会报“list index out of range”这种错误。
解决方式:
①定位到labelimg.py源码目录
[Shell] 纯文本查看 复制代码
C:\Users\daowuya\.conda\envs\labelimg\Lib\site-packages\labelImg

②在源码目录新建data文件夹,再在data文件夹里新建 predefined_classes.txt,注:这个txt文件的编码需要保存为utf-8。
再将classes.txt里的所有内容都黏贴进去,保存即可!

VIP培训班介绍汇总[安卓/IOSusb版/IOS脱机版/PHP/nodejs等]
http://bbs.laoleng.vip/forum.php?mod=viewthread&tid=428

付费工具介绍汇总[热更/远程调试/IOS易语言UI/拓展插件等]
http://bbs.laoleng.vip/forum.php?mod=viewthread&tid=430
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

想要力量吗骚年上一条 /2 下一条

关闭

免责声明|Archiver|手机版|老冷论坛 ( 闽ICP备20013040号-2 )|网站地图

GMT+8, 2025-3-30 04:11

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表