Python FileNotFoundError:[Errno 2]没有这样的文件或目录,即使我在那个特定文件夹中有图像
我是python的新手。在我使用CNN处理之前,我试图将我的22k图像放入矩阵。然而,我遇到了这种情况,我不知道我哪里做错了Python FileNotFoundError:[Errno 2]没有这样的文件或目录,即使我在那个特定文件夹中有图像,python,Python,我是python的新手。在我使用CNN处理之前,我试图将我的22k图像放入矩阵。然而,我遇到了这种情况,我不知道我哪里做错了 path1 = 'C:/Users/Z/Documents/Python Scripts/Data' path2 = 'C:/Users/Z/Documents/Python Scripts/Data1' listing = os.listdir(path1) num_samples=size(listing) for file in listing: im
path1 = 'C:/Users/Z/Documents/Python Scripts/Data'
path2 = 'C:/Users/Z/Documents/Python Scripts/Data1'
listing = os.listdir(path1)
num_samples=size(listing)
for file in listing:
im = Image.open(path1 + '\\' + file)
img_rows, img_cols = 224, 224
img = im.resize((img_rows,img_cols),3)
img.save(path2 +'\\' + file, "JPEG")
imlist = os.listdir(path2)
img_data_list=[]
a = Image.open('Data1' + '\\'+ imlist[0]) # open one image to get size
im1 = array(a)
m,n = im1.shape[0:3] # get the size of the images
imnbr = len(imlist) # get the number of images
num_samples = len(imlist)
我犯了这个错误
打开单个图像时,您的路径不正确,应该是:
a = Image.open(path2 + '\\'+ imlist[0])
你只是有一个小的代码错误<代码>“Data1”路径不正确a=Image.open('Data1'+'\\'+imlist[0])打开一个图像以获得大小
你应该阅读路径2。你不是吗???你在使用什么操作系统?windows?我正在使用windows查看我的答案,如果它有助于将其标记为已接受;)@Tan Ying YingYou正在引用一个部分文件路径-您已经预定义了path1和path2,但是在从底部开始的第5行中,您只使用“Data1”作为字符串
a=…
更改该行以包含完整路径。这个错误很容易自我解释谢谢你,我意识到了。
a = Image.open(path2 + '\\'+ imlist[0])