I am trying to use MMdetection 2.0 for MASKD object detection. However, I am facing difficulty in creating the test file.
Here is the code that I have written
from mmdet.datasets import build_dataloader
cfg.data.test.test_mode = True
distributed = False
val_dataset = build_dataset(cfg.data.val)
data_loader = build_dataloader(
val_dataset,
samples_per_gpu=1,
workers_per_gpu=1,
dist=distributed,
shuffle=False)
from mmcv.runner import load_checkpoint
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmdet.apis import single_gpu_test
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
model = build_detector(cfg.model, train_cfg=None, test_cfg=cfg.test_cfg)
checkpoint = load_checkpoint(model, WEIGHTS_FILE, map_location='cpu')
model.CLASSES = dataset.CLASSES
model = MMDataParallel(model, device_ids=[0])
outputs = single_gpu_test(model, data_loader, False, None, 0.5)
val_dataset.format_results(outputs)
However I get the following output
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-122-4158962a1af4> in <module>()
----> 1 val_dataset.format_results(outputs)
2 frames
/content/mmdetection/mmdet/datasets/coco.py in format_results(self, results, jsonfile_prefix, **kwargs)
359 else:
360 tmp_dir = None
--> 361 result_files = self.results2json(results, jsonfile_prefix)
362 return result_files, tmp_dir
363
/content/mmdetection/mmdet/datasets/coco.py in results2json(self, results, outfile_prefix)
291 result_files = dict()
292 if isinstance(results[0], list):
--> 293 json_results = self._det2json(results)
294 result_files['bbox'] = f'{outfile_prefix}.bbox.json'
295 result_files['proposal'] = f'{outfile_prefix}.bbox.json'
/content/mmdetection/mmdet/datasets/coco.py in _det2json(self, results)
228 data['bbox'] = self.xyxy2xywh(bboxes[i])
229 data['score'] = float(bboxes[i][4])
--> 230 data['category_id'] = self.cat_ids[label]
231 json_results.append(data)
232 return json_results
IndexError: list index out of range
I guess I am unable to get the category_id
but I cant find how to fix that.
Please help