megvii-research/AnchorDETR

coco test-dev

helq2612 opened this issue · 4 comments

Hi,

Great work! Do you have the code for coco test-dev?

Thanks!

@helq2612 Hi,

You can modify the path to the test-dev.

In order to save the results, you should add some lines as follows:

# in datasets/coco_eval.py
class CocoEvaluator(object):
    def __init__(self, coco_gt, iou_types):
        assert isinstance(iou_types, (list, tuple))
        coco_gt = copy.deepcopy(coco_gt)
        self.coco_gt = coco_gt

        self.iou_types = iou_types
        self.coco_eval = {}
        for iou_type in iou_types:
            self.coco_eval[iou_type] = COCOeval(coco_gt, iouType=iou_type)

        self.img_ids = []
        self.eval_imgs = {k: [] for k in iou_types}
        self.results=[]

    def update(self, predictions):
        img_ids = list(np.unique(list(predictions.keys())))
        self.img_ids.extend(img_ids)

        for iou_type in self.iou_types:
            results = self.prepare(predictions, iou_type)
            self.results.extend(results)
# in main.py
            with open(os.path.join(args.output_dir,'res.json'),'w') as f:
                json.dump(coco_evaluator.results,f)

BTW, if you want to use multiple gpus, you should gather the results at each card.

Thank you very much! I find 1 GPU works for me, but with multiple GPUs, the results seem not good.

Yes, only the results at 1 card will be saved if simply using multiple GPUs. You can use the all_gather function to gather all the results at different ranks if you want to use multiple GPUs.

Now we support to save the json results. And the results at different ranks will be gathered if you use multiple gpus.