I am having some trouble with getting inference to work with my multi bounding box image data, on which I have trained RetinaNet.
I am using the inference tutorial as my guide. I have a test set of unlabelled data. To allow me to use the same DataBunch structure, I give the unlabelled data some dummy bounding boxes.
- Load the data:
size = 256
data = (ObjectItemList.from_df(path=PATH, folder='ground_truth_images', df=grouped_inf)
.split_by_rand_pct()
.label_from_df()
.transform(get_transforms(max_rotate=5, max_zoom=1.05), size=size, resize_method=ResizeMethod.SQUISH)
.databunch(bs=64, collate_fn=bb_pad_collate)
.normalize(imagenet_stats)
)
- I have previously trained my network, saved and exported it, so I load it:
learn = load_learner('/rds/user/trpb2/hpc-work/data/ground_truth')
- and then try to predict for an image:
img = data.train_ds[0][0]
learn.predict(img)
and I get the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-ef47b9ae205b> in <module>
1 img = data.train_ds[0][0]
----> 2 learn.predict(img)
3 #preds = learn.pred_batch(DatasetType.Train)
~/.conda/envs/fastai_v1_2/lib/python3.7/site-packages/fastai/basic_train.py in predict(self, item, return_x, batch_first, with_dropout, **kwargs)
365 batch = self.data.one_item(item)
366 res = self.pred_batch(batch=batch, with_dropout=with_dropout)
--> 367 raw_pred,x = grab_idx(res,0,batch_first=batch_first),batch[0]
368 norm = getattr(self.data,'norm',False)
369 if norm:
~/.conda/envs/fastai_v1_2/lib/python3.7/site-packages/fastai/torch_core.py in grab_idx(x, i, batch_first)
325 def grab_idx(x,i,batch_first:bool=True):
326 "Grab the `i`-th batch in `x`, `batch_first` stating the batch dimension."
--> 327 if batch_first: return ([o[i].cpu() for o in x] if is_listy(x) else x[i].cpu())
328 else: return ([o[:,i].cpu() for o in x] if is_listy(x) else x[:,i].cpu())
329
~/.conda/envs/fastai_v1_2/lib/python3.7/site-packages/fastai/torch_core.py in <listcomp>(.0)
325 def grab_idx(x,i,batch_first:bool=True):
326 "Grab the `i`-th batch in `x`, `batch_first` stating the batch dimension."
--> 327 if batch_first: return ([o[i].cpu() for o in x] if is_listy(x) else x[i].cpu())
328 else: return ([o[:,i].cpu() for o in x] if is_listy(x) else x[:,i].cpu())
329
AttributeError: 'list' object has no attribute 'cpu'
I’d be really grateful for any help!