coco_panoptic_metric.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import datetime
  3. import itertools
  4. import os.path as osp
  5. import tempfile
  6. from typing import Dict, Optional, Sequence, Tuple, Union
  7. import mmcv
  8. import numpy as np
  9. from mmengine.evaluator import BaseMetric
  10. from mmengine.fileio import dump, get_local_path, load
  11. from mmengine.logging import MMLogger, print_log
  12. from terminaltables import AsciiTable
  13. from mmdet.datasets.api_wrappers import COCOPanoptic
  14. from mmdet.registry import METRICS
  15. from ..functional import (INSTANCE_OFFSET, pq_compute_multi_core,
  16. pq_compute_single_core)
  17. try:
  18. import panopticapi
  19. from panopticapi.evaluation import VOID, PQStat
  20. from panopticapi.utils import id2rgb, rgb2id
  21. except ImportError:
  22. panopticapi = None
  23. id2rgb = None
  24. rgb2id = None
  25. VOID = None
  26. PQStat = None
  27. @METRICS.register_module()
  28. class CocoPanopticMetric(BaseMetric):
  29. """COCO panoptic segmentation evaluation metric.
  30. Evaluate PQ, SQ RQ for panoptic segmentation tasks. Please refer to
  31. https://cocodataset.org/#panoptic-eval for more details.
  32. Args:
  33. ann_file (str, optional): Path to the coco format annotation file.
  34. If not specified, ground truth annotations from the dataset will
  35. be converted to coco format. Defaults to None.
  36. seg_prefix (str, optional): Path to the directory which contains the
  37. coco panoptic segmentation mask. It should be specified when
  38. evaluate. Defaults to None.
  39. classwise (bool): Whether to evaluate the metric class-wise.
  40. Defaults to False.
  41. outfile_prefix (str, optional): The prefix of json files. It includes
  42. the file path and the prefix of filename, e.g., "a/b/prefix".
  43. If not specified, a temp file will be created.
  44. It should be specified when format_only is True. Defaults to None.
  45. format_only (bool): Format the output results without perform
  46. evaluation. It is useful when you want to format the result
  47. to a specific format and submit it to the test server.
  48. Defaults to False.
  49. nproc (int): Number of processes for panoptic quality computing.
  50. Defaults to 32. When ``nproc`` exceeds the number of cpu cores,
  51. the number of cpu cores is used.
  52. file_client_args (dict, optional): Arguments to instantiate the
  53. corresponding backend in mmdet <= 3.0.0rc6. Defaults to None.
  54. backend_args (dict, optional): Arguments to instantiate the
  55. corresponding backend. Defaults to None.
  56. collect_device (str): Device name used for collecting results from
  57. different ranks during distributed training. Must be 'cpu' or
  58. 'gpu'. Defaults to 'cpu'.
  59. prefix (str, optional): The prefix that will be added in the metric
  60. names to disambiguate homonymous metrics of different evaluators.
  61. If prefix is not provided in the argument, self.default_prefix
  62. will be used instead. Defaults to None.
  63. """
  64. default_prefix: Optional[str] = 'coco_panoptic'
  65. def __init__(self,
  66. ann_file: Optional[str] = None,
  67. seg_prefix: Optional[str] = None,
  68. classwise: bool = False,
  69. format_only: bool = False,
  70. outfile_prefix: Optional[str] = None,
  71. nproc: int = 32,
  72. file_client_args: dict = None,
  73. backend_args: dict = None,
  74. collect_device: str = 'cpu',
  75. prefix: Optional[str] = None) -> None:
  76. if panopticapi is None:
  77. raise RuntimeError(
  78. 'panopticapi is not installed, please install it by: '
  79. 'pip install git+https://github.com/cocodataset/'
  80. 'panopticapi.git.')
  81. super().__init__(collect_device=collect_device, prefix=prefix)
  82. self.classwise = classwise
  83. self.format_only = format_only
  84. if self.format_only:
  85. assert outfile_prefix is not None, 'outfile_prefix must be not'
  86. 'None when format_only is True, otherwise the result files will'
  87. 'be saved to a temp directory which will be cleaned up at the end.'
  88. self.tmp_dir = None
  89. # outfile_prefix should be a prefix of a path which points to a shared
  90. # storage when train or test with multi nodes.
  91. self.outfile_prefix = outfile_prefix
  92. if outfile_prefix is None:
  93. self.tmp_dir = tempfile.TemporaryDirectory()
  94. self.outfile_prefix = osp.join(self.tmp_dir.name, 'results')
  95. # the directory to save predicted panoptic segmentation mask
  96. self.seg_out_dir = f'{self.outfile_prefix}.panoptic'
  97. self.nproc = nproc
  98. self.seg_prefix = seg_prefix
  99. self.cat_ids = None
  100. self.cat2label = None
  101. self.backend_args = backend_args
  102. if file_client_args is not None:
  103. raise RuntimeError(
  104. 'The `file_client_args` is deprecated, '
  105. 'please use `backend_args` instead, please refer to'
  106. 'https://github.com/open-mmlab/mmdetection/blob/main/configs/_base_/datasets/coco_detection.py' # noqa: E501
  107. )
  108. if ann_file:
  109. with get_local_path(
  110. ann_file, backend_args=self.backend_args) as local_path:
  111. self._coco_api = COCOPanoptic(local_path)
  112. self.categories = self._coco_api.cats
  113. else:
  114. self._coco_api = None
  115. self.categories = None
  116. def __del__(self) -> None:
  117. """Clean up."""
  118. if self.tmp_dir is not None:
  119. self.tmp_dir.cleanup()
  120. def gt_to_coco_json(self, gt_dicts: Sequence[dict],
  121. outfile_prefix: str) -> Tuple[str, str]:
  122. """Convert ground truth to coco panoptic segmentation format json file.
  123. Args:
  124. gt_dicts (Sequence[dict]): Ground truth of the dataset.
  125. outfile_prefix (str): The filename prefix of the json file. If the
  126. prefix is "somepath/xxx", the json file will be named
  127. "somepath/xxx.gt.json".
  128. Returns:
  129. Tuple[str, str]: The filename of the json file and the name of the\
  130. directory which contains panoptic segmentation masks.
  131. """
  132. assert len(gt_dicts) > 0, 'gt_dicts is empty.'
  133. gt_folder = osp.dirname(gt_dicts[0]['seg_map_path'])
  134. converted_json_path = f'{outfile_prefix}.gt.json'
  135. categories = []
  136. for id, name in enumerate(self.dataset_meta['classes']):
  137. isthing = 1 if name in self.dataset_meta['thing_classes'] else 0
  138. categories.append({'id': id, 'name': name, 'isthing': isthing})
  139. image_infos = []
  140. annotations = []
  141. for gt_dict in gt_dicts:
  142. img_id = gt_dict['image_id']
  143. image_info = {
  144. 'id': img_id,
  145. 'width': gt_dict['width'],
  146. 'height': gt_dict['height'],
  147. 'file_name': osp.split(gt_dict['seg_map_path'])[-1]
  148. }
  149. image_infos.append(image_info)
  150. pan_png = mmcv.imread(gt_dict['seg_map_path']).squeeze()
  151. pan_png = pan_png[:, :, ::-1]
  152. pan_png = rgb2id(pan_png)
  153. segments_info = []
  154. for segment_info in gt_dict['segments_info']:
  155. id = segment_info['id']
  156. label = segment_info['category']
  157. mask = pan_png == id
  158. isthing = categories[label]['isthing']
  159. if isthing:
  160. iscrowd = 1 if not segment_info['is_thing'] else 0
  161. else:
  162. iscrowd = 0
  163. new_segment_info = {
  164. 'id': id,
  165. 'category_id': label,
  166. 'isthing': isthing,
  167. 'iscrowd': iscrowd,
  168. 'area': mask.sum()
  169. }
  170. segments_info.append(new_segment_info)
  171. segm_file = image_info['file_name'].replace('jpg', 'png')
  172. annotation = dict(
  173. image_id=img_id,
  174. segments_info=segments_info,
  175. file_name=segm_file)
  176. annotations.append(annotation)
  177. pan_png = id2rgb(pan_png)
  178. info = dict(
  179. date_created=str(datetime.datetime.now()),
  180. description='Coco json file converted by mmdet CocoPanopticMetric.'
  181. )
  182. coco_json = dict(
  183. info=info,
  184. images=image_infos,
  185. categories=categories,
  186. licenses=None,
  187. )
  188. if len(annotations) > 0:
  189. coco_json['annotations'] = annotations
  190. dump(coco_json, converted_json_path)
  191. return converted_json_path, gt_folder
  192. def result2json(self, results: Sequence[dict],
  193. outfile_prefix: str) -> Tuple[str, str]:
  194. """Dump the panoptic results to a COCO style json file and a directory.
  195. Args:
  196. results (Sequence[dict]): Testing results of the dataset.
  197. outfile_prefix (str): The filename prefix of the json files and the
  198. directory.
  199. Returns:
  200. Tuple[str, str]: The json file and the directory which contains \
  201. panoptic segmentation masks. The filename of the json is
  202. "somepath/xxx.panoptic.json" and name of the directory is
  203. "somepath/xxx.panoptic".
  204. """
  205. label2cat = dict((v, k) for (k, v) in self.cat2label.items())
  206. pred_annotations = []
  207. for idx in range(len(results)):
  208. result = results[idx]
  209. for segment_info in result['segments_info']:
  210. sem_label = segment_info['category_id']
  211. # convert sem_label to json label
  212. cat_id = label2cat[sem_label]
  213. segment_info['category_id'] = label2cat[sem_label]
  214. is_thing = self.categories[cat_id]['isthing']
  215. segment_info['isthing'] = is_thing
  216. pred_annotations.append(result)
  217. pan_json_results = dict(annotations=pred_annotations)
  218. json_filename = f'{outfile_prefix}.panoptic.json'
  219. dump(pan_json_results, json_filename)
  220. return json_filename, (
  221. self.seg_out_dir
  222. if self.tmp_dir is None else tempfile.gettempdir())
  223. def _parse_predictions(self,
  224. pred: dict,
  225. img_id: int,
  226. segm_file: str,
  227. label2cat=None) -> dict:
  228. """Parse panoptic segmentation predictions.
  229. Args:
  230. pred (dict): Panoptic segmentation predictions.
  231. img_id (int): Image id.
  232. segm_file (str): Segmentation file name.
  233. label2cat (dict): Mapping from label to category id.
  234. Defaults to None.
  235. Returns:
  236. dict: Parsed predictions.
  237. """
  238. result = dict()
  239. result['img_id'] = img_id
  240. # shape (1, H, W) -> (H, W)
  241. pan = pred['pred_panoptic_seg']['sem_seg'].cpu().numpy()[0]
  242. ignore_index = pred['pred_panoptic_seg'].get(
  243. 'ignore_index', len(self.dataset_meta['classes']))
  244. pan_labels = np.unique(pan)
  245. segments_info = []
  246. for pan_label in pan_labels:
  247. sem_label = pan_label % INSTANCE_OFFSET
  248. # We reserve the length of dataset_meta['classes']
  249. # and ignore_index for VOID label
  250. if sem_label == len(
  251. self.dataset_meta['classes']) or sem_label == ignore_index:
  252. continue
  253. mask = pan == pan_label
  254. area = mask.sum()
  255. segments_info.append({
  256. 'id':
  257. int(pan_label),
  258. # when ann_file provided, sem_label should be cat_id, otherwise
  259. # sem_label should be a continuous id, not the cat_id
  260. # defined in dataset
  261. 'category_id':
  262. label2cat[sem_label] if label2cat else sem_label,
  263. 'area':
  264. int(area)
  265. })
  266. # evaluation script uses 0 for VOID label.
  267. pan[pan % INSTANCE_OFFSET == len(self.dataset_meta['classes'])] = VOID
  268. pan[pan % INSTANCE_OFFSET == ignore_index] = VOID
  269. pan = id2rgb(pan).astype(np.uint8)
  270. mmcv.imwrite(pan[:, :, ::-1], osp.join(self.seg_out_dir, segm_file))
  271. result = {
  272. 'image_id': img_id,
  273. 'segments_info': segments_info,
  274. 'file_name': segm_file
  275. }
  276. return result
  277. def _compute_batch_pq_stats(self, data_samples: Sequence[dict]):
  278. """Process gts and predictions when ``outfile_prefix`` is not set, gts
  279. are from dataset or a json file which is defined by ``ann_file``.
  280. Intermediate results, ``pq_stats``, are computed here and put into
  281. ``self.results``.
  282. """
  283. if self._coco_api is None:
  284. categories = dict()
  285. for id, name in enumerate(self.dataset_meta['classes']):
  286. isthing = 1 if name in self.dataset_meta['thing_classes']\
  287. else 0
  288. categories[id] = {'id': id, 'name': name, 'isthing': isthing}
  289. label2cat = None
  290. else:
  291. categories = self.categories
  292. cat_ids = self._coco_api.get_cat_ids(
  293. cat_names=self.dataset_meta['classes'])
  294. label2cat = {i: cat_id for i, cat_id in enumerate(cat_ids)}
  295. for data_sample in data_samples:
  296. # parse pred
  297. img_id = data_sample['img_id']
  298. segm_file = osp.basename(data_sample['img_path']).replace(
  299. 'jpg', 'png')
  300. result = self._parse_predictions(
  301. pred=data_sample,
  302. img_id=img_id,
  303. segm_file=segm_file,
  304. label2cat=label2cat)
  305. # parse gt
  306. gt = dict()
  307. gt['image_id'] = img_id
  308. gt['width'] = data_sample['ori_shape'][1]
  309. gt['height'] = data_sample['ori_shape'][0]
  310. gt['file_name'] = segm_file
  311. if self._coco_api is None:
  312. # get segments_info from data_sample
  313. seg_map_path = osp.join(self.seg_prefix, segm_file)
  314. pan_png = mmcv.imread(seg_map_path).squeeze()
  315. pan_png = pan_png[:, :, ::-1]
  316. pan_png = rgb2id(pan_png)
  317. segments_info = []
  318. for segment_info in data_sample['segments_info']:
  319. id = segment_info['id']
  320. label = segment_info['category']
  321. mask = pan_png == id
  322. isthing = categories[label]['isthing']
  323. if isthing:
  324. iscrowd = 1 if not segment_info['is_thing'] else 0
  325. else:
  326. iscrowd = 0
  327. new_segment_info = {
  328. 'id': id,
  329. 'category_id': label,
  330. 'isthing': isthing,
  331. 'iscrowd': iscrowd,
  332. 'area': mask.sum()
  333. }
  334. segments_info.append(new_segment_info)
  335. else:
  336. # get segments_info from annotation file
  337. segments_info = self._coco_api.imgToAnns[img_id]
  338. gt['segments_info'] = segments_info
  339. pq_stats = pq_compute_single_core(
  340. proc_id=0,
  341. annotation_set=[(gt, result)],
  342. gt_folder=self.seg_prefix,
  343. pred_folder=self.seg_out_dir,
  344. categories=categories,
  345. backend_args=self.backend_args)
  346. self.results.append(pq_stats)
  347. def _process_gt_and_predictions(self, data_samples: Sequence[dict]):
  348. """Process gts and predictions when ``outfile_prefix`` is set.
  349. The predictions will be saved to directory specified by
  350. ``outfile_predfix``. The matched pair (gt, result) will be put into
  351. ``self.results``.
  352. """
  353. for data_sample in data_samples:
  354. # parse pred
  355. img_id = data_sample['img_id']
  356. segm_file = osp.basename(data_sample['img_path']).replace(
  357. 'jpg', 'png')
  358. result = self._parse_predictions(
  359. pred=data_sample, img_id=img_id, segm_file=segm_file)
  360. # parse gt
  361. gt = dict()
  362. gt['image_id'] = img_id
  363. gt['width'] = data_sample['ori_shape'][1]
  364. gt['height'] = data_sample['ori_shape'][0]
  365. if self._coco_api is None:
  366. # get segments_info from dataset
  367. gt['segments_info'] = data_sample['segments_info']
  368. gt['seg_map_path'] = data_sample['seg_map_path']
  369. self.results.append((gt, result))
  370. # TODO: data_batch is no longer needed, consider adjusting the
  371. # parameter position
  372. def process(self, data_batch: dict, data_samples: Sequence[dict]) -> None:
  373. """Process one batch of data samples and predictions. The processed
  374. results should be stored in ``self.results``, which will be used to
  375. compute the metrics when all batches have been processed.
  376. Args:
  377. data_batch (dict): A batch of data from the dataloader.
  378. data_samples (Sequence[dict]): A batch of data samples that
  379. contain annotations and predictions.
  380. """
  381. # If ``self.tmp_dir`` is none, it will save gt and predictions to
  382. # self.results, otherwise, it will compute pq_stats here.
  383. if self.tmp_dir is None:
  384. self._process_gt_and_predictions(data_samples)
  385. else:
  386. self._compute_batch_pq_stats(data_samples)
  387. def compute_metrics(self, results: list) -> Dict[str, float]:
  388. """Compute the metrics from processed results.
  389. Args:
  390. results (list): The processed results of each batch. There
  391. are two cases:
  392. - When ``outfile_prefix`` is not provided, the elements in
  393. results are pq_stats which can be summed directly to get PQ.
  394. - When ``outfile_prefix`` is provided, the elements in
  395. results are tuples like (gt, pred).
  396. Returns:
  397. Dict[str, float]: The computed metrics. The keys are the names of
  398. the metrics, and the values are corresponding results.
  399. """
  400. logger: MMLogger = MMLogger.get_current_instance()
  401. if self.tmp_dir is None:
  402. # do evaluation after collect all the results
  403. # split gt and prediction list
  404. gts, preds = zip(*results)
  405. if self._coco_api is None:
  406. # use converted gt json file to initialize coco api
  407. logger.info('Converting ground truth to coco format...')
  408. coco_json_path, gt_folder = self.gt_to_coco_json(
  409. gt_dicts=gts, outfile_prefix=self.outfile_prefix)
  410. self._coco_api = COCOPanoptic(coco_json_path)
  411. else:
  412. gt_folder = self.seg_prefix
  413. self.cat_ids = self._coco_api.get_cat_ids(
  414. cat_names=self.dataset_meta['classes'])
  415. self.cat2label = {
  416. cat_id: i
  417. for i, cat_id in enumerate(self.cat_ids)
  418. }
  419. self.img_ids = self._coco_api.get_img_ids()
  420. self.categories = self._coco_api.cats
  421. # convert predictions to coco format and dump to json file
  422. json_filename, pred_folder = self.result2json(
  423. results=preds, outfile_prefix=self.outfile_prefix)
  424. if self.format_only:
  425. logger.info('results are saved in '
  426. f'{osp.dirname(self.outfile_prefix)}')
  427. return dict()
  428. imgs = self._coco_api.imgs
  429. gt_json = self._coco_api.img_ann_map
  430. gt_json = [{
  431. 'image_id': k,
  432. 'segments_info': v,
  433. 'file_name': imgs[k]['segm_file']
  434. } for k, v in gt_json.items()]
  435. pred_json = load(json_filename)
  436. pred_json = dict(
  437. (el['image_id'], el) for el in pred_json['annotations'])
  438. # match the gt_anns and pred_anns in the same image
  439. matched_annotations_list = []
  440. for gt_ann in gt_json:
  441. img_id = gt_ann['image_id']
  442. if img_id not in pred_json.keys():
  443. raise Exception('no prediction for the image'
  444. ' with id: {}'.format(img_id))
  445. matched_annotations_list.append((gt_ann, pred_json[img_id]))
  446. pq_stat = pq_compute_multi_core(
  447. matched_annotations_list,
  448. gt_folder,
  449. pred_folder,
  450. self.categories,
  451. backend_args=self.backend_args,
  452. nproc=self.nproc)
  453. else:
  454. # aggregate the results generated in process
  455. if self._coco_api is None:
  456. categories = dict()
  457. for id, name in enumerate(self.dataset_meta['classes']):
  458. isthing = 1 if name in self.dataset_meta[
  459. 'thing_classes'] else 0
  460. categories[id] = {
  461. 'id': id,
  462. 'name': name,
  463. 'isthing': isthing
  464. }
  465. self.categories = categories
  466. pq_stat = PQStat()
  467. for result in results:
  468. pq_stat += result
  469. metrics = [('All', None), ('Things', True), ('Stuff', False)]
  470. pq_results = {}
  471. for name, isthing in metrics:
  472. pq_results[name], classwise_results = pq_stat.pq_average(
  473. self.categories, isthing=isthing)
  474. if name == 'All':
  475. pq_results['classwise'] = classwise_results
  476. classwise_results = None
  477. if self.classwise:
  478. classwise_results = {
  479. k: v
  480. for k, v in zip(self.dataset_meta['classes'],
  481. pq_results['classwise'].values())
  482. }
  483. print_panoptic_table(pq_results, classwise_results, logger=logger)
  484. results = parse_pq_results(pq_results)
  485. return results
  486. def parse_pq_results(pq_results: dict) -> dict:
  487. """Parse the Panoptic Quality results.
  488. Args:
  489. pq_results (dict): Panoptic Quality results.
  490. Returns:
  491. dict: Panoptic Quality results parsed.
  492. """
  493. result = dict()
  494. result['PQ'] = 100 * pq_results['All']['pq']
  495. result['SQ'] = 100 * pq_results['All']['sq']
  496. result['RQ'] = 100 * pq_results['All']['rq']
  497. result['PQ_th'] = 100 * pq_results['Things']['pq']
  498. result['SQ_th'] = 100 * pq_results['Things']['sq']
  499. result['RQ_th'] = 100 * pq_results['Things']['rq']
  500. result['PQ_st'] = 100 * pq_results['Stuff']['pq']
  501. result['SQ_st'] = 100 * pq_results['Stuff']['sq']
  502. result['RQ_st'] = 100 * pq_results['Stuff']['rq']
  503. return result
  504. def print_panoptic_table(
  505. pq_results: dict,
  506. classwise_results: Optional[dict] = None,
  507. logger: Optional[Union['MMLogger', str]] = None) -> None:
  508. """Print the panoptic evaluation results table.
  509. Args:
  510. pq_results(dict): The Panoptic Quality results.
  511. classwise_results(dict, optional): The classwise Panoptic Quality.
  512. results. The keys are class names and the values are metrics.
  513. Defaults to None.
  514. logger (:obj:`MMLogger` | str, optional): Logger used for printing
  515. related information during evaluation. Default: None.
  516. """
  517. headers = ['', 'PQ', 'SQ', 'RQ', 'categories']
  518. data = [headers]
  519. for name in ['All', 'Things', 'Stuff']:
  520. numbers = [
  521. f'{(pq_results[name][k] * 100):0.3f}' for k in ['pq', 'sq', 'rq']
  522. ]
  523. row = [name] + numbers + [pq_results[name]['n']]
  524. data.append(row)
  525. table = AsciiTable(data)
  526. print_log('Panoptic Evaluation Results:\n' + table.table, logger=logger)
  527. if classwise_results is not None:
  528. class_metrics = [(name, ) + tuple(f'{(metrics[k] * 100):0.3f}'
  529. for k in ['pq', 'sq', 'rq'])
  530. for name, metrics in classwise_results.items()]
  531. num_columns = min(8, len(class_metrics) * 4)
  532. results_flatten = list(itertools.chain(*class_metrics))
  533. headers = ['category', 'PQ', 'SQ', 'RQ'] * (num_columns // 4)
  534. results_2d = itertools.zip_longest(
  535. *[results_flatten[i::num_columns] for i in range(num_columns)])
  536. data = [headers]
  537. data += [result for result in results_2d]
  538. table = AsciiTable(data)
  539. print_log(
  540. 'Classwise Panoptic Evaluation Results:\n' + table.table,
  541. logger=logger)