facebookresearch / Mask2Former

Code release for "Masked-attention Mask Transformer for Universal Image Segmentation"
MIT License
2.46k stars 372 forks source link

[BUGS] TypeError: _evaluate_predictions_on_coco() got an unexpected keyword argument 'use_fast_impl' #212

Open bjzhb666 opened 1 year ago

bjzhb666 commented 1 year ago

In Mask2Former/mask2former/evaluation/instance_evaluation.py line91 https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/evaluation/instance_evaluation.py#L91-L99, we use _evaluate_predictions_on_coco(), but this function does not have the keyword argument 'use_fast_impl' (See in https://github.com/facebookresearch/detectron2/blob/main/detectron2/evaluation/coco_evaluation.py#L567-L575).

When I use InstanceSegEvaluator, I get this TypeError. How to fix it? Thanks

Traceback (most recent call last): File "/home/zhaohongbo/miniconda3/envs/p39t20/lib/python3.9/site-packages/torch/multiprocessing/spawn.py", line 69, in _wrap fn(i, *args) File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/launch.py", line 123, in _distributed_worker main_func(*args) File "/data/zhaohongbo/Github/satellite/Mask2Former/train_net.py", line 321, in main return trainer.train() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/defaults.py", line 484, in train super().train(self.start_iter, self.max_iter) File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/train_loop.py", line 156, in train self.after_step() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/train_loop.py", line 190, in after_step h.after_step() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/hooks.py", line 556, in after_step self._do_eval() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/hooks.py", line 529, in _do_eval results = self._func() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/defaults.py", line 453, in test_and_save_results self._last_eval_results = self.test(self.cfg, self.model) File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/engine/defaults.py", line 617, in test results_i = inference_on_dataset(model, data_loader, evaluator) File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/evaluation/evaluator.py", line 204, in inference_on_dataset results = evaluator.evaluate() File "/data/zhaohongbo/Github/satellite/Mask2Former/detectron2/detectron2/evaluation/coco_evaluation.py", line 206, in evaluate self._eval_predictions(predictions, img_ids=img_ids) File "/data/zhaohongbo/Github/satellite/Mask2Former/mask2former/evaluation/instance_evaluation.py", line 91, in _eval_predictions _evaluate_predictions_on_coco( TypeError: _evaluate_predictions_on_coco() got an unexpected keyword argument 'use_fast_impl'

Ze-Yang commented 7 months ago

I also encounter the same issue. Is there any suggestion?

pepperbubble commented 3 months ago

delete "use_fast_impl=self._use_fast_impl" in mask2former/evaluation/instance_evaluation.py

    for task in sorted(tasks):
        assert task in {"bbox", "segm", "keypoints"}, f"Got unknown task: {task}!"
        coco_eval = (
            _evaluate_predictions_on_coco(
                self._coco_api,
                coco_results,
                task,
                kpt_oks_sigmas=self._kpt_oks_sigmas,
                **# use_fast_impl=self._use_fast_impl,**
                img_ids=img_ids,
                max_dets_per_image=self._max_dets_per_image,
            )
            if len(coco_results) > 0
            else None  # cocoapi does not handle empty results very well
        )
collinmccarthy commented 3 months ago

The more correct solution is to use the function call used in COCOEvaluator in detectron2.evaluation.coco_evaluation.py: L266-274:

_evaluate_predictions_on_coco(
        self._coco_api,
        coco_results,
        task,
        kpt_oks_sigmas=self._kpt_oks_sigmas,
        cocoeval_fn=COCOeval_opt if self._use_fast_impl else COCOeval,
        img_ids=img_ids,
        max_dets_per_image=self._max_dets_per_image,
    )

This also requires you to use the same import as coco_evaluation.py:

try:
    from detectron2.evaluation.fast_eval_api import COCOeval_opt
except ImportError:
    COCOeval_opt = COCOeval