FileNotFoundError: [Errno 2] No such file or directory: ‘./train/hazy/hazy‘

对DW-GAN进行训练时,自己编写了train.py代码,执行时出现以下问题:

FileNotFoundError: [Errno 2] No such file or directory: './train/hazy/hazy'

FileNotFoundError: [Errno 2] No such file or directory: ‘./train/hazy/hazy‘_第1张图片

 这个问题是文件路径有误导致的,可通过如下语句解决:

def __init__(self, train_dir):
    self.transform = transforms.Compose([transforms.ToTensor()])
    self.list_train=[]

    for i in os.listdir(train_dir+'/hazy'):
        self.list_train.append(i)

    #'./train/'
    self.root_hazy=os.path.join(train_dir, 'hazy/')
    self.root_clean =os.path.join(train_dir, 'clean/')
    self.file_len = len(self.list_train)

在后面调用Image.open时会定位到train/hazy文件夹

你可能感兴趣的:(训练问题记录,python)