FileNotFoundError:`[Errno 2]没有这样的文件或目录:'用于根据几个类显示条形图 [英] FileNotFoundError: `[Errno 2] No such file or directory: ' for showing the bar graph according to the several classes

查看:57
本文介绍了FileNotFoundError:`[Errno 2]没有这样的文件或目录:'用于根据几个类显示条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将演示条形图,该条形图将显示每个子文件夹中显示的几类图像的统计结果.我已经编写了代码,但出现了错误

I am going to demonstrate the Bar graph where it will show the statistical result of several classes of images presented in each sub-folder. I have written the code but it appears error

我的代码:

#Class Name
image_folder = ['AB','','AC','AA','BB', 'BA', 'BC', 'CA', 'CB', 'CC', 'DD','EE' ]
nimgs = {}
for i in image_folder:
    nimages = len(os.listdir('/content/dataset/'+i+'/'))
    nimgs[i]=nimages
plt.figure(figsize=(34, 12))
plt.bar(range(len(nimgs)), list(nimgs.values()), align='center')
plt.xticks(range(len(nimgs)), list(nimgs.keys()))
plt.title('Distribution of different classes of Dataset')
plt.show()


Error in line : nimages = len(os.listdir('/content/dataset/'+i+'/'))  

错误: FileNotFoundError:[错误2]没有这样的文件或目录:'/content/dataset/AB/'

推荐答案

image_folder中的空str导致了错误.当迭代器到达空字符串时,您实际上是在尝试将文件夹定义为图像!

The empty str in image_folder is causing the error. When the iterator reaches the empty string, you are effectively trying to define a folder as an image!

这篇关于FileNotFoundError:`[Errno 2]没有这样的文件或目录:'用于根据几个类显示条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