本文整理匯總了Python中pycocotools.cocoeval.COCOeval方法的典型用法代碼示例。如果您正苦於以下問題:Python cocoeval.COCOeval方法的具體用法?Python cocoeval.COCOeval怎麽用?Python cocoeval.COCOeval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pycocotools.cocoeval
的用法示例。
在下文中一共展示了cocoeval.COCOeval方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: evaluate_predictions_on_coco
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate_predictions_on_coco(
coco_gt, coco_results, json_result_file, iou_type="bbox"
):
import json
with open(json_result_file, "w") as f:
json.dump(coco_results, f)
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
coco_dt = coco_gt.loadRes(str(json_result_file)) if coco_results else COCO()
# coco_dt = coco_gt.loadRes(coco_results)
coco_eval = COCOeval(coco_gt, coco_dt, iou_type)
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
return coco_eval
示例2: evaluate
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate(self, path_to_results_dir: str, image_ids: List[str], bboxes: List[List[float]], classes: List[int], probs: List[float]) -> Tuple[float, str]:
self._write_results(path_to_results_dir, image_ids, bboxes, classes, probs)
annType = 'bbox'
path_to_coco_dir = os.path.join(self._path_to_data_dir, 'COCO')
path_to_annotations_dir = os.path.join(path_to_coco_dir, 'annotations')
path_to_annotation = os.path.join(path_to_annotations_dir, 'instances_val2017.json')
cocoGt = COCO(path_to_annotation)
cocoDt = cocoGt.loadRes(os.path.join(path_to_results_dir, 'results.json'))
cocoEval = COCOeval(cocoGt, cocoDt, annType)
cocoEval.evaluate()
cocoEval.accumulate()
original_stdout = sys.stdout
string_stdout = StringIO()
sys.stdout = string_stdout
cocoEval.summarize()
sys.stdout = original_stdout
mean_ap = cocoEval.stats[0].item() # stats[0] records AP@[0.5:0.95]
detail = string_stdout.getvalue()
return mean_ap, detail
示例3: __init__
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def __init__(self, groundtruth=None, detections=None, agnostic_mode=False,
iou_type='bbox'):
"""COCOEvalWrapper constructor.
Note that for the area-based metrics to be meaningful, detection and
groundtruth boxes must be in image coordinates measured in pixels.
Args:
groundtruth: a coco.COCO (or coco_tools.COCOWrapper) object holding
groundtruth annotations
detections: a coco.COCO (or coco_tools.COCOWrapper) object holding
detections
agnostic_mode: boolean (default: False). If True, evaluation ignores
class labels, treating all detections as proposals.
iou_type: IOU type to use for evaluation. Supports `bbox` or `segm`.
"""
cocoeval.COCOeval.__init__(self, groundtruth, detections,
iouType=iou_type)
if agnostic_mode:
self.params.useCats = 0
示例4: evaluate_predictions_on_coco
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate_predictions_on_coco(coco_gt, coco_results, json_result_file, iou_type="bbox"):
if iou_type != "uv":
with open(json_result_file, "w") as f:
json.dump(coco_results, f)
coco_dt = coco_gt.loadRes(str(json_result_file)) if coco_results else COCO()
# coco_dt = coco_gt.loadRes(coco_results)
coco_eval = COCOeval(coco_gt, coco_dt, iou_type)
coco_eval.evaluate()
else:
calc_mode = 'GPSm' if cfg.UVRCNN.GPSM_ON else 'GPS'
pkl_result_file = json_result_file.replace('.json', '.pkl')
with open(pkl_result_file, 'wb') as f:
pickle.dump(coco_results, f, 2)
if cfg.TEST.DATASETS[0].find('test') > -1:
return
eval_data_dir = cfg.DATA_DIR + '/DensePoseData/eval_data/'
coco_dt = coco_gt.loadRes(coco_results)
test_sigma = 0.255
coco_eval = denseposeCOCOeval(eval_data_dir, coco_gt, coco_dt, iou_type, test_sigma)
coco_eval.evaluate(calc_mode=calc_mode)
coco_eval.accumulate()
if iou_type == "bbox":
_print_detection_eval_metrics(coco_gt, coco_eval)
coco_eval.summarize()
return coco_eval
示例5: update
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def update(self, coco_eval):
if coco_eval is None:
return
assert isinstance(coco_eval, (COCOeval, denseposeCOCOeval))
s = coco_eval.stats
iou_type = coco_eval.params.iouType
res = self.results[iou_type]
metrics = COCOResults.METRICS[iou_type]
if iou_type == 'uv':
idx_map = [0, 1, 6, 11, 12]
for idx, metric in enumerate(metrics):
res[metric] = s[idx_map[idx]]
else:
for idx, metric in enumerate(metrics):
res[metric] = s[idx]
示例6: summarize
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def summarize(predictions, annotations_file, img_list, mask=False):
msk_map = 0
with tempfile.NamedTemporaryFile("w") as fid:
json.dump(predictions, fid)
fid.flush()
# Detection
gt = COCO(annotations_file, img_list)
pred = gt.loadRes(fid.name)
pred_eval = COCOeval(gt, pred, "bbox")
pred_eval.evaluate()
pred_eval.accumulate()
pred_eval.summarize()
det_map = pred_eval.stats[0]
if mask:
pred_eval = COCOeval(gt, pred, "segm")
pred_eval.evaluate()
pred_eval.accumulate()
pred_eval.summarize()
msk_map = pred_eval.stats[0]
return det_map, msk_map
示例7: evaluate
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate(self, result_json, cls_ids, image_ids):
from pycocotools.cocoeval import COCOeval
if self._split == "testdev":
return None
coco = self._coco
eval_ids = [self._eval_ids[image_id] for image_id in image_ids]
cat_ids = [self._cls2coco[cls_id] for cls_id in cls_ids]
coco_dets = coco.loadRes(result_json)
coco_eval = COCOeval(coco, coco_dets, "bbox")
coco_eval.params.imgIds = eval_ids
coco_eval.params.catIds = cat_ids
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
return coco_eval.stats[0], coco_eval.stats[12:]
示例8: after_run
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def after_run(self, sess):
print("Detection Finished ...")
# for item in self.detection:
# print(item)
if len(self.detection) > 0:
annotation_file = os.path.join(
DATASET_DIR,
"annotations",
"instances_" + DATASET_META + ".json")
coco = COCO(annotation_file)
coco_results = coco.loadRes(self.detection)
# DETECTION_FILE = "/home/ubuntu/data/mscoco/results/SSD_512x512_score/detections_minival_ssd512_results.json"
# coco_results = coco.loadRes(DETECTION_FILE)
cocoEval = COCOeval(coco, coco_results, "bbox")
cocoEval.params.imgIds = self.image_ids
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
else:
print("Found no valid detection. Consider re-train your model.")
示例9: _update
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def _update(self):
"""Use coco to get real scores. """
import json
try:
with open(self._filename, 'w') as f:
json.dump(self._results, f)
except IOError as e:
raise RuntimeError("Unable to dump json file, ignored. What(): {}".format(str(e)))
pred = self.dataset.coco.loadRes(self._filename)
gt = self.dataset.coco
# lazy import pycocotools
from ...data.mscoco.utils import try_import_pycocotools
try_import_pycocotools()
from pycocotools.cocoeval import COCOeval
coco_eval = COCOeval(gt, pred, 'keypoints')
coco_eval.params.useSegm = None
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
self._coco_eval = coco_eval
return coco_eval
示例10: evaluate_predictions_on_coco
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate_predictions_on_coco(
coco_gt, coco_results, json_result_file, iou_type="bbox"
):
import json
with open(json_result_file, "w") as f:
json.dump(coco_results, f)
from pycocotools.cocoeval import COCOeval
coco_dt = coco_gt.loadRes(str(json_result_file))
# coco_dt = coco_gt.loadRes(coco_results)
coco_eval = COCOeval(coco_gt, coco_dt, iou_type)
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
return coco_eval
示例11: finalize_saving_epoch_measures
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def finalize_saving_epoch_measures(self):
self.detections_file.write("]")
self.detections_file.close()
self.detections_file = None
cocoDt = self.coco.loadRes(self.det_file_path)
from pycocotools.cocoeval import COCOeval
cocoEval = COCOeval(self.coco, cocoDt, 'bbox')
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
new_measures = {Measures.MAP_BBOX: cocoEval.stats[0]}
if self.add_masks:
cocoEval = COCOeval(self.coco, cocoDt, 'segm')
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
new_measures[Measures.MAP_SEGM] = cocoEval.stats[0]
return new_measures
示例12: _do_detection_eval
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def _do_detection_eval(self, res_file, output_dir):
ann_type = 'bbox'
coco_dt = self._COCO.loadRes(res_file)
coco_eval = COCOeval(self._COCO, coco_dt)
coco_eval.params.useSegm = (ann_type == 'segm')
coco_eval.evaluate()
coco_eval.accumulate()
self._print_detection_eval_metrics(coco_eval)
eval_file = osp.join(output_dir, 'detection_results.pkl')
with open(eval_file, 'wb') as fid:
pickle.dump(coco_eval, fid, pickle.HIGHEST_PROTOCOL)
print('Wrote COCO eval results to: {}'.format(eval_file))
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:14,代碼來源:coco.py
示例13: coco_eval_with_return
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def coco_eval_with_return(result_files,
result_types,
coco,
max_dets=(100, 300, 1000)):
for res_type in result_types:
assert res_type in ['proposal', 'bbox', 'segm', 'keypoints']
if mmcv.is_str(coco):
coco = COCO(coco)
assert isinstance(coco, COCO)
eval_results = {}
for res_type in result_types:
result_file = result_files[res_type]
assert result_file.endswith('.json')
coco_dets = coco.loadRes(result_file)
img_ids = coco.getImgIds()
iou_type = 'bbox' if res_type == 'proposal' else res_type
cocoEval = COCOeval(coco, coco_dets, iou_type)
cocoEval.params.imgIds = img_ids
if res_type == 'proposal':
cocoEval.params.useCats = 0
cocoEval.params.maxDets = list(max_dets)
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
if res_type == 'segm' or res_type == 'bbox':
metric_names = [
'AP', 'AP50', 'AP75', 'APs', 'APm', 'APl', 'AR1', 'AR10',
'AR100', 'ARs', 'ARm', 'ARl'
]
eval_results[res_type] = {
metric_names[i]: cocoEval.stats[i]
for i in range(len(metric_names))
}
else:
eval_results[res_type] = cocoEval.stats
return eval_results
示例14: _do_python_eval
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def _do_python_eval(self, _coco):
coco_dt = _coco.loadRes(self._result_file)
coco_eval = COCOeval(_coco, coco_dt)
coco_eval.params.useSegm = False
coco_eval.evaluate()
coco_eval.accumulate()
self._print_detection_metrics(coco_eval)
示例15: evaluate
# 需要導入模塊: from pycocotools import cocoeval [as 別名]
# 或者: from pycocotools.cocoeval import COCOeval [as 別名]
def evaluate(self, path_to_results_dir: str, image_ids: List[str], bboxes: List[List[float]], classes: List[int], probs: List[float]) -> Tuple[float, str]:
self._write_results(path_to_results_dir, image_ids, bboxes, classes, probs)
annType = 'bbox'
path_to_coco_dir = os.path.join(self._path_to_data_dir, 'COCO')
path_to_annotations_dir = os.path.join(path_to_coco_dir, 'annotations')
path_to_annotation = os.path.join(path_to_annotations_dir, 'instances_val2017.json')
cocoGt = COCO(path_to_annotation)
cocoDt = cocoGt.loadRes(os.path.join(path_to_results_dir, 'results.json'))
cocoEval = COCOeval(cocoGt, cocoDt, annType)
cocoEval.params.catIds = [COCO2017.CATEGORY_TO_LABEL_DICT[category] # filtering label should refer to original `COCO2017` dataset
for category in COCO2017Animal.CATEGORY_TO_LABEL_DICT.keys()]
cocoEval.evaluate()
cocoEval.accumulate()
original_stdout = sys.stdout
string_stdout = StringIO()
sys.stdout = string_stdout
cocoEval.summarize()
sys.stdout = original_stdout
mean_ap = cocoEval.stats[0].item() # stats[0] records AP@[0.5:0.95]
detail = string_stdout.getvalue()
return mean_ap, detail