(output_dir='output', use_07=True)
| 161 | |
| 162 | |
| 163 | def do_python_eval(output_dir='output', use_07=True): |
| 164 | cachedir = os.path.join(devkit_path, 'annotations_cache') |
| 165 | aps = [] |
| 166 | # The PASCAL VOC metric changed in 2010 |
| 167 | use_07_metric = use_07 |
| 168 | print('VOC07 metric? ' + ('Yes' if use_07_metric else 'No')) |
| 169 | if not os.path.isdir(output_dir): |
| 170 | os.mkdir(output_dir) |
| 171 | for i, cls in enumerate(labelmap): |
| 172 | filename = get_voc_results_file_template(set_type, cls) |
| 173 | rec, prec, ap = voc_eval( |
| 174 | filename, annopath, imgsetpath.format(set_type), cls, cachedir, |
| 175 | ovthresh=0.5, use_07_metric=use_07_metric) |
| 176 | aps += [ap] |
| 177 | print('AP for {} = {:.4f}'.format(cls, ap)) |
| 178 | with open(os.path.join(output_dir, cls + '_pr.pkl'), 'wb') as f: |
| 179 | pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f) |
| 180 | print('Mean AP = {:.4f}'.format(np.mean(aps))) |
| 181 | print('~~~~~~~~') |
| 182 | print('Results:') |
| 183 | for ap in aps: |
| 184 | print('{:.3f}'.format(ap)) |
| 185 | print('{:.3f}'.format(np.mean(aps))) |
| 186 | print('~~~~~~~~') |
| 187 | print('') |
| 188 | print('--------------------------------------------------------------') |
| 189 | print('Results computed with the **unofficial** Python eval code.') |
| 190 | print('Results should be very close to the official MATLAB eval code.') |
| 191 | print('--------------------------------------------------------------') |
| 192 | |
| 193 | |
| 194 | def voc_ap(rec, prec, use_07_metric=True): |
no test coverage detected