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.
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.