在数据加载的时候有可能会报这个错误
1.检查你的数据集是否为空,否则进行下一步;
2.找到数据加载的地方,打印出路径和__len__ 方法: 返回数据集中图像的总数,检查是否为空。
我遇到的问题就是路径是对的,文件夹中也有图片,但是没有被正确加载。
3.以下是我的代码,使用到了make_dataset函数,那就是这里加载有问题,
def __init__(self, opt):
"""Initialize this dataset class.
Parameters:
opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
"""
BaseDataset.__init__(self, opt)
self.dir_A = os.path.join(opt.dataroot, opt.phase + 'A') # create a path '/path/to/data/trainA'
self.dir_B = os.path.join(opt.dataroot, opt.phase + 'B') # create a path '/path/to/data/trainB'
self.A_paths = sorted(make_dataset(self.dir_A, opt.max_dataset_size)) # load images from '/path/to/data/trainA'
self.B_paths = sorted(make_dataset(self.dir_B, opt.max_dataset_size))
def make_dataset(dir, max_dataset_size=float("inf")):
images = []
assert os.path.isdir(dir), '%s is not a valid directory' % dir
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(root, fname)
images.append(path)
return images[:min(max_dataset_size, len(images))
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
'.tif', '.TIF', '.tiff', '.TIFF','npy'
]
最后发现是因为,文件后缀名和定义不对导致的。