调用pycocotools计算mAP

from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import json
from tempfile import NamedTemporaryFile

# coco格式的json文件,原始标注数据
anno_file = '/home/j_m/Desktop/val/val.json'
coco_gt = COCO(anno_file)

# 用GT框作为预测框进行计算,目的是得到detection_res
with open(anno_file, 'r') as f:
    json_file = json.load(f)
annotations = json_file['annotations']
detection_res = []
for anno in annotations:
    detection_res.append({
        'score': 1.,
        'category_id': anno['category_id'],
        'bbox': anno['bbox'],
        'image_id': anno['image_id']
    })

with NamedTemporaryFile(suffix='.json') as tf:
    # 由于后续需要,先将detection_res转换成二进制后写入json文件
    content = json.dumps(detection_res).encode(encoding='utf-8')
    tf.write(content)
    res_path = tf.name

    # loadRes会在coco_gt的基础上生成一个新的COCO类型的instance并返回
    coco_dt &
  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值