fastai.data.core.DataLoaders built from pytorch dataset. How to prepare test loader?

If I have fastai.data.core.DataLoaders return from datablock API, I usually obtain test dataloader as below

test_dl = dls.test_dl(test_df)
pred_prob = learn.get_preds(dl=test_dl)[0]

Right now, task at hand requires me to create fastai.data.core.DataLoaders from Pytorch dataset. Details are

train_dataset = SedDataset(
        df = train_tp,
        period=args.period,
        audio_transform=train_audio_transform,
        data_path=args.train_data_path,
        mode="train"
)

valid_dataset = SedDataset(
        df = train_tp,
        period=args.period,
        stride=5,
        audio_transform=None,
        data_path=args.train_data_path,
        mode="valid"
)

trn_dl = DataLoader(train_dataset, batch_size=16, shuffle=True)
val_dl = DataLoader(valid_dataset, batch_size=16, shuffle=True)

dls = DataLoaders(trn_dl, val_dl)
dls.c = 24

While dls is also fastai.data.core.DataLoaders, calling dls.test_dl(test_df) results in

I also attempt to bind Pytorch test loader to fastai.data.core.DataLoaders like so

dls = DataLoaders(trn_dl, val_dl, test_dl)

However, the result object doesn’t have attribute reference to the test loader (equivalent of dls.train and dls.valid). Therefore, I can not call

learn.get_preds(dl=test_dl) due to missing test loader

Question:

How do I prepare fastai test loader in this scenario?

Is the DataLoader class the fastai version or the pytorch version. Does val_dl have a .new() method after you instantiate it?

1 Like