当前位置:网站首页>错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:

错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:

2022-08-02 03:21:00 woshicaiji12138

今天在做深度学习时,出现了如下错误:

root='G:/anaconda/pythonProject2/DATA/HWDB1'
transform = transforms.Compose([transforms.Resize((64,64)),
                                transforms.ToTensor(),
                                transforms.Grayscale()
                               ])
 # 读取训练集
train_dataset =Mydataset(root+'/train.txt',num_class=10,transforms=transform)

with open(txt_path,‘r’) as f: FileNotFoundError: [Errno 2] No such file or directory: ‘G:\anaconda\pythonProject2\HWDB1/train.txt’
究其原因,在于train.txt文件格式内容都如下所示:./DATA/HWDB1/train\00000\100234.png。
而HWDB1数据集文件名为HWDB1,因而绝对路径变成了G:/anaconda/pythonProject2/HWDB1/HWDB1,自然无法找到该路径。
所以只需要将文件夹HWDB1改名为DATA,使路径名为G:\anaconda\pythonProject2\DATA\HWDB1即可。

原网站

版权声明
本文为[woshicaiji12138]所创,转载请带上原文链接,感谢
https://blog.csdn.net/woshicaiji12138/article/details/124309820