Pytorch dataset image loading

pls explain why is this error( NameError : name ‘ds’ is not defined)

import torch
from torchvision import datasets, transforms

path = 'D:/work/train'

    ds = datasets.ImageFolder(root=path)


NameError : name ‘ds’ is not defined

ds = dataset.ImageFolder(root=path) seems to raise an exception, which is caught in the expect block and thrown away since you are just using pass instead of notifying the user. ds is never initialized and len(ds) will raise the next exception.

yes. The problem is some folders(labels) are empty. so any other way to load the dataset with empty folders?

You need to provide a path to a valid dataset where each subfolder contains valid image data types.
If some of the folders are empty, this error will be raised, so remove these empty folders.