DataLoader issue : Batch must contain numbers, dicts or lists; found <class 'torch.FloatTensor'>

(Rupesh Goud) #1

I am trying to run the notebook of lesson 10th using multi-label,
I have nearly thirty labels and they are in below format.
l1 l2 l3 l4 l5 … l30 text

I’m trying to build a classifier out of it
when I passed my labels as numpy array to learn.lr_find and, I’m getting below error,
RuntimeError: Expected object of type Variable[torch.FloatTensor] but found type Variable[torch.LongTensor] for argument #1 'target’
Doing some research I found this error is because of torch expects FloatTensor but labels numpy array are being converted to LongTensor.
So I tried converting the labels explicitly to [torch.FloatTensor].
But fastai library throwing me this error,
Batch must contain numbers, dicts or lists; found <class ‘torch.FloatTensor’>

I’m stuck at this place from last 2 days. Please help me to resolve this issue.

trn_ds = TextDataset(trn_clas, trn_labels)
val_ds = TextDataset(val_clas, val_labels)
trn_samp = SortishSampler(trn_clas, key=lambda x: len(trn_clas[x]), bs=bs//2)
val_samp = SortSampler(val_clas, key=lambda x: len(val_clas[x]))
trn_dl = DataLoader(trn_ds, bs//2, transpose=True, num_workers=1, pad_idx=1, sampler=trn_samp)
val_dl = DataLoader(val_ds, bs, transpose=True, num_workers=1, pad_idx=1, sampler=val_samp)
md = ModelData(PATH, trn_dl, val_dl)
dps = np.array([0.4,0.5,0.05,0.3,0.4])*0.5
m = get_rnn_classifer(bptt, 20*70, c, vs, emb_sz=em_sz, n_hid=nh, n_layers=nl, pad_token=1,
          layers=[em_sz*3, 50, c], drops=[dps[4], 0.1],
          dropouti=dps[0], wdrop=dps[1], dropoute=dps[2], dropouth=dps[3])
m = m.float()
opt_fn = partial(optim.Adam, betas=(0.7, 0.99))

lrm = 2.6
lrs = np.array([lr/(lrm**4), lr/(lrm**3), lr/(lrm**2), lr/lrm, lr])
wd = 1e-7
wd = 0

(Rupesh Goud) #2

This got cleared when I used latest fastai version,
There are much easier ways to do multilabel in latest version.
I think there is no much support for multilabel classification in fastai 0.7.