machine-learning-book icon indicating copy to clipboard operation
machine-learning-book copied to clipboard

Chapter 15: TypeError

Open vmirly opened this issue 2 years ago • 0 comments

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

vmirly avatar Feb 04 '23 04:02 vmirly