| 82 | self.createIndex() |
| 83 | |
| 84 | def createIndex(self): |
| 85 | # create index |
| 86 | print 'creating index...' |
| 87 | anns = {} |
| 88 | imgToAnns = {} |
| 89 | catToImgs = {} |
| 90 | cats = {} |
| 91 | imgs = {} |
| 92 | if 'annotations' in self.dataset: |
| 93 | imgToAnns = {ann['image_id']: [] for ann in self.dataset['annotations']} |
| 94 | anns = {ann['id']: [] for ann in self.dataset['annotations']} |
| 95 | for ann in self.dataset['annotations']: |
| 96 | imgToAnns[ann['image_id']] += [ann] |
| 97 | anns[ann['id']] = ann |
| 98 | |
| 99 | if 'images' in self.dataset: |
| 100 | imgs = {im['id']: {} for im in self.dataset['images']} |
| 101 | for img in self.dataset['images']: |
| 102 | imgs[img['id']] = img |
| 103 | |
| 104 | if 'categories' in self.dataset: |
| 105 | cats = {cat['id']: [] for cat in self.dataset['categories']} |
| 106 | for cat in self.dataset['categories']: |
| 107 | cats[cat['id']] = cat |
| 108 | catToImgs = {cat['id']: [] for cat in self.dataset['categories']} |
| 109 | if 'annotations' in self.dataset: |
| 110 | for ann in self.dataset['annotations']: |
| 111 | catToImgs[ann['category_id']] += [ann['image_id']] |
| 112 | |
| 113 | print 'index created!' |
| 114 | |
| 115 | # create class members |
| 116 | self.anns = anns |
| 117 | self.imgToAnns = imgToAnns |
| 118 | self.catToImgs = catToImgs |
| 119 | self.imgs = imgs |
| 120 | self.cats = cats |
| 121 | |
| 122 | def info(self): |
| 123 | """ |