rasbt / machine-learning-book

Code Repository for Machine Learning with PyTorch and Scikit-Learn
https://sebastianraschka.com/books/#machine-learning-with-pytorch-and-scikit-learn
MIT License
3.66k stars 1.32k forks source link

Chapter 15: TypeError #108

Open vmirly opened 1 year ago

vmirly commented 1 year ago

The test dataset is a DataPipe, and therefore does not have a length, which results in the following error in the evaluate function:

    return total_acc/len(dataloader.dataset), total_loss/len(dataloader.dataset)
TypeError: MapperIterDataPipe instance doesn't have valid length

One way to fix this is to convert that to a list, before applying the len() function:

    return total_acc/len(list(dataloader.dataset)), total_loss/len(list(dataloader.dataset))