Evaluating test set using csv - DataLoaders has no len()

Hi everyone,

After the first two lessons of fastai, I thought of trying out the library on an emotion-reco dataset. I’ve trained the model but I’m facing issues evaluating it on the test data. The test data is in a folder called ‘test_img’ and the labels are given in a csv file called ‘test_labels.csv’

So I have:
test_df = pd.read_csv(‘test_img/test_labels.csv’, header=None)
test_df.head()

0 1
0 Angry_2247.png 0
1 Disgust_1014.png 1
2 Disgust_1315.png 1
3 Angry_388.png 0
4 Angry_2140.png 0

Then I do:
test_data = ImageDataLoaders.from_df(test_df, ‘test_img’, valid_pct=0)
learn2 = load_learner(‘models/resnet18.pkl’) #This is the model i have trained
learn2.validate(dl=test_data)

but validate throws me an error:
TypeError: object of type ‘DataLoaders’ has no len()

Is this the right way to load a test set from a csv file? I think i’m missing something.

A good way to isolate the error is to run each of the three lines starting from

test_data = ImageDataloaders...`

in their own jupyter cell. When shown like this, you’ll know if the problem shows up when trying to call learn.validate() or when creating the ImageDataLoader. As you’ve posted the question it’s hard to tell where exactly the error is showing up.

Hi Brian, thanks for the suggestion. I guess I didn’t mention it clearly in the question.

The error pops up when I run learn.validate()
ImageDataLoader seems to load the data without any problems. Also, I can run individual predictions using learn.predict(‘image.png’). It’s only when I try to load all the data from the csv that I run into this issue.