python - UnicodeDecodeError:“utf-8”编解码器无法解码位置 0 的字节 0xc4:
问题描述
我是 python 新手。我创建了一个代码来计算 YOLO 注释中包含多少类,我遇到了这个错误。
我真的不熟悉这个编码错误。`_' 这个我找了很多,但是没有'0xc4'的解决方案。
首先,我添加我的整个代码。
mid_num = 4000
total_num = 13485 #총 이미지 개수
dir = '/media/aicar/Seagate Backup Plus Drive/최종_데이터셋_cone/labels/' #어노테이션이 있는 위치
# dir = '/home/aicar/labelImg-master/data/'
cone = 0
stick = 0
crossline = 0
stopline = 0
red_light = 0
yellow_light = 0
green_light = 0
str_and_left = 0
left_turn = 0
drum = 0
for idx in range(1, mid_num+1):
# filename = dir + str(idx) + '.txt'
filename = dir + 'corn_' + str(idx) + '.txt'
# f = open(filename, 'r')
col_2=[]
with open(filename) as f:
for line in f:
chars=[]
line=line.split(' ')
for char in line:
if char not in ['',' ']:
chars.append(char)
col_2.append(chars[0])
f.close()
# print(col_2)
if '0' in col_2:
cone = cone +1
if '1' in col_2:
stick = stick +1
if '2' in col_2:
crossline = crossline +1
if '3' in col_2:
stopline = stopline +1
if '4' in col_2:
red_light = red_light +1
if '5' in col_2:
yellow_light = yellow_light +1
if '6' in col_2:
green_light = green_light +1
if '7' in col_2:
str_and_left = str_and_left +1
if '8' in col_2:
left_turn = left_turn +1
if '9' in col_2:
drum = drum +1
print('cone : ' + str(cone))
print('stick : ' + str(stick))
print('crossline : ' + str(crossline))
print('stopline : ' + str(red_light))
print('red_light : ' + str(red_light))
print('yellow_light : ' + str(yellow_light))
print('green_light : ' + str(green_light))
print('str_and_left : ' + str(str_and_left))
print('left_turn : ' + str(left_turn))
print('drum : ' + str(drum))
我拥有的锡总数为 13,485,显示在第 5 行的“total_num”中。
如果我在 13,485 个注释上运行此代码,则会出现 UnicodeDecodeError,如果我运行大约 1,000 个,它可以正常工作。
下图是代码开启只有1000个注解时的终端窗口。
我需要专家的帮助。谢谢。
解决方案
推荐阅读
- python - 如何在python中的dir()中传递变量
- r - 为什么添加到列表时的 R 行为取决于分配顺序
- angular - 从旧版 Web 应用程序运行 angular7 应用程序
- r - `TruncNorm:下限大于上限`MNP包中的错误
- c# - 在 WPF C# 中为 WebBrowser 发送数据和 Json 序列化列表
- css - 最大宽度网格问题 - 当更改为 90% 时离开页面
- php - 将 SQL 查询多维数组输出作为 stdClass 对象管理
- c++ - Windows 上的 CUDA 编译问题,Cmake 错误:未找到 CUDA 工具集
- c# - 如何在 UWP 中使用代码模拟 Tab 键按下
- python - 使用 MMdnn IR 接口模型将 Pytorch 模型转换为 Keras 模型