ade20k.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os.path as osp
  3. from typing import List
  4. from mmengine import fileio
  5. from mmdet.registry import DATASETS
  6. from .base_semseg_dataset import BaseSegDataset
  7. from .coco import CocoDataset
  8. from .coco_panoptic import CocoPanopticDataset
  9. ADE_PALETTE = [(120, 120, 120), (180, 120, 120), (6, 230, 230), (80, 50, 50),
  10. (4, 200, 3), (120, 120, 80), (140, 140, 140), (204, 5, 255),
  11. (230, 230, 230), (4, 250, 7), (224, 5, 255), (235, 255, 7),
  12. (150, 5, 61), (120, 120, 70), (8, 255, 51), (255, 6, 82),
  13. (143, 255, 140), (204, 255, 4), (255, 51, 7), (204, 70, 3),
  14. (0, 102, 200), (61, 230, 250), (255, 6, 51), (11, 102, 255),
  15. (255, 7, 71), (255, 9, 224), (9, 7, 230), (220, 220, 220),
  16. (255, 9, 92), (112, 9, 255), (8, 255, 214), (7, 255, 224),
  17. (255, 184, 6), (10, 255, 71), (255, 41, 10), (7, 255, 255),
  18. (224, 255, 8), (102, 8, 255), (255, 61, 6), (255, 194, 7),
  19. (255, 122, 8), (0, 255, 20), (255, 8, 41), (255, 5, 153),
  20. (6, 51, 255), (235, 12, 255), (160, 150, 20), (0, 163, 255),
  21. (140, 140, 140), (250, 10, 15), (20, 255, 0), (31, 255, 0),
  22. (255, 31, 0), (255, 224, 0), (153, 255, 0), (0, 0, 255),
  23. (255, 71, 0), (0, 235, 255), (0, 173, 255), (31, 0, 255),
  24. (11, 200, 200), (255, 82, 0), (0, 255, 245), (0, 61, 255),
  25. (0, 255, 112), (0, 255, 133), (255, 0, 0), (255, 163, 0),
  26. (255, 102, 0), (194, 255, 0), (0, 143, 255), (51, 255, 0),
  27. (0, 82, 255), (0, 255, 41), (0, 255, 173), (10, 0, 255),
  28. (173, 255, 0), (0, 255, 153), (255, 92, 0), (255, 0, 255),
  29. (255, 0, 245), (255, 0, 102), (255, 173, 0), (255, 0, 20),
  30. (255, 184, 184), (0, 31, 255), (0, 255, 61), (0, 71, 255),
  31. (255, 0, 204), (0, 255, 194), (0, 255, 82), (0, 10, 255),
  32. (0, 112, 255), (51, 0, 255), (0, 194, 255), (0, 122, 255),
  33. (0, 255, 163), (255, 153, 0), (0, 255, 10), (255, 112, 0),
  34. (143, 255, 0), (82, 0, 255), (163, 255, 0), (255, 235, 0),
  35. (8, 184, 170), (133, 0, 255), (0, 255, 92), (184, 0, 255),
  36. (255, 0, 31), (0, 184, 255), (0, 214, 255), (255, 0, 112),
  37. (92, 255, 0), (0, 224, 255), (112, 224, 255), (70, 184, 160),
  38. (163, 0, 255), (153, 0, 255), (71, 255, 0), (255, 0, 163),
  39. (255, 204, 0), (255, 0, 143), (0, 255, 235), (133, 255, 0),
  40. (255, 0, 235), (245, 0, 255), (255, 0, 122), (255, 245, 0),
  41. (10, 190, 212), (214, 255, 0), (0, 204, 255), (20, 0, 255),
  42. (255, 255, 0), (0, 153, 255), (0, 41, 255), (0, 255, 204),
  43. (41, 0, 255), (41, 255, 0), (173, 0, 255), (0, 245, 255),
  44. (71, 0, 255), (122, 0, 255), (0, 255, 184), (0, 92, 255),
  45. (184, 255, 0), (0, 133, 255), (255, 214, 0), (25, 194, 194),
  46. (102, 255, 0), (92, 0, 255)]
  47. @DATASETS.register_module()
  48. class ADE20KPanopticDataset(CocoPanopticDataset):
  49. METAINFO = {
  50. 'classes':
  51. ('bed', 'window', 'cabinet', 'person', 'door', 'table', 'curtain',
  52. 'chair', 'car', 'painting, picture', 'sofa', 'shelf', 'mirror',
  53. 'armchair', 'seat', 'fence', 'desk', 'wardrobe, closet, press',
  54. 'lamp', 'tub', 'rail', 'cushion', 'box', 'column, pillar',
  55. 'signboard, sign', 'chest of drawers, chest, bureau, dresser',
  56. 'counter', 'sink', 'fireplace', 'refrigerator, icebox', 'stairs',
  57. 'case, display case, showcase, vitrine',
  58. 'pool table, billiard table, snooker table', 'pillow',
  59. 'screen door, screen', 'bookcase', 'coffee table',
  60. 'toilet, can, commode, crapper, pot, potty, stool, throne', 'flower',
  61. 'book', 'bench', 'countertop', 'stove', 'palm, palm tree',
  62. 'kitchen island', 'computer', 'swivel chair', 'boat',
  63. 'arcade machine', 'bus', 'towel', 'light', 'truck', 'chandelier',
  64. 'awning, sunshade, sunblind', 'street lamp', 'booth', 'tv',
  65. 'airplane', 'clothes', 'pole',
  66. 'bannister, banister, balustrade, balusters, handrail',
  67. 'ottoman, pouf, pouffe, puff, hassock', 'bottle', 'van', 'ship',
  68. 'fountain', 'washer, automatic washer, washing machine',
  69. 'plaything, toy', 'stool', 'barrel, cask', 'basket, handbasket',
  70. 'bag', 'minibike, motorbike', 'oven', 'ball', 'food, solid food',
  71. 'step, stair', 'trade name', 'microwave', 'pot', 'animal', 'bicycle',
  72. 'dishwasher', 'screen', 'sculpture', 'hood, exhaust hood', 'sconce',
  73. 'vase', 'traffic light', 'tray', 'trash can', 'fan', 'plate',
  74. 'monitor', 'bulletin board', 'radiator', 'glass, drinking glass',
  75. 'clock', 'flag', 'wall', 'building', 'sky', 'floor', 'tree',
  76. 'ceiling', 'road, route', 'grass', 'sidewalk, pavement',
  77. 'earth, ground', 'mountain, mount', 'plant', 'water', 'house', 'sea',
  78. 'rug', 'field', 'rock, stone', 'base, pedestal, stand', 'sand',
  79. 'skyscraper', 'grandstand, covered stand', 'path', 'runway',
  80. 'stairway, staircase', 'river', 'bridge, span', 'blind, screen',
  81. 'hill', 'bar', 'hovel, hut, hutch, shack, shanty', 'tower',
  82. 'dirt track', 'land, ground, soil',
  83. 'escalator, moving staircase, moving stairway',
  84. 'buffet, counter, sideboard',
  85. 'poster, posting, placard, notice, bill, card', 'stage',
  86. 'conveyer belt, conveyor belt, conveyer, conveyor, transporter',
  87. 'canopy', 'pool', 'falls', 'tent', 'cradle', 'tank, storage tank',
  88. 'lake', 'blanket, cover', 'pier', 'crt screen', 'shower'),
  89. 'thing_classes':
  90. ('bed', 'window', 'cabinet', 'person', 'door', 'table', 'curtain',
  91. 'chair', 'car', 'painting, picture', 'sofa', 'shelf', 'mirror',
  92. 'armchair', 'seat', 'fence', 'desk', 'wardrobe, closet, press',
  93. 'lamp', 'tub', 'rail', 'cushion', 'box', 'column, pillar',
  94. 'signboard, sign', 'chest of drawers, chest, bureau, dresser',
  95. 'counter', 'sink', 'fireplace', 'refrigerator, icebox', 'stairs',
  96. 'case, display case, showcase, vitrine',
  97. 'pool table, billiard table, snooker table', 'pillow',
  98. 'screen door, screen', 'bookcase', 'coffee table',
  99. 'toilet, can, commode, crapper, pot, potty, stool, throne', 'flower',
  100. 'book', 'bench', 'countertop', 'stove', 'palm, palm tree',
  101. 'kitchen island', 'computer', 'swivel chair', 'boat',
  102. 'arcade machine', 'bus', 'towel', 'light', 'truck', 'chandelier',
  103. 'awning, sunshade, sunblind', 'street lamp', 'booth', 'tv',
  104. 'airplane', 'clothes', 'pole',
  105. 'bannister, banister, balustrade, balusters, handrail',
  106. 'ottoman, pouf, pouffe, puff, hassock', 'bottle', 'van', 'ship',
  107. 'fountain', 'washer, automatic washer, washing machine',
  108. 'plaything, toy', 'stool', 'barrel, cask', 'basket, handbasket',
  109. 'bag', 'minibike, motorbike', 'oven', 'ball', 'food, solid food',
  110. 'step, stair', 'trade name', 'microwave', 'pot', 'animal', 'bicycle',
  111. 'dishwasher', 'screen', 'sculpture', 'hood, exhaust hood', 'sconce',
  112. 'vase', 'traffic light', 'tray', 'trash can', 'fan', 'plate',
  113. 'monitor', 'bulletin board', 'radiator', 'glass, drinking glass',
  114. 'clock', 'flag'),
  115. 'stuff_classes':
  116. ('wall', 'building', 'sky', 'floor', 'tree', 'ceiling', 'road, route',
  117. 'grass', 'sidewalk, pavement', 'earth, ground', 'mountain, mount',
  118. 'plant', 'water', 'house', 'sea', 'rug', 'field', 'rock, stone',
  119. 'base, pedestal, stand', 'sand', 'skyscraper',
  120. 'grandstand, covered stand', 'path', 'runway', 'stairway, staircase',
  121. 'river', 'bridge, span', 'blind, screen', 'hill', 'bar',
  122. 'hovel, hut, hutch, shack, shanty', 'tower', 'dirt track',
  123. 'land, ground, soil', 'escalator, moving staircase, moving stairway',
  124. 'buffet, counter, sideboard',
  125. 'poster, posting, placard, notice, bill, card', 'stage',
  126. 'conveyer belt, conveyor belt, conveyer, conveyor, transporter',
  127. 'canopy', 'pool', 'falls', 'tent', 'cradle', 'tank, storage tank',
  128. 'lake', 'blanket, cover', 'pier', 'crt screen', 'shower'),
  129. 'palette':
  130. ADE_PALETTE
  131. }
  132. @DATASETS.register_module()
  133. class ADE20KInstanceDataset(CocoDataset):
  134. METAINFO = {
  135. 'classes':
  136. ('bed', 'windowpane', 'cabinet', 'person', 'door', 'table', 'curtain',
  137. 'chair', 'car', 'painting', 'sofa', 'shelf', 'mirror', 'armchair',
  138. 'seat', 'fence', 'desk', 'wardrobe', 'lamp', 'bathtub', 'railing',
  139. 'cushion', 'box', 'column', 'signboard', 'chest of drawers',
  140. 'counter', 'sink', 'fireplace', 'refrigerator', 'stairs', 'case',
  141. 'pool table', 'pillow', 'screen door', 'bookcase', 'coffee table',
  142. 'toilet', 'flower', 'book', 'bench', 'countertop', 'stove', 'palm',
  143. 'kitchen island', 'computer', 'swivel chair', 'boat',
  144. 'arcade machine', 'bus', 'towel', 'light', 'truck', 'chandelier',
  145. 'awning', 'streetlight', 'booth', 'television receiver', 'airplane',
  146. 'apparel', 'pole', 'bannister', 'ottoman', 'bottle', 'van', 'ship',
  147. 'fountain', 'washer', 'plaything', 'stool', 'barrel', 'basket', 'bag',
  148. 'minibike', 'oven', 'ball', 'food', 'step', 'trade name', 'microwave',
  149. 'pot', 'animal', 'bicycle', 'dishwasher', 'screen', 'sculpture',
  150. 'hood', 'sconce', 'vase', 'traffic light', 'tray', 'ashcan', 'fan',
  151. 'plate', 'monitor', 'bulletin board', 'radiator', 'glass', 'clock',
  152. 'flag'),
  153. 'palette': [(204, 5, 255), (230, 230, 230), (224, 5, 255),
  154. (150, 5, 61), (8, 255, 51), (255, 6, 82), (255, 51, 7),
  155. (204, 70, 3), (0, 102, 200), (255, 6, 51), (11, 102, 255),
  156. (255, 7, 71), (220, 220, 220), (8, 255, 214),
  157. (7, 255, 224), (255, 184, 6), (10, 255, 71), (7, 255, 255),
  158. (224, 255, 8), (102, 8, 255), (255, 61, 6), (255, 194, 7),
  159. (0, 255, 20), (255, 8, 41), (255, 5, 153), (6, 51, 255),
  160. (235, 12, 255), (0, 163, 255), (250, 10, 15), (20, 255, 0),
  161. (255, 224, 0), (0, 0, 255), (255, 71, 0), (0, 235, 255),
  162. (0, 173, 255), (0, 255, 245), (0, 255, 112), (0, 255, 133),
  163. (255, 0, 0), (255, 163, 0), (194, 255, 0), (0, 143, 255),
  164. (51, 255, 0), (0, 82, 255), (0, 255, 41), (0, 255, 173),
  165. (10, 0, 255), (173, 255, 0), (255, 92, 0), (255, 0, 245),
  166. (255, 0, 102), (255, 173, 0), (255, 0, 20), (0, 31, 255),
  167. (0, 255, 61), (0, 71, 255), (255, 0, 204), (0, 255, 194),
  168. (0, 255, 82), (0, 112, 255), (51, 0, 255), (0, 122, 255),
  169. (255, 153, 0), (0, 255, 10), (163, 255, 0), (255, 235, 0),
  170. (8, 184, 170), (184, 0, 255), (255, 0, 31), (0, 214, 255),
  171. (255, 0, 112), (92, 255, 0), (70, 184, 160), (163, 0, 255),
  172. (71, 255, 0), (255, 0, 163), (255, 204, 0), (255, 0, 143),
  173. (133, 255, 0), (255, 0, 235), (245, 0, 255), (255, 0, 122),
  174. (255, 245, 0), (214, 255, 0), (0, 204, 255), (255, 255, 0),
  175. (0, 153, 255), (0, 41, 255), (0, 255, 204), (41, 0, 255),
  176. (41, 255, 0), (173, 0, 255), (0, 245, 255), (0, 255, 184),
  177. (0, 92, 255), (184, 255, 0), (255, 214, 0), (25, 194, 194),
  178. (102, 255, 0), (92, 0, 255)],
  179. }
  180. @DATASETS.register_module()
  181. class ADE20KSegDataset(BaseSegDataset):
  182. """ADE20K dataset.
  183. In segmentation map annotation for ADE20K, 0 stands for background, which
  184. is not included in 150 categories. The ``img_suffix`` is fixed to '.jpg',
  185. and ``seg_map_suffix`` is fixed to '.png'.
  186. """
  187. METAINFO = dict(
  188. classes=('wall', 'building', 'sky', 'floor', 'tree', 'ceiling', 'road',
  189. 'bed ', 'windowpane', 'grass', 'cabinet', 'sidewalk',
  190. 'person', 'earth', 'door', 'table', 'mountain', 'plant',
  191. 'curtain', 'chair', 'car', 'water', 'painting', 'sofa',
  192. 'shelf', 'house', 'sea', 'mirror', 'rug', 'field', 'armchair',
  193. 'seat', 'fence', 'desk', 'rock', 'wardrobe', 'lamp',
  194. 'bathtub', 'railing', 'cushion', 'base', 'box', 'column',
  195. 'signboard', 'chest of drawers', 'counter', 'sand', 'sink',
  196. 'skyscraper', 'fireplace', 'refrigerator', 'grandstand',
  197. 'path', 'stairs', 'runway', 'case', 'pool table', 'pillow',
  198. 'screen door', 'stairway', 'river', 'bridge', 'bookcase',
  199. 'blind', 'coffee table', 'toilet', 'flower', 'book', 'hill',
  200. 'bench', 'countertop', 'stove', 'palm', 'kitchen island',
  201. 'computer', 'swivel chair', 'boat', 'bar', 'arcade machine',
  202. 'hovel', 'bus', 'towel', 'light', 'truck', 'tower',
  203. 'chandelier', 'awning', 'streetlight', 'booth',
  204. 'television receiver', 'airplane', 'dirt track', 'apparel',
  205. 'pole', 'land', 'bannister', 'escalator', 'ottoman', 'bottle',
  206. 'buffet', 'poster', 'stage', 'van', 'ship', 'fountain',
  207. 'conveyer belt', 'canopy', 'washer', 'plaything',
  208. 'swimming pool', 'stool', 'barrel', 'basket', 'waterfall',
  209. 'tent', 'bag', 'minibike', 'cradle', 'oven', 'ball', 'food',
  210. 'step', 'tank', 'trade name', 'microwave', 'pot', 'animal',
  211. 'bicycle', 'lake', 'dishwasher', 'screen', 'blanket',
  212. 'sculpture', 'hood', 'sconce', 'vase', 'traffic light',
  213. 'tray', 'ashcan', 'fan', 'pier', 'crt screen', 'plate',
  214. 'monitor', 'bulletin board', 'shower', 'radiator', 'glass',
  215. 'clock', 'flag'),
  216. palette=ADE_PALETTE)
  217. def __init__(self,
  218. img_suffix='.jpg',
  219. seg_map_suffix='.png',
  220. return_classes=False,
  221. **kwargs) -> None:
  222. self.return_classes = return_classes
  223. super().__init__(
  224. img_suffix=img_suffix, seg_map_suffix=seg_map_suffix, **kwargs)
  225. def load_data_list(self) -> List[dict]:
  226. """Load annotation from directory or annotation file.
  227. Returns:
  228. List[dict]: All data info of dataset.
  229. """
  230. data_list = []
  231. img_dir = self.data_prefix.get('img_path', None)
  232. ann_dir = self.data_prefix.get('seg_map_path', None)
  233. for img in fileio.list_dir_or_file(
  234. dir_path=img_dir,
  235. list_dir=False,
  236. suffix=self.img_suffix,
  237. recursive=True,
  238. backend_args=self.backend_args):
  239. data_info = dict(img_path=osp.join(img_dir, img))
  240. if ann_dir is not None:
  241. seg_map = img.replace(self.img_suffix, self.seg_map_suffix)
  242. data_info['seg_map_path'] = osp.join(ann_dir, seg_map)
  243. data_info['label_map'] = self.label_map
  244. if self.return_classes:
  245. data_info['text'] = list(self._metainfo['classes'])
  246. data_list.append(data_info)
  247. return data_list