COCOeval类简介

  1. class COCOeval:
  2. # Interface for evaluating detection on the Microsoft COCO dataset.
  3. #
  4. # The usage for CocoEval is as follows:
  5. # cocoGt=..., cocoDt=... # load dataset and results
  6. # E = CocoEval(cocoGt,cocoDt); # initialize CocoEval object
  7. # E.params.recThrs = ...; # set parameters as desired
  8. # E.evaluate(); # run per image evaluation
  9. # E.accumulate(); # accumulate per image results
  10. # E.summarize(); # display summary metrics of results
  11. # For example usage see evalDemo.m and http://mscoco.org/.
  12. #
  13. # The evaluation parameters are as follows (defaults in brackets):
  14. # imgIds - [all] N img ids to use for evaluation
  15. # catIds - [all] K cat ids to use for evaluation
  16. # iouThrs - [.5:.05:.95] T=10 IoU thresholds for evaluation
  17. # recThrs - [0:.01:1] R=101 recall thresholds for evaluation
  18. # areaRng - [...] A=4 object area ranges for evaluation
  19. # maxDets - [1 10 100] M=3 thresholds on max detections per image
  20. # iouType - ['segm'] set iouType to 'segm', 'bbox' or 'keypoints'
  21. # iouType replaced the now DEPRECATED useSegm parameter.
  22. # useCats - [1] if true use category labels for evaluation
  23. # Note: if useCats=0 category labels are ignored as in proposal scoring.
  24. # Note: multiple areaRngs [Ax2] and maxDets [Mx1] can be specified.
  25. #
  26. # evaluate(): evaluates detections on every image and every category and
  27. # concats the results into the "evalImgs" with fields:
  28. # dtIds - [1xD] id for each of the D detections (dt)
  29. # gtIds - [1xG] id for each of the G ground truths (gt)
  30. # dtMatches - [TxD] matching gt id at each IoU or 0
  31. # gtMatches - [TxG] matching dt id at each IoU or 0
  32. # dtScores - [1xD] confidence of each dt
  33. # gtIgnore - [1xG] ignore flag for each gt
  34. # dtIgnore - [TxD] ignore flag for each dt at each IoU
  35. #
  36. # accumulate(): accumulates the per-image, per-category evaluation
  37. # results in "evalImgs" into the dictionary "eval" with fields:
  38. # params - parameters used for evaluation
  39. # date - date evaluation was performed
  40. # counts - [T,R,K,A,M] parameter dimensions (see above)
  41. # precision - [TxRxKxAxM] precision for every evaluation setting
  42. # recall - [TxKxAxM] max recall for every evaluation setting
  43. # Note: precision and recall==-1 for settings with no gt objects.
  44. #
  45. # See also coco, mask, pycocoDemo, pycocoEvalDemo
  46. #
  47. # Microsoft COCO Toolbox. version 2.0
  48. # Data, paper, and tutorials available at: http://mscoco.org/
  49. # Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
  50. # Licensed under the Simplified BSD License [see coco/license.txt]
  51. def __init__(self, cocoGt=None, cocoDt=None, iouType='segm'):
  52. '''
  53. Initialize CocoEval using coco APIs for gt and dt
  54. :param cocoGt: coco object with ground truth annotations
  55. :param cocoDt: coco object with detection results
  56. :return: None
  57. '''
  58. if not iouType:
  59. print('iouType not specified. use default iouType segm')
  60. self.cocoGt = cocoGt # ground truth COCO API
  61. self.cocoDt = cocoDt # detections COCO API
  62. self.evalImgs = defaultdict(list) # per-image per-category evaluation results [KxAxI] elements
  63. self.eval = {} # accumulated evaluation results
  64. self._gts = defaultdict(list) # gt for evaluation
  65. self._dts = defaultdict(list) # dt for evaluation
  66. self.params = Params(iouType=iouType) # parameters
  67. self._paramsEval = {} # parameters for evaluation
  68. self.stats = [] # result summarization
  69. self.ious = {} # ious between all gts and dts
  70. if not cocoGt is None:
  71. self.params.imgIds = sorted(cocoGt.getImgIds())
  72. self.params.catIds = sorted(cocoGt.getCatIds())

调用方法如下

  1. # running evaluation
  2. cocoEval = COCOeval(cocoGt,cocoDt,annType)
  3. cocoEval.evaluate()
  4. cocoEval.accumulate()
  5. cocoEval.summarize()

