docstr: Convert instance segmentation results to COCO json style.
docstr_tok: ["Convert","instance","segmentation","results","to","COCO","json","style","."]
code: def _segm2json(self, results):
      """Convert instance segmentation results to COCO json style."""
      bbox_json_results = []
      segm_json_results = []
      for idx in range(len(self)):
          img_id = self.img_ids[idx]
          det, seg = results[idx]
          for label in range(len(det)):
              # bbox results
              bboxes = det[label]
              for i in range(bboxes.shape[0]):
                  data = dict()
                  data["image_id"] = img_id
                  data["bbox"] = self.xyxy2xywh(bboxes[i])
                  data["score"] = float(bboxes[i][4])
                  data["category_id"] = self.cat_ids[label]
                  bbox_json_results.append(data)
  
              # segm results
              # some detectors use different scores for bbox and mask
              if isinstance(seg, tuple):
                  segms = seg[0][label]
                  mask_score = seg[1][label]
              else:
                  segms = seg[label]
                  mask_score = [bbox[4] for bbox in bboxes]
              for i in range(bboxes.shape[0]):
                  data = dict()
                  data["image_id"] = img_id
                  data["bbox"] = self.xyxy2xywh(bboxes[i])
                  data["score"] = float(mask_score[i])
                  data["category_id"] = self.cat_ids[label]
                  if isinstance(segms[i]["counts"], bytes):
                      segms[i]["counts"] = segms[i]["counts"].decode()
                  data["segmentation"] = segms[i]
                  segm_json_results.append(data)
      return bbox_json_results, segm_json_results
  
imports: import itertools
  import logging
  import os.path
  import tempfile
  from collections import OrderedDict
  import mmcv
  import numpy
  from mmcv.utils import print_log
  from pycocotools.coco import COCO
  from pycocotools.cocoeval import COCOeval
  from terminaltables import AsciiTable
  from mmdet.core import eval_recalls
  from .builder import DATASETS
  from .custom import CustomDataset
label_desc: Use image node_id 9 for calling the CocoDataset obj's underlying member method code with example usage: obj._segm2json(results) and returns: bbox_json_results,  segm_json_results