Can't creat test_set with labels: Expected an input of type in.....but got <class 'pathlib.PosixPath'>

Hi everyone
I have problem with adding 'with_labels= ’ argument in

test_set (dsets:__main__.Datasets|__main__.TfmdLists, test_items,
rm_tfms=None, with_labels:bool=False)

my goal is to use learn.validate() on testset and get accuracy from testset. so I should make test_dl.
here is my code:

fns_small = fnames[:10]; fns_small[0] #just for test my code
a=dls.test_dl(fns_small,with_labels=True) # or a = test_set(dls.valid_ds, fns_small)



error: Expected an input of type in

  • <class ‘pandas.core.series.Series’>
  • <class ‘numpy.int64’>
  • <class ‘fastai.torch_core.TensorCategory’>
    but got <class ‘pathlib.PosixPath’>

as you use with_labels=True you also have to tell the .test_dl method what the labels are, right now you only pass it the filenames (and the dataloader does not infer the labels from the filename…). I think the easiest solution to this is to pass the test items as you passed the train items, so as a DataFrame here.

#test_dl = learn.dls.test_dl(fns[:10], with_labels=True)
test_dl = learn.dls.test_dl(df.sample(10), with_labels=True)

shouldn’t complain :slight_smile: