Target size and input size mismatch multilabel classification

I’m trying to predict accuracy(threshold) on test set for Multilabel classification.

I create a new databunch for test in the following way

# Create Databunch

    il = ImageList.from_df(test_df, path=path/'frames_v1_v2')

    ils = il.split_none() #All data on Train Set

    ll = ils.label_from_df(cols='Labels', label_delim=' ')

    ll.valid = ll.train 

    ll.transform(tfms=None,size=IMAGE_SIZE) # Optional Transforms

    test_data = ll.databunch(bs=BATCH_SIZE);


    test_data.valid_dl =, drop_last=False) = test_data.valid_dl

This was suggested in one the posts in the forum

However if I’m doing learner.validate(), I’m getting the following error

Target size (torch.Size([1280])) must be the same as input size (torch.Size([1408]))

Found the problem in my case.

While creating the test data, the test dataframe did not contain any datapoint for one of the classes. So as a result there only x-1 classes instead of x classes in original training databunch.

Solved this by creating a new df.

1 Like