diff --git a/chainercv/datasets/__init__.py b/chainercv/datasets/__init__.py index a810d4b2db..54736c3d6f 100644 --- a/chainercv/datasets/__init__.py +++ b/chainercv/datasets/__init__.py @@ -19,6 +19,12 @@ from chainercv.datasets.cub.cub_utils import cub_label_names # NOQA from chainercv.datasets.directory_parsing_label_dataset import directory_parsing_label_names # NOQA from chainercv.datasets.directory_parsing_label_dataset import DirectoryParsingLabelDataset # NOQA +from chainercv.datasets.imagenet.imagenet_det_bbox_dataset import ImagenetDetBboxDataset # NOQA +from chainercv.datasets.imagenet.imagenet_loc_bbox_dataset import ImagenetLocBboxDataset # NOQA +from chainercv.datasets.imagenet.imagenet_utils import imagenet_det_bbox_label_names # NOQA +from chainercv.datasets.imagenet.imagenet_utils import imagenet_det_synset_ids # NOQA +from chainercv.datasets.imagenet.imagenet_utils import imagenet_loc_bbox_label_names # NOQA +from chainercv.datasets.imagenet.imagenet_utils import imagenet_loc_synset_ids # NOQA from chainercv.datasets.mixup_soft_label_dataset import MixUpSoftLabelDataset # NOQA from chainercv.datasets.online_products.online_products_dataset import online_products_super_label_names # NOQA from chainercv.datasets.online_products.online_products_dataset import OnlineProductsDataset # NOQA diff --git a/chainercv/datasets/imagenet/__init__.py b/chainercv/datasets/imagenet/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/chainercv/datasets/imagenet/imagenet_det_bbox_dataset.py b/chainercv/datasets/imagenet/imagenet_det_bbox_dataset.py new file mode 100644 index 0000000000..21ef3ee7e3 --- /dev/null +++ b/chainercv/datasets/imagenet/imagenet_det_bbox_dataset.py @@ -0,0 +1,172 @@ +import numpy as np +import os + +from chainer.dataset import download + +from chainercv.chainer_experimental.datasets.sliceable import GetterDataset +from chainercv.datasets.imagenet.imagenet_utils import get_ilsvrc_devkit +from chainercv.datasets.imagenet.imagenet_utils import imagenet_det_synset_ids +from chainercv.datasets.voc.voc_utils import parse_voc_bbox_annotation +from chainercv.utils import read_image + + +class ImagenetDetBboxDataset(GetterDataset): + + """ILSVRC ImageNet detection dataset. + + The data is distributed on the `official Kaggle page`_. + + .. _`official Kaggle page`: https://www.kaggle.com/c/ + imagenet-object-detection-challenge + + Please refer to the readme of ILSVRC2014 dev kit for a comprehensive + documentation. Note that the detection part of ILSVRC has not changed since + 2014. An overview of annotation process is described in the `paper`_. + + .. _`paper`: http://ai.stanford.edu/~olga/papers/chi2014-MultiLabel.pdf + + Every image in the training set has one or more image-level labels. + The image-level labels determine the full presence, partial presence or + absence of one or more object categories. + Bounding boxes are provided around instances of the present categories. + + Args: + data_dir (string): Path to the root of the training data. If this is + :obj:`auto`, + :obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/imagenet` is used. + split ({'train', 'val', 'val1', 'val2'}): Selects a split of the + dataset. + year ({'2013', '2014'}): Use a dataset prepared for a challenge + held in :obj:`year`. The default value is :obj:`2014`. + return_img_label (bool): If :obj:`True`, this dataset returns + image-wise labels. This consists of two arrays: + :obj:`img_label` and :obj:`img_label_type`. + use_val_blacklist (bool): If :obj:`False`, images that are + included in the blacklist are avoided when + the split is :obj:`val`. The default value is :obj:`False`. + + This dataset returns the following data. + + .. csv-table:: + :header: name, shape, dtype, format + + :obj:`img`, ":math:`(3, H, W)`", :obj:`float32`, \ + "RGB, :math:`[0, 255]`" + :obj:`bbox`, ":math:`(R, 4)`", :obj:`float32`, \ + ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`" + :obj:`label`, ":math:`(R,)`", :obj:`int32`, \ + ":math:`[0, \#fg\_class - 1]`" + :obj:`img_label` [#imagenet_det_1]_, ":math:`(M,)`", :obj:`int32`, \ + ":math:`[0, \#fg\_class - 1]`" + :obj:`img_label_type` [#imagenet_det_1]_ [#imagenet_det_2]_, \ + ":math:`(M,)`", :obj:`int32`, ":math:`[-1, 1]`" + + .. [#imagenet_det_1] available + if :obj:`return_img_label = True`. + .. [#imagenet_det_2] :obj:`-1` means absent. :obj:`1` means present. + :obj:`0` means partially present. When a category is partially + present, the image contains at least one + instance of X, but not all instances of X may be annotated with + bounding boxes. + + """ + + def __init__(self, data_dir='auto', split='train', year='2014', + return_img_label=False, use_val_blacklist=False): + super(ImagenetDetBboxDataset, self).__init__() + if data_dir == 'auto': + data_dir = download.get_dataset_directory( + 'pfnet/chainercv/imagenet') + get_ilsvrc_devkit() + val_blacklist_path = os.path.join( + data_dir, 'ILSVRC2014_devkit/data/', + 'ILSVRC2014_det_validation_blacklist.txt') + + if year not in ('2013', '2014'): + raise ValueError('\'year\' has to be either ' + '\'2013\' or \'2014\'.') + self.base_dir = os.path.join(data_dir, 'ILSVRC') + imageset_dir = os.path.join(self.base_dir, 'ImageSets/DET') + + if split == 'train': + img_labels = {} + for lb in range(0, 200): + with open(os.path.join( + imageset_dir, 'train_{}.txt'.format(lb + 1))) as f: + for l in f: + id_ = l.split()[0] + if 'ILSVRC2014' in id_ and year != '2014': + continue + + anno_type = l.split()[1] + if id_ not in img_labels: + img_labels[id_] = [] + img_labels[id_].append((lb, int(anno_type))) + self.img_labels = img_labels + self.ids = list(img_labels.keys()) + self.split_type = 'train' + else: + if return_img_label: + raise ValueError('split has to be \'train\' when ' + 'return_img_label is True') + if use_val_blacklist: + blacklist_ids = [] + else: + ids = [] + with open(os.path.join( + imageset_dir, 'val.txt'.format(split))) as f: + for l in f: + id_ = l.split()[0] + ids.append(id_) + blacklist_ids = [] + with open(val_blacklist_path) as f: + for l in f: + index = int(l.split()[0]) + blacklist_ids.append(ids[index]) + + ids = [] + with open(os.path.join( + imageset_dir, '{}.txt'.format(split))) as f: + for l in f: + id_ = l.split()[0] + if id_ not in blacklist_ids: + ids.append(id_) + self.ids = ids + self.split_type = 'val' + + self.add_getter('img', self._get_image) + self.add_getter(('bbox', 'label'), self._get_inst_anno) + if return_img_label: + self.add_getter( + ('img_label', 'img_label_type'), self._get_img_label) + + def __len__(self): + return len(self.ids) + + def _get_image(self, i): + img_path = os.path.join( + self.base_dir, 'Data/DET', self.split_type, + self.ids[i] + '.JPEG') + img = read_image(img_path, color=True) + return img + + def _get_inst_anno(self, i): + if 'extra' not in self.ids[i]: + anno_path = os.path.join( + self.base_dir, 'Annotations/DET', self.split_type, + self.ids[i] + '.xml') + bbox, label, _ = parse_voc_bbox_annotation( + anno_path, imagenet_det_synset_ids, + skip_names_not_in_label_names=True) + else: + bbox = np.zeros((0, 4), dtype=np.float32) + label = np.zeros((0,), dtype=np.int32) + return bbox, label + + def _get_img_label(self, i): + img_label = np.array([val[0] for val in self.img_labels[self.ids[i]]], + dtype=np.int32) + img_label_type = np.array( + [val[1] for val in self.img_labels[self.ids[i]]], + dtype=np.int32) + return img_label, img_label_type diff --git a/chainercv/datasets/imagenet/imagenet_loc_bbox_dataset.py b/chainercv/datasets/imagenet/imagenet_loc_bbox_dataset.py new file mode 100644 index 0000000000..93ddfffe18 --- /dev/null +++ b/chainercv/datasets/imagenet/imagenet_loc_bbox_dataset.py @@ -0,0 +1,105 @@ +import os + +from chainer.dataset import download + +from chainercv.chainer_experimental.datasets.sliceable import GetterDataset +from chainercv.datasets.imagenet.imagenet_utils import get_ilsvrc_devkit +from chainercv.datasets.imagenet.imagenet_utils import imagenet_loc_synset_ids +from chainercv.datasets.voc.voc_utils import parse_voc_bbox_annotation +from chainercv.utils import read_image + + +class ImagenetLocBboxDataset(GetterDataset): + + """ILSVRC2012 ImageNet localization dataset. + + The data is distributed on `the official Kaggle page`_. + + .. _`the official Kaggle page`: https://www.kaggle.com/c/ + imagenet-object-localization-challenge + + Please refer to the readme of ILSVRC2012 dev kit for a comprehensive + documentation. Note that the detection part of ILSVRC has not changed since + 2012. + + Every image in the training and validation sets has a single + image-level label specifying the presence of one object category. + + Args: + data_dir (string): Path to the root of the training data. If this is + :obj:`auto`, + :obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/imagenet` is used. + split ({'train', 'val'}): Selects a split of the dataset. + use_val_blacklist (bool): If :obj:`False`, images that are + included in the blacklist are avoided when + the split is :obj:`val`. The default value is :obj:`False`. + + This dataset returns the following data. + + .. csv-table:: + :header: name, shape, dtype, format + + :obj:`img`, ":math:`(3, H, W)`", :obj:`float32`, \ + "RGB, :math:`[0, 255]`" + :obj:`bbox`, ":math:`(R, 4)`", :obj:`float32`, \ + ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`" + :obj:`label`, ":math:`(R,)`", :obj:`int32`, \ + ":math:`[0, \#fg\_class - 1]`" + + """ + + def __init__(self, data_dir='auto', split='train', + use_val_blacklist=False): + super(ImagenetLocBboxDataset, self).__init__() + if data_dir == 'auto': + data_dir = download.get_dataset_directory( + 'pfnet/chainercv/imagenet') + get_ilsvrc_devkit() + val_blacklist_path = os.path.join( + data_dir, 'ILSVRC2014_devkit/data/', + 'ILSVRC2014_clsloc_validation_blacklist.txt') + self.base_dir = os.path.join(data_dir, 'ILSVRC') + imageset_dir = os.path.join(self.base_dir, 'ImageSets/CLS-LOC') + + ids = [] + if split == 'train': + imageset_path = os.path.join(imageset_dir, 'train_loc.txt') + elif split == 'val': + imageset_path = os.path.join(imageset_dir, 'val.txt') + + if not use_val_blacklist: + blacklist = [] + with open(val_blacklist_path) as f: + for l in f: + blacklist.append(int(l)) + else: + blacklist = [] + with open(imageset_path) as f: + for l in f: + if int(l.split()[1]) not in blacklist: + id_ = l.split()[0] + ids.append(id_) + self.ids = ids + self.split = split + + self.add_getter('img', self._get_image) + self.add_getter(('bbox', 'label'), self._get_inst_anno) + + def __len__(self): + return len(self.ids) + + def _get_image(self, i): + img_path = os.path.join( + self.base_dir, 'Data/CLS-LOC', self.split, + self.ids[i] + '.JPEG') + img = read_image(img_path, color=True) + return img + + def _get_inst_anno(self, i): + anno_path = os.path.join( + self.base_dir, 'Annotations/CLS-LOC', self.split, + self.ids[i] + '.xml') + bbox, label, _ = parse_voc_bbox_annotation( + anno_path, imagenet_loc_synset_ids, + skip_names_not_in_label_names=False) + return bbox, label diff --git a/chainercv/datasets/imagenet/imagenet_utils.py b/chainercv/datasets/imagenet/imagenet_utils.py new file mode 100644 index 0000000000..aa257b2026 --- /dev/null +++ b/chainercv/datasets/imagenet/imagenet_utils.py @@ -0,0 +1,2432 @@ +import os + +from chainer.dataset import download +from chainercv import utils + +root = 'pfnet/chainercv/imagenet' +devkit_url = 'http://image-net.org/image/ilsvrc2014/ILSVRC2014_devkit.tgz' + + +def get_ilsvrc_devkit(): + data_root = download.get_dataset_directory(root) + base_dir = os.path.join(data_root, 'ILSVRC2014_devkit') + if os.path.exists(base_dir): + return data_root + download_file_path = utils.cached_download(devkit_url) + ext = os.path.splitext(devkit_url)[1] + utils.extractall(download_file_path, data_root, ext) + return data_root + + +# Look up meta_det.mat from dev kit +imagenet_det_bbox_label_names = ( + 'accordion', + 'airplane', + 'ant', + 'antelope', + 'apple', + 'armadillo', + 'artichoke', + 'axe', + 'baby bed', + 'backpack', + 'bagel', + 'balance beam', + 'banana', + 'band aid', + 'banjo', + 'baseball', + 'basketball', + 'bathing cap', + 'beaker', + 'bear', + 'bee', + 'bell pepper', + 'bench', + 'bicycle', + 'binder', + 'bird', + 'bookshelf', + 'bow tie', + 'bow', + 'bowl', + 'brassiere', + 'burrito', + 'bus', + 'butterfly', + 'camel', + 'can opener', + 'car', + 'cart', + 'cattle', + 'cello', + 'centipede', + 'chain saw', + 'chair', + 'chime', + 'cocktail shaker', + 'coffee maker', + 'computer keyboard', + 'computer mouse', + 'corkscrew', + 'cream', + 'croquet ball', + 'crutch', + 'cucumber', + 'cup or mug', + 'diaper', + 'digital clock', + 'dishwasher', + 'dog', + 'domestic cat', + 'dragonfly', + 'drum', + 'dumbbell', + 'electric fan', + 'elephant', + 'face powder', + 'fig', + 'filing cabinet', + 'flower pot', + 'flute', + 'fox', + 'french horn', + 'frog', + 'frying pan', + 'giant panda', + 'goldfish', + 'golf ball', + 'golfcart', + 'guacamole', + 'guitar', + 'hair dryer', + 'hair spray', + 'hamburger', + 'hammer', + 'hamster', + 'harmonica', + 'harp', + 'hat with a wide brim', + 'head cabbage', + 'helmet', + 'hippopotamus', + 'horizontal bar', + 'horse', + 'hotdog', + 'iPod', + 'isopod', + 'jellyfish', + 'koala bear', + 'ladle', + 'ladybug', + 'lamp', + 'laptop', + 'lemon', + 'lion', + 'lipstick', + 'lizard', + 'lobster', + 'maillot', + 'maraca', + 'microphone', + 'microwave', + 'milk can', + 'miniskirt', + 'monkey', + 'motorcycle', + 'mushroom', + 'nail', + 'neck brace', + 'oboe', + 'orange', + 'otter', + 'pencil box', + 'pencil sharpener', + 'perfume', + 'person', + 'piano', + 'pineapple', + 'ping-pong ball', + 'pitcher', + 'pizza', + 'plastic bag', + 'plate rack', + 'pomegranate', + 'popsicle', + 'porcupine', + 'power drill', + 'pretzel', + 'printer', + 'puck', + 'punching bag', + 'purse', + 'rabbit', + 'racket', + 'ray', + 'red panda', + 'refrigerator', + 'remote control', + 'rubber eraser', + 'rugby ball', + 'ruler', + 'salt or pepper shaker', + 'saxophone', + 'scorpion', + 'screwdriver', + 'seal', + 'sheep', + 'ski', + 'skunk', + 'snail', + 'snake', + 'snowmobile', + 'snowplow', + 'soap dispenser', + 'soccer ball', + 'sofa', + 'spatula', + 'squirrel', + 'starfish', + 'stethoscope', + 'stove', + 'strainer', + 'strawberry', + 'stretcher', + 'sunglasses', + 'swimming trunks', + 'swine', + 'syringe', + 'table', + 'tape player', + 'tennis ball', + 'tick', + 'tie', + 'tiger', + 'toaster', + 'traffic light', + 'train', + 'trombone', + 'trumpet', + 'turtle', + 'tv or monitor', + 'unicycle', + 'vacuum', + 'violin', + 'volleyball', + 'waffle iron', + 'washer', + 'water bottle', + 'watercraft', + 'whale', + 'wine bottle', + 'zebra') + + +imagenet_det_synset_ids = ( + 'n02672831', + 'n02691156', + 'n02219486', + 'n02419796', + 'n07739125', + 'n02454379', + 'n07718747', + 'n02764044', + 'n02766320', + 'n02769748', + 'n07693725', + 'n02777292', + 'n07753592', + 'n02786058', + 'n02787622', + 'n02799071', + 'n02802426', + 'n02807133', + 'n02815834', + 'n02131653', + 'n02206856', + 'n07720875', + 'n02828884', + 'n02834778', + 'n02840245', + 'n01503061', + 'n02870880', + 'n02883205', + 'n02879718', + 'n02880940', + 'n02892767', + 'n07880968', + 'n02924116', + 'n02274259', + 'n02437136', + 'n02951585', + 'n02958343', + 'n02970849', + 'n02402425', + 'n02992211', + 'n01784675', + 'n03000684', + 'n03001627', + 'n03017168', + 'n03062245', + 'n03063338', + 'n03085013', + 'n03793489', + 'n03109150', + 'n03128519', + 'n03134739', + 'n03141823', + 'n07718472', + 'n03797390', + 'n03188531', + 'n03196217', + 'n03207941', + 'n02084071', + 'n02121808', + 'n02268443', + 'n03249569', + 'n03255030', + 'n03271574', + 'n02503517', + 'n03314780', + 'n07753113', + 'n03337140', + 'n03991062', + 'n03372029', + 'n02118333', + 'n03394916', + 'n01639765', + 'n03400231', + 'n02510455', + 'n01443537', + 'n03445777', + 'n03445924', + 'n07583066', + 'n03467517', + 'n03483316', + 'n03476991', + 'n07697100', + 'n03481172', + 'n02342885', + 'n03494278', + 'n03495258', + 'n03124170', + 'n07714571', + 'n03513137', + 'n02398521', + 'n03535780', + 'n02374451', + 'n07697537', + 'n03584254', + 'n01990800', + 'n01910747', + 'n01882714', + 'n03633091', + 'n02165456', + 'n03636649', + 'n03642806', + 'n07749582', + 'n02129165', + 'n03676483', + 'n01674464', + 'n01982650', + 'n03710721', + 'n03720891', + 'n03759954', + 'n03761084', + 'n03764736', + 'n03770439', + 'n02484322', + 'n03790512', + 'n07734744', + 'n03804744', + 'n03814639', + 'n03838899', + 'n07747607', + 'n02444819', + 'n03908618', + 'n03908714', + 'n03916031', + 'n00007846', + 'n03928116', + 'n07753275', + 'n03942813', + 'n03950228', + 'n07873807', + 'n03958227', + 'n03961711', + 'n07768694', + 'n07615774', + 'n02346627', + 'n03995372', + 'n07695742', + 'n04004767', + 'n04019541', + 'n04023962', + 'n04026417', + 'n02324045', + 'n04039381', + 'n01495701', + 'n02509815', + 'n04070727', + 'n04074963', + 'n04116512', + 'n04118538', + 'n04118776', + 'n04131690', + 'n04141076', + 'n01770393', + 'n04154565', + 'n02076196', + 'n02411705', + 'n04228054', + 'n02445715', + 'n01944390', + 'n01726692', + 'n04252077', + 'n04252225', + 'n04254120', + 'n04254680', + 'n04256520', + 'n04270147', + 'n02355227', + 'n02317335', + 'n04317175', + 'n04330267', + 'n04332243', + 'n07745940', + 'n04336792', + 'n04356056', + 'n04371430', + 'n02395003', + 'n04376876', + 'n04379243', + 'n04392985', + 'n04409515', + 'n01776313', + 'n04591157', + 'n02129604', + 'n04442312', + 'n06874185', + 'n04468005', + 'n04487394', + 'n03110669', + 'n01662784', + 'n03211117', + 'n04509417', + 'n04517823', + 'n04536866', + 'n04540053', + 'n04542943', + 'n04554684', + 'n04557648', + 'n04530566', + 'n02062744', + 'n04591713', + 'n02391049') + + +imagenet_loc_bbox_label_names = ( + 'tench', + 'goldfish', + 'great white shark', + 'tiger shark', + 'hammerhead', + 'electric ray', + 'stingray', + 'cock', + 'hen', + 'ostrich', + 'brambling', + 'goldfinch', + 'house finch', + 'junco', + 'indigo bunting', + 'robin', + 'bulbul', + 'jay', + 'magpie', + 'chickadee', + 'water ouzel', + 'kite', + 'bald eagle', + 'vulture', + 'great grey owl', + 'European fire salamander', + 'common newt', + 'eft', + 'spotted salamander', + 'axolotl', + 'bullfrog', + 'tree frog', + 'tailed frog', + 'loggerhead', + 'leatherback turtle', + 'mud turtle', + 'terrapin', + 'box turtle', + 'banded gecko', + 'common iguana', + 'American chameleon', + 'whiptail', + 'agama', + 'frilled lizard', + 'alligator lizard', + 'Gila monster', + 'green lizard', + 'African chameleon', + 'Komodo dragon', + 'African crocodile', + 'American alligator', + 'triceratops', + 'thunder snake', + 'ringneck snake', + 'hognose snake', + 'green snake', + 'king snake', + 'garter snake', + 'water snake', + 'vine snake', + 'night snake', + 'boa constrictor', + 'rock python', + 'Indian cobra', + 'green mamba', + 'sea snake', + 'horned viper', + 'diamondback', + 'sidewinder', + 'trilobite', + 'harvestman', + 'scorpion', + 'black and gold garden spider', + 'barn spider', + 'garden spider', + 'black widow', + 'tarantula', + 'wolf spider', + 'tick', + 'centipede', + 'black grouse', + 'ptarmigan', + 'ruffed grouse', + 'prairie chicken', + 'peacock', + 'quail', + 'partridge', + 'African grey', + 'macaw', + 'sulphur-crested cockatoo', + 'lorikeet', + 'coucal', + 'bee eater', + 'hornbill', + 'hummingbird', + 'jacamar', + 'toucan', + 'drake', + 'red-breasted merganser', + 'goose', + 'black swan', + 'tusker', + 'echidna', + 'platypus', + 'wallaby', + 'koala', + 'wombat', + 'jellyfish', + 'sea anemone', + 'brain coral', + 'flatworm', + 'nematode', + 'conch', + 'snail', + 'slug', + 'sea slug', + 'chiton', + 'chambered nautilus', + 'Dungeness crab', + 'rock crab', + 'fiddler crab', + 'king crab', + 'American lobster', + 'spiny lobster', + 'crayfish', + 'hermit crab', + 'isopod', + 'white stork', + 'black stork', + 'spoonbill', + 'flamingo', + 'little blue heron', + 'American egret', + 'bittern', + 'crane', + 'limpkin', + 'European gallinule', + 'American coot', + 'bustard', + 'ruddy turnstone', + 'red-backed sandpiper', + 'redshank', + 'dowitcher', + 'oystercatcher', + 'pelican', + 'king penguin', + 'albatross', + 'grey whale', + 'killer whale', + 'dugong', + 'sea lion', + 'Chihuahua', + 'Japanese spaniel', + 'Maltese dog', + 'Pekinese', + 'Shih-Tzu', + 'Blenheim spaniel', + 'papillon', + 'toy terrier', + 'Rhodesian ridgeback', + 'Afghan hound', + 'basset', + 'beagle', + 'bloodhound', + 'bluetick', + 'black-and-tan coonhound', + 'Walker hound', + 'English foxhound', + 'redbone', + 'borzoi', + 'Irish wolfhound', + 'Italian greyhound', + 'whippet', + 'Ibizan hound', + 'Norwegian elkhound', + 'otterhound', + 'Saluki', + 'Scottish deerhound', + 'Weimaraner', + 'Staffordshire bullterrier', + 'American Staffordshire terrier', + 'Bedlington terrier', + 'Border terrier', + 'Kerry blue terrier', + 'Irish terrier', + 'Norfolk terrier', + 'Norwich terrier', + 'Yorkshire terrier', + 'wire-haired fox terrier', + 'Lakeland terrier', + 'Sealyham terrier', + 'Airedale', + 'cairn', + 'Australian terrier', + 'Dandie Dinmont', + 'Boston bull', + 'miniature schnauzer', + 'giant schnauzer', + 'standard schnauzer', + 'Scotch terrier', + 'Tibetan terrier', + 'silky terrier', + 'soft-coated wheaten terrier', + 'West Highland white terrier', + 'Lhasa', + 'flat-coated retriever', + 'curly-coated retriever', + 'golden retriever', + 'Labrador retriever', + 'Chesapeake Bay retriever', + 'German short-haired pointer', + 'vizsla', + 'English setter', + 'Irish setter', + 'Gordon setter', + 'Brittany spaniel', + 'clumber', + 'English springer', + 'Welsh springer spaniel', + 'cocker spaniel', + 'Sussex spaniel', + 'Irish water spaniel', + 'kuvasz', + 'schipperke', + 'groenendael', + 'malinois', + 'briard', + 'kelpie', + 'komondor', + 'Old English sheepdog', + 'Shetland sheepdog', + 'collie', + 'Border collie', + 'Bouvier des Flandres', + 'Rottweiler', + 'German shepherd', + 'Doberman', + 'miniature pinscher', + 'Greater Swiss Mountain dog', + 'Bernese mountain dog', + 'Appenzeller', + 'EntleBucher', + 'boxer', + 'bull mastiff', + 'Tibetan mastiff', + 'French bulldog', + 'Great Dane', + 'Saint Bernard', + 'Eskimo dog', + 'malamute', + 'Siberian husky', + 'dalmatian', + 'affenpinscher', + 'basenji', + 'pug', + 'Leonberg', + 'Newfoundland', + 'Great Pyrenees', + 'Samoyed', + 'Pomeranian', + 'chow', + 'keeshond', + 'Brabancon griffon', + 'Pembroke', + 'Cardigan', + 'toy poodle', + 'miniature poodle', + 'standard poodle', + 'Mexican hairless', + 'timber wolf', + 'white wolf', + 'red wolf', + 'coyote', + 'dingo', + 'dhole', + 'African hunting dog', + 'hyena', + 'red fox', + 'kit fox', + 'Arctic fox', + 'grey fox', + 'tabby', + 'tiger cat', + 'Persian cat', + 'Siamese cat', + 'Egyptian cat', + 'cougar', + 'lynx', + 'leopard', + 'snow leopard', + 'jaguar', + 'lion', + 'tiger', + 'cheetah', + 'brown bear', + 'American black bear', + 'ice bear', + 'sloth bear', + 'mongoose', + 'meerkat', + 'tiger beetle', + 'ladybug', + 'ground beetle', + 'long-horned beetle', + 'leaf beetle', + 'dung beetle', + 'rhinoceros beetle', + 'weevil', + 'fly', + 'bee', + 'ant', + 'grasshopper', + 'cricket', + 'walking stick', + 'cockroach', + 'mantis', + 'cicada', + 'leafhopper', + 'lacewing', + 'dragonfly', + 'damselfly', + 'admiral', + 'ringlet', + 'monarch', + 'cabbage butterfly', + 'sulphur butterfly', + 'lycaenid', + 'starfish', + 'sea urchin', + 'sea cucumber', + 'wood rabbit', + 'hare', + 'Angora', + 'hamster', + 'porcupine', + 'fox squirrel', + 'marmot', + 'beaver', + 'guinea pig', + 'sorrel', + 'zebra', + 'hog', + 'wild boar', + 'warthog', + 'hippopotamus', + 'ox', + 'water buffalo', + 'bison', + 'ram', + 'bighorn', + 'ibex', + 'hartebeest', + 'impala', + 'gazelle', + 'Arabian camel', + 'llama', + 'weasel', + 'mink', + 'polecat', + 'black-footed ferret', + 'otter', + 'skunk', + 'badger', + 'armadillo', + 'three-toed sloth', + 'orangutan', + 'gorilla', + 'chimpanzee', + 'gibbon', + 'siamang', + 'guenon', + 'patas', + 'baboon', + 'macaque', + 'langur', + 'colobus', + 'proboscis monkey', + 'marmoset', + 'capuchin', + 'howler monkey', + 'titi', + 'spider monkey', + 'squirrel monkey', + 'Madagascar cat', + 'indri', + 'Indian elephant', + 'African elephant', + 'lesser panda', + 'giant panda', + 'barracouta', + 'eel', + 'coho', + 'rock beauty', + 'anemone fish', + 'sturgeon', + 'gar', + 'lionfish', + 'puffer', + 'abacus', + 'abaya', + 'academic gown', + 'accordion', + 'acoustic guitar', + 'aircraft carrier', + 'airliner', + 'airship', + 'altar', + 'ambulance', + 'amphibian', + 'analog clock', + 'apiary', + 'apron', + 'ashcan', + 'assault rifle', + 'backpack', + 'bakery', + 'balance beam', + 'balloon', + 'ballpoint', + 'Band Aid', + 'banjo', + 'bannister', + 'barbell', + 'barber chair', + 'barbershop', + 'barn', + 'barometer', + 'barrel', + 'barrow', + 'baseball', + 'basketball', + 'bassinet', + 'bassoon', + 'bathing cap', + 'bath towel', + 'bathtub', + 'beach wagon', + 'beacon', + 'beaker', + 'bearskin', + 'beer bottle', + 'beer glass', + 'bell cote', + 'bib', + 'bicycle-built-for-two', + 'bikini', + 'binder', + 'binoculars', + 'birdhouse', + 'boathouse', + 'bobsled', + 'bolo tie', + 'bonnet', + 'bookcase', + 'bookshop', + 'bottlecap', + 'bow', + 'bow tie', + 'brass', + 'brassiere', + 'breakwater', + 'breastplate', + 'broom', + 'bucket', + 'buckle', + 'bulletproof vest', + 'bullet train', + 'butcher shop', + 'cab', + 'caldron', + 'candle', + 'cannon', + 'canoe', + 'can opener', + 'cardigan', + 'car mirror', + 'carousel', + 'carpenters kit', + 'carton', + 'car wheel', + 'cash machine', + 'cassette', + 'cassette player', + 'castle', + 'catamaran', + 'CD player', + 'cello', + 'cellular telephone', + 'chain', + 'chainlink fence', + 'chain mail', + 'chain saw', + 'chest', + 'chiffonier', + 'chime', + 'china cabinet', + 'Christmas stocking', + 'church', + 'cinema', + 'cleaver', + 'cliff dwelling', + 'cloak', + 'clog', + 'cocktail shaker', + 'coffee mug', + 'coffeepot', + 'coil', + 'combination lock', + 'computer keyboard', + 'confectionery', + 'container ship', + 'convertible', + 'corkscrew', + 'cornet', + 'cowboy boot', + 'cowboy hat', + 'cradle', + 'crane', + 'crash helmet', + 'crate', + 'crib', + 'Crock Pot', + 'croquet ball', + 'crutch', + 'cuirass', + 'dam', + 'desk', + 'desktop computer', + 'dial telephone', + 'diaper', + 'digital clock', + 'digital watch', + 'dining table', + 'dishrag', + 'dishwasher', + 'disk brake', + 'dock', + 'dogsled', + 'dome', + 'doormat', + 'drilling platform', + 'drum', + 'drumstick', + 'dumbbell', + 'Dutch oven', + 'electric fan', + 'electric guitar', + 'electric locomotive', + 'entertainment center', + 'envelope', + 'espresso maker', + 'face powder', + 'feather boa', + 'file', + 'fireboat', + 'fire engine', + 'fire screen', + 'flagpole', + 'flute', + 'folding chair', + 'football helmet', + 'forklift', + 'fountain', + 'fountain pen', + 'four-poster', + 'freight car', + 'French horn', + 'frying pan', + 'fur coat', + 'garbage truck', + 'gasmask', + 'gas pump', + 'goblet', + 'go-kart', + 'golf ball', + 'golfcart', + 'gondola', + 'gong', + 'gown', + 'grand piano', + 'greenhouse', + 'grille', + 'grocery store', + 'guillotine', + 'hair slide', + 'hair spray', + 'half track', + 'hammer', + 'hamper', + 'hand blower', + 'hand-held computer', + 'handkerchief', + 'hard disc', + 'harmonica', + 'harp', + 'harvester', + 'hatchet', + 'holster', + 'home theater', + 'honeycomb', + 'hook', + 'hoopskirt', + 'horizontal bar', + 'horse cart', + 'hourglass', + 'iPod', + 'iron', + 'jack-o-lantern', + 'jean', + 'jeep', + 'jersey', + 'jigsaw puzzle', + 'jinrikisha', + 'joystick', + 'kimono', + 'knee pad', + 'knot', + 'lab coat', + 'ladle', + 'lampshade', + 'laptop', + 'lawn mower', + 'lens cap', + 'letter opener', + 'library', + 'lifeboat', + 'lighter', + 'limousine', + 'liner', + 'lipstick', + 'Loafer', + 'lotion', + 'loudspeaker', + 'loupe', + 'lumbermill', + 'magnetic compass', + 'mailbag', + 'mailbox', + 'maillot', + 'maillot', + 'manhole cover', + 'maraca', + 'marimba', + 'mask', + 'matchstick', + 'maypole', + 'maze', + 'measuring cup', + 'medicine chest', + 'megalith', + 'microphone', + 'microwave', + 'military uniform', + 'milk can', + 'minibus', + 'miniskirt', + 'minivan', + 'missile', + 'mitten', + 'mixing bowl', + 'mobile home', + 'Model T', + 'modem', + 'monastery', + 'monitor', + 'moped', + 'mortar', + 'mortarboard', + 'mosque', + 'mosquito net', + 'motor scooter', + 'mountain bike', + 'mountain tent', + 'mouse', + 'mousetrap', + 'moving van', + 'muzzle', + 'nail', + 'neck brace', + 'necklace', + 'nipple', + 'notebook', + 'obelisk', + 'oboe', + 'ocarina', + 'odometer', + 'oil filter', + 'organ', + 'oscilloscope', + 'overskirt', + 'oxcart', + 'oxygen mask', + 'packet', + 'paddle', + 'paddlewheel', + 'padlock', + 'paintbrush', + 'pajama', + 'palace', + 'panpipe', + 'paper towel', + 'parachute', + 'parallel bars', + 'park bench', + 'parking meter', + 'passenger car', + 'patio', + 'pay-phone', + 'pedestal', + 'pencil box', + 'pencil sharpener', + 'perfume', + 'Petri dish', + 'photocopier', + 'pick', + 'pickelhaube', + 'picket fence', + 'pickup', + 'pier', + 'piggy bank', + 'pill bottle', + 'pillow', + 'ping-pong ball', + 'pinwheel', + 'pirate', + 'pitcher', + 'plane', + 'planetarium', + 'plastic bag', + 'plate rack', + 'plow', + 'plunger', + 'Polaroid camera', + 'pole', + 'police van', + 'poncho', + 'pool table', + 'pop bottle', + 'pot', + 'potters wheel', + 'power drill', + 'prayer rug', + 'printer', + 'prison', + 'projectile', + 'projector', + 'puck', + 'punching bag', + 'purse', + 'quill', + 'quilt', + 'racer', + 'racket', + 'radiator', + 'radio', + 'radio telescope', + 'rain barrel', + 'recreational vehicle', + 'reel', + 'reflex camera', + 'refrigerator', + 'remote control', + 'restaurant', + 'revolver', + 'rifle', + 'rocking chair', + 'rotisserie', + 'rubber eraser', + 'rugby ball', + 'rule', + 'running shoe', + 'safe', + 'safety pin', + 'saltshaker', + 'sandal', + 'sarong', + 'sax', + 'scabbard', + 'scale', + 'school bus', + 'schooner', + 'scoreboard', + 'screen', + 'screw', + 'screwdriver', + 'seat belt', + 'sewing machine', + 'shield', + 'shoe shop', + 'shoji', + 'shopping basket', + 'shopping cart', + 'shovel', + 'shower cap', + 'shower curtain', + 'ski', + 'ski mask', + 'sleeping bag', + 'slide rule', + 'sliding door', + 'slot', + 'snorkel', + 'snowmobile', + 'snowplow', + 'soap dispenser', + 'soccer ball', + 'sock', + 'solar dish', + 'sombrero', + 'soup bowl', + 'space bar', + 'space heater', + 'space shuttle', + 'spatula', + 'speedboat', + 'spider web', + 'spindle', + 'sports car', + 'spotlight', + 'stage', + 'steam locomotive', + 'steel arch bridge', + 'steel drum', + 'stethoscope', + 'stole', + 'stone wall', + 'stopwatch', + 'stove', + 'strainer', + 'streetcar', + 'stretcher', + 'studio couch', + 'stupa', + 'submarine', + 'suit', + 'sundial', + 'sunglass', + 'sunglasses', + 'sunscreen', + 'suspension bridge', + 'swab', + 'sweatshirt', + 'swimming trunks', + 'swing', + 'switch', + 'syringe', + 'table lamp', + 'tank', + 'tape player', + 'teapot', + 'teddy', + 'television', + 'tennis ball', + 'thatch', + 'theater curtain', + 'thimble', + 'thresher', + 'throne', + 'tile roof', + 'toaster', + 'tobacco shop', + 'toilet seat', + 'torch', + 'totem pole', + 'tow truck', + 'toyshop', + 'tractor', + 'trailer truck', + 'tray', + 'trench coat', + 'tricycle', + 'trimaran', + 'tripod', + 'triumphal arch', + 'trolleybus', + 'trombone', + 'tub', + 'turnstile', + 'typewriter keyboard', + 'umbrella', + 'unicycle', + 'upright', + 'vacuum', + 'vase', + 'vault', + 'velvet', + 'vending machine', + 'vestment', + 'viaduct', + 'violin', + 'volleyball', + 'waffle iron', + 'wall clock', + 'wallet', + 'wardrobe', + 'warplane', + 'washbasin', + 'washer', + 'water bottle', + 'water jug', + 'water tower', + 'whiskey jug', + 'whistle', + 'wig', + 'window screen', + 'window shade', + 'Windsor tie', + 'wine bottle', + 'wing', + 'wok', + 'wooden spoon', + 'wool', + 'worm fence', + 'wreck', + 'yawl', + 'yurt', + 'web site', + 'comic book', + 'crossword puzzle', + 'street sign', + 'traffic light', + 'book jacket', + 'menu', + 'plate', + 'guacamole', + 'consomme', + 'hot pot', + 'trifle', + 'ice cream', + 'ice lolly', + 'French loaf', + 'bagel', + 'pretzel', + 'cheeseburger', + 'hotdog', + 'mashed potato', + 'head cabbage', + 'broccoli', + 'cauliflower', + 'zucchini', + 'spaghetti squash', + 'acorn squash', + 'butternut squash', + 'cucumber', + 'artichoke', + 'bell pepper', + 'cardoon', + 'mushroom', + 'Granny Smith', + 'strawberry', + 'orange', + 'lemon', + 'fig', + 'pineapple', + 'banana', + 'jackfruit', + 'custard apple', + 'pomegranate', + 'hay', + 'carbonara', + 'chocolate sauce', + 'dough', + 'meat loaf', + 'pizza', + 'potpie', + 'burrito', + 'red wine', + 'espresso', + 'cup', + 'eggnog', + 'alp', + 'bubble', + 'cliff', + 'coral reef', + 'geyser', + 'lakeside', + 'promontory', + 'sandbar', + 'seashore', + 'valley', + 'volcano', + 'ballplayer', + 'groom', + 'scuba diver', + 'rapeseed', + 'daisy', + 'yellow ladys slipper', + 'corn', + 'acorn', + 'hip', + 'buckeye', + 'coral fungus', + 'agaric', + 'gyromitra', + 'stinkhorn', + 'earthstar', + 'hen-of-the-woods', + 'bolete', + 'ear', + 'toilet tissue', +) + + +imagenet_loc_synset_ids = ( + 'n01440764', + 'n01443537', + 'n01484850', + 'n01491361', + 'n01494475', + 'n01496331', + 'n01498041', + 'n01514668', + 'n01514859', + 'n01518878', + 'n01530575', + 'n01531178', + 'n01532829', + 'n01534433', + 'n01537544', + 'n01558993', + 'n01560419', + 'n01580077', + 'n01582220', + 'n01592084', + 'n01601694', + 'n01608432', + 'n01614925', + 'n01616318', + 'n01622779', + 'n01629819', + 'n01630670', + 'n01631663', + 'n01632458', + 'n01632777', + 'n01641577', + 'n01644373', + 'n01644900', + 'n01664065', + 'n01665541', + 'n01667114', + 'n01667778', + 'n01669191', + 'n01675722', + 'n01677366', + 'n01682714', + 'n01685808', + 'n01687978', + 'n01688243', + 'n01689811', + 'n01692333', + 'n01693334', + 'n01694178', + 'n01695060', + 'n01697457', + 'n01698640', + 'n01704323', + 'n01728572', + 'n01728920', + 'n01729322', + 'n01729977', + 'n01734418', + 'n01735189', + 'n01737021', + 'n01739381', + 'n01740131', + 'n01742172', + 'n01744401', + 'n01748264', + 'n01749939', + 'n01751748', + 'n01753488', + 'n01755581', + 'n01756291', + 'n01768244', + 'n01770081', + 'n01770393', + 'n01773157', + 'n01773549', + 'n01773797', + 'n01774384', + 'n01774750', + 'n01775062', + 'n01776313', + 'n01784675', + 'n01795545', + 'n01796340', + 'n01797886', + 'n01798484', + 'n01806143', + 'n01806567', + 'n01807496', + 'n01817953', + 'n01818515', + 'n01819313', + 'n01820546', + 'n01824575', + 'n01828970', + 'n01829413', + 'n01833805', + 'n01843065', + 'n01843383', + 'n01847000', + 'n01855032', + 'n01855672', + 'n01860187', + 'n01871265', + 'n01872401', + 'n01873310', + 'n01877812', + 'n01882714', + 'n01883070', + 'n01910747', + 'n01914609', + 'n01917289', + 'n01924916', + 'n01930112', + 'n01943899', + 'n01944390', + 'n01945685', + 'n01950731', + 'n01955084', + 'n01968897', + 'n01978287', + 'n01978455', + 'n01980166', + 'n01981276', + 'n01983481', + 'n01984695', + 'n01985128', + 'n01986214', + 'n01990800', + 'n02002556', + 'n02002724', + 'n02006656', + 'n02007558', + 'n02009229', + 'n02009912', + 'n02011460', + 'n02012849', + 'n02013706', + 'n02017213', + 'n02018207', + 'n02018795', + 'n02025239', + 'n02027492', + 'n02028035', + 'n02033041', + 'n02037110', + 'n02051845', + 'n02056570', + 'n02058221', + 'n02066245', + 'n02071294', + 'n02074367', + 'n02077923', + 'n02085620', + 'n02085782', + 'n02085936', + 'n02086079', + 'n02086240', + 'n02086646', + 'n02086910', + 'n02087046', + 'n02087394', + 'n02088094', + 'n02088238', + 'n02088364', + 'n02088466', + 'n02088632', + 'n02089078', + 'n02089867', + 'n02089973', + 'n02090379', + 'n02090622', + 'n02090721', + 'n02091032', + 'n02091134', + 'n02091244', + 'n02091467', + 'n02091635', + 'n02091831', + 'n02092002', + 'n02092339', + 'n02093256', + 'n02093428', + 'n02093647', + 'n02093754', + 'n02093859', + 'n02093991', + 'n02094114', + 'n02094258', + 'n02094433', + 'n02095314', + 'n02095570', + 'n02095889', + 'n02096051', + 'n02096177', + 'n02096294', + 'n02096437', + 'n02096585', + 'n02097047', + 'n02097130', + 'n02097209', + 'n02097298', + 'n02097474', + 'n02097658', + 'n02098105', + 'n02098286', + 'n02098413', + 'n02099267', + 'n02099429', + 'n02099601', + 'n02099712', + 'n02099849', + 'n02100236', + 'n02100583', + 'n02100735', + 'n02100877', + 'n02101006', + 'n02101388', + 'n02101556', + 'n02102040', + 'n02102177', + 'n02102318', + 'n02102480', + 'n02102973', + 'n02104029', + 'n02104365', + 'n02105056', + 'n02105162', + 'n02105251', + 'n02105412', + 'n02105505', + 'n02105641', + 'n02105855', + 'n02106030', + 'n02106166', + 'n02106382', + 'n02106550', + 'n02106662', + 'n02107142', + 'n02107312', + 'n02107574', + 'n02107683', + 'n02107908', + 'n02108000', + 'n02108089', + 'n02108422', + 'n02108551', + 'n02108915', + 'n02109047', + 'n02109525', + 'n02109961', + 'n02110063', + 'n02110185', + 'n02110341', + 'n02110627', + 'n02110806', + 'n02110958', + 'n02111129', + 'n02111277', + 'n02111500', + 'n02111889', + 'n02112018', + 'n02112137', + 'n02112350', + 'n02112706', + 'n02113023', + 'n02113186', + 'n02113624', + 'n02113712', + 'n02113799', + 'n02113978', + 'n02114367', + 'n02114548', + 'n02114712', + 'n02114855', + 'n02115641', + 'n02115913', + 'n02116738', + 'n02117135', + 'n02119022', + 'n02119789', + 'n02120079', + 'n02120505', + 'n02123045', + 'n02123159', + 'n02123394', + 'n02123597', + 'n02124075', + 'n02125311', + 'n02127052', + 'n02128385', + 'n02128757', + 'n02128925', + 'n02129165', + 'n02129604', + 'n02130308', + 'n02132136', + 'n02133161', + 'n02134084', + 'n02134418', + 'n02137549', + 'n02138441', + 'n02165105', + 'n02165456', + 'n02167151', + 'n02168699', + 'n02169497', + 'n02172182', + 'n02174001', + 'n02177972', + 'n02190166', + 'n02206856', + 'n02219486', + 'n02226429', + 'n02229544', + 'n02231487', + 'n02233338', + 'n02236044', + 'n02256656', + 'n02259212', + 'n02264363', + 'n02268443', + 'n02268853', + 'n02276258', + 'n02277742', + 'n02279972', + 'n02280649', + 'n02281406', + 'n02281787', + 'n02317335', + 'n02319095', + 'n02321529', + 'n02325366', + 'n02326432', + 'n02328150', + 'n02342885', + 'n02346627', + 'n02356798', + 'n02361337', + 'n02363005', + 'n02364673', + 'n02389026', + 'n02391049', + 'n02395406', + 'n02396427', + 'n02397096', + 'n02398521', + 'n02403003', + 'n02408429', + 'n02410509', + 'n02412080', + 'n02415577', + 'n02417914', + 'n02422106', + 'n02422699', + 'n02423022', + 'n02437312', + 'n02437616', + 'n02441942', + 'n02442845', + 'n02443114', + 'n02443484', + 'n02444819', + 'n02445715', + 'n02447366', + 'n02454379', + 'n02457408', + 'n02480495', + 'n02480855', + 'n02481823', + 'n02483362', + 'n02483708', + 'n02484975', + 'n02486261', + 'n02486410', + 'n02487347', + 'n02488291', + 'n02488702', + 'n02489166', + 'n02490219', + 'n02492035', + 'n02492660', + 'n02493509', + 'n02493793', + 'n02494079', + 'n02497673', + 'n02500267', + 'n02504013', + 'n02504458', + 'n02509815', + 'n02510455', + 'n02514041', + 'n02526121', + 'n02536864', + 'n02606052', + 'n02607072', + 'n02640242', + 'n02641379', + 'n02643566', + 'n02655020', + 'n02666196', + 'n02667093', + 'n02669723', + 'n02672831', + 'n02676566', + 'n02687172', + 'n02690373', + 'n02692877', + 'n02699494', + 'n02701002', + 'n02704792', + 'n02708093', + 'n02727426', + 'n02730930', + 'n02747177', + 'n02749479', + 'n02769748', + 'n02776631', + 'n02777292', + 'n02782093', + 'n02783161', + 'n02786058', + 'n02787622', + 'n02788148', + 'n02790996', + 'n02791124', + 'n02791270', + 'n02793495', + 'n02794156', + 'n02795169', + 'n02797295', + 'n02799071', + 'n02802426', + 'n02804414', + 'n02804610', + 'n02807133', + 'n02808304', + 'n02808440', + 'n02814533', + 'n02814860', + 'n02815834', + 'n02817516', + 'n02823428', + 'n02823750', + 'n02825657', + 'n02834397', + 'n02835271', + 'n02837789', + 'n02840245', + 'n02841315', + 'n02843684', + 'n02859443', + 'n02860847', + 'n02865351', + 'n02869837', + 'n02870880', + 'n02871525', + 'n02877765', + 'n02879718', + 'n02883205', + 'n02892201', + 'n02892767', + 'n02894605', + 'n02895154', + 'n02906734', + 'n02909870', + 'n02910353', + 'n02916936', + 'n02917067', + 'n02927161', + 'n02930766', + 'n02939185', + 'n02948072', + 'n02950826', + 'n02951358', + 'n02951585', + 'n02963159', + 'n02965783', + 'n02966193', + 'n02966687', + 'n02971356', + 'n02974003', + 'n02977058', + 'n02978881', + 'n02979186', + 'n02980441', + 'n02981792', + 'n02988304', + 'n02992211', + 'n02992529', + 'n02999410', + 'n03000134', + 'n03000247', + 'n03000684', + 'n03014705', + 'n03016953', + 'n03017168', + 'n03018349', + 'n03026506', + 'n03028079', + 'n03032252', + 'n03041632', + 'n03042490', + 'n03045698', + 'n03047690', + 'n03062245', + 'n03063599', + 'n03063689', + 'n03065424', + 'n03075370', + 'n03085013', + 'n03089624', + 'n03095699', + 'n03100240', + 'n03109150', + 'n03110669', + 'n03124043', + 'n03124170', + 'n03125729', + 'n03126707', + 'n03127747', + 'n03127925', + 'n03131574', + 'n03133878', + 'n03134739', + 'n03141823', + 'n03146219', + 'n03160309', + 'n03179701', + 'n03180011', + 'n03187595', + 'n03188531', + 'n03196217', + 'n03197337', + 'n03201208', + 'n03207743', + 'n03207941', + 'n03208938', + 'n03216828', + 'n03218198', + 'n03220513', + 'n03223299', + 'n03240683', + 'n03249569', + 'n03250847', + 'n03255030', + 'n03259280', + 'n03271574', + 'n03272010', + 'n03272562', + 'n03290653', + 'n03291819', + 'n03297495', + 'n03314780', + 'n03325584', + 'n03337140', + 'n03344393', + 'n03345487', + 'n03347037', + 'n03355925', + 'n03372029', + 'n03376595', + 'n03379051', + 'n03384352', + 'n03388043', + 'n03388183', + 'n03388549', + 'n03393912', + 'n03394916', + 'n03400231', + 'n03404251', + 'n03417042', + 'n03424325', + 'n03425413', + 'n03443371', + 'n03444034', + 'n03445777', + 'n03445924', + 'n03447447', + 'n03447721', + 'n03450230', + 'n03452741', + 'n03457902', + 'n03459775', + 'n03461385', + 'n03467068', + 'n03476684', + 'n03476991', + 'n03478589', + 'n03481172', + 'n03482405', + 'n03483316', + 'n03485407', + 'n03485794', + 'n03492542', + 'n03494278', + 'n03495258', + 'n03496892', + 'n03498962', + 'n03527444', + 'n03529860', + 'n03530642', + 'n03532672', + 'n03534580', + 'n03535780', + 'n03538406', + 'n03544143', + 'n03584254', + 'n03584829', + 'n03590841', + 'n03594734', + 'n03594945', + 'n03595614', + 'n03598930', + 'n03599486', + 'n03602883', + 'n03617480', + 'n03623198', + 'n03627232', + 'n03630383', + 'n03633091', + 'n03637318', + 'n03642806', + 'n03649909', + 'n03657121', + 'n03658185', + 'n03661043', + 'n03662601', + 'n03666591', + 'n03670208', + 'n03673027', + 'n03676483', + 'n03680355', + 'n03690938', + 'n03691459', + 'n03692522', + 'n03697007', + 'n03706229', + 'n03709823', + 'n03710193', + 'n03710637', + 'n03710721', + 'n03717622', + 'n03720891', + 'n03721384', + 'n03724870', + 'n03729826', + 'n03733131', + 'n03733281', + 'n03733805', + 'n03742115', + 'n03743016', + 'n03759954', + 'n03761084', + 'n03763968', + 'n03764736', + 'n03769881', + 'n03770439', + 'n03770679', + 'n03773504', + 'n03775071', + 'n03775546', + 'n03776460', + 'n03777568', + 'n03777754', + 'n03781244', + 'n03782006', + 'n03785016', + 'n03786901', + 'n03787032', + 'n03788195', + 'n03788365', + 'n03791053', + 'n03792782', + 'n03792972', + 'n03793489', + 'n03794056', + 'n03796401', + 'n03803284', + 'n03804744', + 'n03814639', + 'n03814906', + 'n03825788', + 'n03832673', + 'n03837869', + 'n03838899', + 'n03840681', + 'n03841143', + 'n03843555', + 'n03854065', + 'n03857828', + 'n03866082', + 'n03868242', + 'n03868863', + 'n03871628', + 'n03873416', + 'n03874293', + 'n03874599', + 'n03876231', + 'n03877472', + 'n03877845', + 'n03884397', + 'n03887697', + 'n03888257', + 'n03888605', + 'n03891251', + 'n03891332', + 'n03895866', + 'n03899768', + 'n03902125', + 'n03903868', + 'n03908618', + 'n03908714', + 'n03916031', + 'n03920288', + 'n03924679', + 'n03929660', + 'n03929855', + 'n03930313', + 'n03930630', + 'n03933933', + 'n03935335', + 'n03937543', + 'n03938244', + 'n03942813', + 'n03944341', + 'n03947888', + 'n03950228', + 'n03954731', + 'n03956157', + 'n03958227', + 'n03961711', + 'n03967562', + 'n03970156', + 'n03976467', + 'n03976657', + 'n03977966', + 'n03980874', + 'n03982430', + 'n03983396', + 'n03991062', + 'n03992509', + 'n03995372', + 'n03998194', + 'n04004767', + 'n04005630', + 'n04008634', + 'n04009552', + 'n04019541', + 'n04023962', + 'n04026417', + 'n04033901', + 'n04033995', + 'n04037443', + 'n04039381', + 'n04040759', + 'n04041544', + 'n04044716', + 'n04049303', + 'n04065272', + 'n04067472', + 'n04069434', + 'n04070727', + 'n04074963', + 'n04081281', + 'n04086273', + 'n04090263', + 'n04099969', + 'n04111531', + 'n04116512', + 'n04118538', + 'n04118776', + 'n04120489', + 'n04125021', + 'n04127249', + 'n04131690', + 'n04133789', + 'n04136333', + 'n04141076', + 'n04141327', + 'n04141975', + 'n04146614', + 'n04147183', + 'n04149813', + 'n04152593', + 'n04153751', + 'n04154565', + 'n04162706', + 'n04179913', + 'n04192698', + 'n04200800', + 'n04201297', + 'n04204238', + 'n04204347', + 'n04208210', + 'n04209133', + 'n04209239', + 'n04228054', + 'n04229816', + 'n04235860', + 'n04238763', + 'n04239074', + 'n04243546', + 'n04251144', + 'n04252077', + 'n04252225', + 'n04254120', + 'n04254680', + 'n04254777', + 'n04258138', + 'n04259630', + 'n04263257', + 'n04264628', + 'n04265275', + 'n04266014', + 'n04270147', + 'n04273569', + 'n04275548', + 'n04277352', + 'n04285008', + 'n04286575', + 'n04296562', + 'n04310018', + 'n04311004', + 'n04311174', + 'n04317175', + 'n04325704', + 'n04326547', + 'n04328186', + 'n04330267', + 'n04332243', + 'n04335435', + 'n04336792', + 'n04344873', + 'n04346328', + 'n04347754', + 'n04350905', + 'n04355338', + 'n04355933', + 'n04356056', + 'n04357314', + 'n04366367', + 'n04367480', + 'n04370456', + 'n04371430', + 'n04371774', + 'n04372370', + 'n04376876', + 'n04380533', + 'n04389033', + 'n04392985', + 'n04398044', + 'n04399382', + 'n04404412', + 'n04409515', + 'n04417672', + 'n04418357', + 'n04423845', + 'n04428191', + 'n04429376', + 'n04435653', + 'n04442312', + 'n04443257', + 'n04447861', + 'n04456115', + 'n04458633', + 'n04461696', + 'n04462240', + 'n04465501', + 'n04467665', + 'n04476259', + 'n04479046', + 'n04482393', + 'n04483307', + 'n04485082', + 'n04486054', + 'n04487081', + 'n04487394', + 'n04493381', + 'n04501370', + 'n04505470', + 'n04507155', + 'n04509417', + 'n04515003', + 'n04517823', + 'n04522168', + 'n04523525', + 'n04525038', + 'n04525305', + 'n04532106', + 'n04532670', + 'n04536866', + 'n04540053', + 'n04542943', + 'n04548280', + 'n04548362', + 'n04550184', + 'n04552348', + 'n04553703', + 'n04554684', + 'n04557648', + 'n04560804', + 'n04562935', + 'n04579145', + 'n04579432', + 'n04584207', + 'n04589890', + 'n04590129', + 'n04591157', + 'n04591713', + 'n04592741', + 'n04596742', + 'n04597913', + 'n04599235', + 'n04604644', + 'n04606251', + 'n04612504', + 'n04613696', + 'n06359193', + 'n06596364', + 'n06785654', + 'n06794110', + 'n06874185', + 'n07248320', + 'n07565083', + 'n07579787', + 'n07583066', + 'n07584110', + 'n07590611', + 'n07613480', + 'n07614500', + 'n07615774', + 'n07684084', + 'n07693725', + 'n07695742', + 'n07697313', + 'n07697537', + 'n07711569', + 'n07714571', + 'n07714990', + 'n07715103', + 'n07716358', + 'n07716906', + 'n07717410', + 'n07717556', + 'n07718472', + 'n07718747', + 'n07720875', + 'n07730033', + 'n07734744', + 'n07742313', + 'n07745940', + 'n07747607', + 'n07749582', + 'n07753113', + 'n07753275', + 'n07753592', + 'n07754684', + 'n07760859', + 'n07768694', + 'n07802026', + 'n07831146', + 'n07836838', + 'n07860988', + 'n07871810', + 'n07873807', + 'n07875152', + 'n07880968', + 'n07892512', + 'n07920052', + 'n07930864', + 'n07932039', + 'n09193705', + 'n09229709', + 'n09246464', + 'n09256479', + 'n09288635', + 'n09332890', + 'n09399592', + 'n09421951', + 'n09428293', + 'n09468604', + 'n09472597', + 'n09835506', + 'n10148035', + 'n10565667', + 'n11879895', + 'n11939491', + 'n12057211', + 'n12144580', + 'n12267677', + 'n12620546', + 'n12768682', + 'n12985857', + 'n12998815', + 'n13037406', + 'n13040303', + 'n13044778', + 'n13052670', + 'n13054560', + 'n13133613', + 'n15075141') diff --git a/chainercv/datasets/voc/voc_bbox_dataset.py b/chainercv/datasets/voc/voc_bbox_dataset.py index 87ab8ad815..5b4c8b1758 100644 --- a/chainercv/datasets/voc/voc_bbox_dataset.py +++ b/chainercv/datasets/voc/voc_bbox_dataset.py @@ -1,7 +1,6 @@ import numpy as np import os import warnings -import xml.etree.ElementTree as ET from chainercv.chainer_experimental.datasets.sliceable import GetterDataset from chainercv.datasets.voc import voc_utils @@ -89,27 +88,11 @@ def _get_image(self, i): def _get_annotations(self, i): id_ = self.ids[i] - anno = ET.parse( - os.path.join(self.data_dir, 'Annotations', id_ + '.xml')) - bbox = [] - label = [] - difficult = [] - for obj in anno.findall('object'): - # when in not using difficult split, and the object is - # difficult, skipt it. - if not self.use_difficult and int(obj.find('difficult').text) == 1: - continue - - difficult.append(int(obj.find('difficult').text)) - bndbox_anno = obj.find('bndbox') - # subtract 1 to make pixel indexes 0-based - bbox.append([ - int(bndbox_anno.find(tag).text) - 1 - for tag in ('ymin', 'xmin', 'ymax', 'xmax')]) - name = obj.find('name').text.lower().strip() - label.append(voc_utils.voc_bbox_label_names.index(name)) - bbox = np.stack(bbox).astype(np.float32) - label = np.stack(label).astype(np.int32) - # When `use_difficult==False`, all elements in `difficult` are False. - difficult = np.array(difficult, dtype=np.bool) + anno_path = os.path.join(self.data_dir, 'Annotations', id_ + '.xml') + bbox, label, difficult = voc_utils.parse_voc_bbox_annotation( + anno_path, voc_utils.voc_bbox_label_names) + if not self.use_difficult: + bbox = bbox[np.logical_not(difficult)] + label = label[np.logical_not(difficult)] + difficult = difficult[np.logical_not(difficult)] return bbox, label, difficult diff --git a/chainercv/datasets/voc/voc_utils.py b/chainercv/datasets/voc/voc_utils.py index ef09200f3a..08728398e8 100644 --- a/chainercv/datasets/voc/voc_utils.py +++ b/chainercv/datasets/voc/voc_utils.py @@ -1,5 +1,6 @@ import numpy as np import os +import xml.etree.ElementTree as ET from chainer.dataset import download @@ -38,6 +39,42 @@ def get_voc(year, split): return base_path +def parse_voc_bbox_annotation(anno_path, label_names, + skip_names_not_in_label_names=False): + anno = ET.parse(anno_path) + bbox = [] + label = [] + difficult = [] + obj = anno.find('size') + H = int(obj.find('height').text) + W = int(obj.find('width').text) + for obj in anno.findall('object'): + name = obj.find('name').text.lower().strip() + if skip_names_not_in_label_names and name not in label_names: + continue + label.append(label_names.index(name)) + bndbox_anno = obj.find('bndbox') + # subtract 1 to make pixel indexes 0-based + bbox.append([ + int(bndbox_anno.find(tag).text) - 1 + for tag in ('ymin', 'xmin', 'ymax', 'xmax')]) + if obj.find('difficult') is not None: + difficult.append(int(obj.find('difficult').text)) + + if len(bbox) > 0: + bbox = np.stack(bbox).astype(np.float32) + bbox[:, 0:2] = bbox[:, 0:2].clip(0) + bbox[:, 2] = bbox[:, 2].clip(0, H) + bbox[:, 3] = bbox[:, 3].clip(0, W) + label = np.stack(label).astype(np.int32) + difficult = np.array(difficult, dtype=np.bool) + else: + bbox = np.zeros((0, 4), dtype=np.float32) + label = np.zeros((0,), dtype=np.int32) + difficult = np.zeros((0,), dtype=np.bool) + return bbox, label, difficult + + def image_wise_to_instance_wise(label_img, inst_img): mask = [] label = [] diff --git a/docs/source/reference/datasets.rst b/docs/source/reference/datasets.rst index 8c7e6e85ed..732ff8122c 100644 --- a/docs/source/reference/datasets.rst +++ b/docs/source/reference/datasets.rst @@ -62,6 +62,17 @@ CUBPointDataset ~~~~~~~~~~~~~~~ .. autoclass:: CUBPointDataset +Imagenet +-------- + +ImagenetDetBboxDataset +~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: ImagenetDetBboxDataset + +ImagenetLocBboxDataset +~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: ImagenetLocBboxDataset + MS COCO -------