无法将字符串转换为浮点数:'.ipynb_checkpoints'
could not convert string to float: '.ipynb_checkpoints'
大家好,我想在我的程序中可视化一个数据集,这样我就可以知道我的数据中有多少类,但是这个错误一直出现,谁能帮我解决这个问题,因为我无法访问我的数据
folders = os.listdir(train_path)
train_number=[]
class_num=[]
for folder in folders:
train_files= os.listdir(train_path + '/' + folder)
train_number.append(len(train_files))
class_num.append(classes[int(float(folder))])
#sorting the dataset on the basis of number images in each class
zipped_lists=zip(train_number,class_num)
sorted_pairs= sorted(zipped_lists)
tuples= zip(*sorted_pairs)
train_number, class_num = [list(tuple) for tuple in tuples]
#plotting the number of images in each class
plt.figure(figsize=(21,10))
plt.bar(class_num,train_number)
plt.xticks(class_num, rotation='vertical')
plt.show
ValueError Traceback (most recent call last)
<ipython-input-28-10b88599517e> in <module>()
5 train_files= os.listdir(train_path + '/' + folder)
6 train_number.append(len(train_files))
----> 7 class_num.append(classes[int(float(folder))])
8
9 #sorting the dataset on the basis of number images in each class
ValueError: could not convert string to float: '.ipynb_checkpoints'
在您的 folders = os.listdir(train_path)
中,您有一个 隐藏 文件夹调用“.ipynb_checkpoints” Python 无法转换为浮动,您可以在try/except块中保护它:
for folder in folders:
try:
train_files= os.listdir(train_path + '/' + folder)
train_number.append(len(train_files))
class_num.append(classes[int(float(folder))])
except ValueError:
# do something with the error
大家好,我想在我的程序中可视化一个数据集,这样我就可以知道我的数据中有多少类,但是这个错误一直出现,谁能帮我解决这个问题,因为我无法访问我的数据
folders = os.listdir(train_path)
train_number=[]
class_num=[]
for folder in folders:
train_files= os.listdir(train_path + '/' + folder)
train_number.append(len(train_files))
class_num.append(classes[int(float(folder))])
#sorting the dataset on the basis of number images in each class
zipped_lists=zip(train_number,class_num)
sorted_pairs= sorted(zipped_lists)
tuples= zip(*sorted_pairs)
train_number, class_num = [list(tuple) for tuple in tuples]
#plotting the number of images in each class
plt.figure(figsize=(21,10))
plt.bar(class_num,train_number)
plt.xticks(class_num, rotation='vertical')
plt.show
ValueError Traceback (most recent call last)
<ipython-input-28-10b88599517e> in <module>()
5 train_files= os.listdir(train_path + '/' + folder)
6 train_number.append(len(train_files))
----> 7 class_num.append(classes[int(float(folder))])
8
9 #sorting the dataset on the basis of number images in each class
ValueError: could not convert string to float: '.ipynb_checkpoints'
在您的 folders = os.listdir(train_path)
中,您有一个 隐藏 文件夹调用“.ipynb_checkpoints” Python 无法转换为浮动,您可以在try/except块中保护它:
for folder in folders:
try:
train_files= os.listdir(train_path + '/' + folder)
train_number.append(len(train_files))
class_num.append(classes[int(float(folder))])
except ValueError:
# do something with the error