cocoGt和cocoDt为COCO对象,初始化函数参数为标注json文件

  1. class COCO:
  2. def __init__(self, annotation_file=None):
  3. """
  4. Constructor of Microsoft COCO helper class for reading and visualizing annotations.
  5. :param annotation_file (str): location of annotation file
  6. :param image_folder (str): location to the folder that hosts images.
  7. :return:
  8. """
  9. # load dataset
  10. self.dataset,self.anns,self.cats,self.imgs = dict(),dict(),dict(),dict()
  11. self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list)
  12. if not annotation_file == None:
  13. print('loading annotations into memory...')
  14. tic = time.time()
  15. dataset = json.load(open(annotation_file, 'r'))
  16. assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))
  17. print('Done (t={:0.2f}s)'.format(time.time()- tic))
  18. self.dataset = dataset
  19. self.createIndex()

COCOeval接口使用的更多相关文章

  1. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  2. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  3. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

  4. Java基础Map接口+Collections工具类

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  5. Java基础Map接口+Collections

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  6. java基础_集合List与Set接口

    List接口继承了Collection的方法  当然也有自己特有的方法向指定位置添加元素   add(索引,添加的元素); 移除指定索引的元素   remove(索引) 修改指定索引的元素   set ...

  7. 【WCF】自定义错误处理(IErrorHandler接口的用法)

    当被调用的服务操作发生异常时,可以直接把异常的原始内容传回给客户端.在WCF中,服务器传回客户端的异常,通常会使用 FaultException,该异常由这么几个东东组成: 1.Action:在服务调 ...

  8. PHP以接口方式实现多重继承(完全模拟)--学习笔记

     1.UML类图: 2.PHP代码: <?php /** * Created by PhpStorm. * User: andy * Date: 16-11-23 * Time: 下午7:57 ...

  9. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo

    Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...

随机推荐

  1. 金字塔原理(Pyramid Principle)

    什么是金字塔原理?简单来说,金字塔原理就是“中心论点---分论点---支撑论据”这样的一个结构. 图片摘自:http://www.woshipm.com/pmd/306704.html 人类通常习惯于 ...

  2. JS实现Base64编码、解码,即window.atob,window.btoa功能

    window.atob(),window.btoa()方法可以对字符串精选base64编码和解码,但是有些环境比如nuxt的服务端环境没法使用window,所以需要自己实现一个base64的编码解码功 ...

  3. epoll 或者 kqueue 的原理是什么?

    来自知乎:http://www.zhihu.com/question/20122137 epoll 或者 kqueue 的原理是什么? 为什么epoll和kqueue可以用基于事件的方式,单线程的实现 ...

  4. from bs4 import BeautifulSoup 引入需要安装的文件和步骤

    调用beautifulsoup库时,运行后提示错误: ImportError: No module named bs4 , 意思就是没有找到bs4模块,所以解决方法就是将bs4安装上,具体步骤如下: ...

  5. deepnude | 福利

    程序好下载github有,但是没有lib,就是没有训练好的model. 以下是搜到的win平台程序的下载链接: magnet:?xt=urn:btih:7BE4EB8D640742D2FFEBD649 ...

  6. springboot整合mybaties

    在pom.xml中添加相关依赖. <!--MyBatis分页插件--> <dependency> <groupId>com.github.pagehelper< ...

  7. accept 和 content-Type区别

    accept表示 客服端(浏览器)支持的类型,也是希望服务器响应发送回来的的数据类型. 例如:Accept:text/xml; ,也就是希望服务器响应发送回来的是xml文本格式的内容 区别: 1.Ac ...

  8. Docker 搭建本地 cnpm 私有仓库

    1.首先启动本地的docker 2.下载 cnpm 仓库 git clone https://github.com/cnpm/cnpmjs.org.git 3.进入到 cnpmjs.org目录 cd ...

  9. [简短问答]C-Lodop中一些测试用的地址

    测试访问:访问http://localhost:8000欢迎页面试试进入欢迎页面http://localhost:8000,点欢迎页面的预览试试 查看下c-lodop启动界面,在设置里查看下当前启动的 ...

  10. LeetCode:第K个排列【60】

    LeetCode:第K个排列[60] 题目描述 给出集合 [1,2,3,…,n],其所有元素共有 n! 种排列. 按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: &quo ...