Test dataset with bounding box


IndexError Traceback (most recent call last)
in ()
----> 1 log_preds,y = learn.TTA(is_test=True)

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in TTA(self, n_aug, is_test)
388 dl1 = self.data.test_dl if is_test else self.data.val_dl
389 dl2 = self.data.test_aug_dl if is_test else self.data.aug_dl
–> 390 preds1,targs = predict_with_targs(self.model, dl1)
391 preds1 = [preds1]*math.ceil(n_aug/4)
392 preds2 = [predict_with_targs(self.model, dl2)[0] for i in tqdm(range(n_aug), leave=False)]

/usr/local/lib/python3.6/dist-packages/fastai/model.py in predict_with_targs(m, dl)
235
236 def predict_with_targs(m, dl):
–> 237 preda,targa = predict_with_targs_(m, dl)
238 return to_np(torch.cat(preda)), to_np(torch.cat(targa))
239

/usr/local/lib/python3.6/dist-packages/fastai/model.py in predict_with_targs_(m, dl)
231 if hasattr(m, ‘reset’): m.reset()
232 res = []
–> 233 for *x,y in iter(dl): res.append([get_prediction(m(*VV(x))),y])
234 return zip(*res)
235

/usr/local/lib/python3.6/dist-packages/fastai/dataloader.py in iter(self)
86 # avoid py3.6 issue where queue is infinite and can result in memory exhaustion
87 for c in chunk_iter(iter(self.batch_sampler), self.num_workers*10):
—> 88 for batch in e.map(self.get_batch, c):
89 yield get_tensor(batch, self.pin_memory, self.half)
90

/usr/lib/python3.6/concurrent/futures/_base.py in result_iterator()
584 # Careful not to keep a reference to the popped future
585 if timeout is None:
–> 586 yield fs.pop().result()
587 else:
588 yield fs.pop().result(end_time - time.monotonic())

/usr/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
423 raise CancelledError()
424 elif self._state == FINISHED:
–> 425 return self.__get_result()
426
427 self._condition.wait(timeout)

/usr/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
382 def __get_result(self):
383 if self._exception:
–> 384 raise self._exception
385 else:
386 return self._result

/usr/lib/python3.6/concurrent/futures/thread.py in run(self)
54
55 try:
—> 56 result = self.fn(*self.args, **self.kwargs)
57 except BaseException as exc:
58 self.future.set_exception(exc)

/usr/local/lib/python3.6/dist-packages/fastai/dataloader.py in get_batch(self, indices)
73
74 def get_batch(self, indices):
—> 75 res = self.np_collate([self.dataset[i] for i in indices])
76 if self.transpose: res[0] = res[0].T
77 if self.transpose_y: res[1] = res[1].T

/usr/local/lib/python3.6/dist-packages/fastai/dataloader.py in (.0)
73
74 def get_batch(self, indices):
—> 75 res = self.np_collate([self.dataset[i] for i in indices])
76 if self.transpose: res[0] = res[0].T
77 if self.transpose_y: res[1] = res[1].T

/usr/local/lib/python3.6/dist-packages/fastai/dataset.py in getitem(self, idx)
165 xs,ys = zip(*[self.get1item(i) for i in range(*idx.indices(self.n))])
166 return np.stack(xs),ys
–> 167 return self.get1item(idx)
168
169 def len(self): return self.n

/usr/local/lib/python3.6/dist-packages/fastai/dataset.py in get1item(self, idx)
159 def get1item(self, idx):
160 x,y = self.get_x(idx),self.get_y(idx)
–> 161 return self.get(self.transform, x, y)
162
163 def getitem(self, idx):

/usr/local/lib/python3.6/dist-packages/fastai/dataset.py in get(self, tfm, x, y)
170
171 def get(self, tfm, x, y):
–> 172 return (x,y) if tfm is None else tfm(x,y)
173
174 @abstractmethod

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in call(self, im, y)
630 self.tfms.append(ChannelOrder(tfm_y))
631
–> 632 def call(self, im, y=None): return compose(im, y, self.tfms)
633 def repr(self): return str(self.tfms)
634

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in compose(im, y, fns)
605 for fn in fns:
606 #pdb.set_trace()
–> 607 im, y =fn(im, y)
608 return im if y is None else (im, y)
609

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in call(self, x, y)
234 x,y = ((self.transform(x),y) if self.tfm_y==TfmType.NO
235 else self.transform(x,y) if self.tfm_y in (TfmType.PIXEL, TfmType.CLASS)
–> 236 else self.transform_coord(x,y))
237 return x, y
238

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in transform_coord(self, x, ys)
265 def transform_coord(self, x, ys):
266 yp = partition(ys, 4)
–> 267 y2 = [self.map_y(y,x) for y in yp]
268 x = self.do_transform(x, False)
269 return x, np.concatenate(y2)

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in (.0)
265 def transform_coord(self, x, ys):
266 yp = partition(ys, 4)
–> 267 y2 = [self.map_y(y,x) for y in yp]
268 x = self.do_transform(x, False)
269 return x, np.concatenate(y2)

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in map_y(self, y0, x)
259
260 def map_y(self, y0, x):
–> 261 y = CoordTransform.make_square(y0, x)
262 y_tr = self.do_transform(y, True)
263 return to_bb(y_tr)

/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in make_square(y, x)
255 y1 = np.zeros((r, c))
256 y = y.astype(np.int)
–> 257 y1[y[0]:y[2], y[1]:y[3]] = 1.
258 return y1
259

IndexError: index 2 is out of bounds for axis 0 with size 1

I’m facing this issue. With help of debugger, I found out that the size of y is 1 and I also found that
learn.data.test_ds.y.shape is (12815,1) whereas learn.data.trn_ds.y.shape is (11000,4).

I tried to initialize y of test_ds by adding this, learn.data.test_ds.y = np.zeros([12815,4])
Still, I get the same error!

Kindly help me out!

Thank you.