pcb defect detetcion application
[ealt-edge.git] / example-apps / PDD / pcb-defect-detection / data / lib_coco / PythonAPI / pycocoEvalDemo.ipynb
1 {
2  "cells": [
3   {
4    "cell_type": "code",
5    "execution_count": 1,
6    "metadata": {
7     "collapsed": false
8    },
9    "outputs": [],
10    "source": [
11     "%matplotlib inline\n",
12     "import matplotlib.pyplot as plt\n",
13     "from pycocotools.coco import COCO\n",
14     "from pycocotools.cocoeval import COCOeval\n",
15     "import numpy as np\n",
16     "import skimage.io as io\n",
17     "import pylab\n",
18     "pylab.rcParams['figure.figsize'] = (10.0, 8.0)"
19    ]
20   },
21   {
22    "cell_type": "code",
23    "execution_count": 2,
24    "metadata": {
25     "collapsed": false
26    },
27    "outputs": [
28     {
29      "name": "stdout",
30      "output_type": "stream",
31      "text": [
32       "Running demo for *bbox* results.\n"
33      ]
34     }
35    ],
36    "source": [
37     "annType = ['segm','bbox','keypoints']\n",
38     "annType = annType[1]      #specify type here\n",
39     "prefix = 'person_keypoints' if annType=='keypoints' else 'instances'\n",
40     "print 'Running demo for *%s* results.'%(annType)"
41    ]
42   },
43   {
44    "cell_type": "code",
45    "execution_count": 3,
46    "metadata": {
47     "collapsed": false
48    },
49    "outputs": [
50     {
51      "name": "stdout",
52      "output_type": "stream",
53      "text": [
54       "loading annotations into memory...\n",
55       "Done (t=8.01s)\n",
56       "creating index...\n",
57       "index created!\n"
58      ]
59     }
60    ],
61    "source": [
62     "#initialize COCO ground truth api\n",
63     "dataDir='../'\n",
64     "dataType='val2014'\n",
65     "annFile = '%s/annotations/%s_%s.json'%(dataDir,prefix,dataType)\n",
66     "cocoGt=COCO(annFile)"
67    ]
68   },
69   {
70    "cell_type": "code",
71    "execution_count": 4,
72    "metadata": {
73     "collapsed": false
74    },
75    "outputs": [
76     {
77      "name": "stdout",
78      "output_type": "stream",
79      "text": [
80       "Loading and preparing results...     \n",
81       "DONE (t=0.05s)\n",
82       "creating index...\n",
83       "index created!\n"
84      ]
85     }
86    ],
87    "source": [
88     "#initialize COCO detections api\n",
89     "resFile='%s/results/%s_%s_fake%s100_results.json'\n",
90     "resFile = resFile%(dataDir, prefix, dataType, annType)\n",
91     "cocoDt=cocoGt.loadRes(resFile)"
92    ]
93   },
94   {
95    "cell_type": "code",
96    "execution_count": 5,
97    "metadata": {
98     "collapsed": false
99    },
100    "outputs": [],
101    "source": [
102     "imgIds=sorted(cocoGt.getImgIds())\n",
103     "imgIds=imgIds[0:100]\n",
104     "imgId = imgIds[np.random.randint(100)]"
105    ]
106   },
107   {
108    "cell_type": "code",
109    "execution_count": 6,
110    "metadata": {
111     "collapsed": false
112    },
113    "outputs": [
114     {
115      "name": "stdout",
116      "output_type": "stream",
117      "text": [
118       "Running per image evaluation...      \n",
119       "DONE (t=0.46s).\n",
120       "Accumulating evaluation results...   \n",
121       "DONE (t=0.38s).\n",
122       " Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.505\n",
123       " Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.697\n",
124       " Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.573\n",
125       " Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.586\n",
126       " Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.519\n",
127       " Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.501\n",
128       " Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.387\n",
129       " Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.594\n",
130       " Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.595\n",
131       " Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.640\n",
132       " Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.566\n",
133       " Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.564\n"
134      ]
135     }
136    ],
137    "source": [
138     "# running evaluation\n",
139     "cocoEval = COCOeval(cocoGt,cocoDt,annType)\n",
140     "cocoEval.params.imgIds  = imgIds\n",
141     "cocoEval.evaluate()\n",
142     "cocoEval.accumulate()\n",
143     "cocoEval.summarize()"
144    ]
145   }
146  ],
147  "metadata": {
148   "kernelspec": {
149    "display_name": "Python 2",
150    "language": "python",
151    "name": "python2"
152   },
153   "language_info": {
154    "codemirror_mode": {
155     "name": "ipython",
156     "version": 2
157    },
158    "file_extension": ".py",
159    "mimetype": "text/x-python",
160    "name": "python",
161    "nbconvert_exporter": "python",
162    "pygments_lexer": "ipython2",
163    "version": "2.7.10"
164   }
165  },
166  "nbformat": 4,
167  "nbformat_minor": 0
168 }