from .lvis_categories_tr import ID2NAME,NAME2ID,SYNSET2ID
LVIS_CATEGORIES = [{'name': 'lettuce', 'instance_count': 5500, 'def': 'leafy plant commonly eaten in salad or on sandwiches', 'synonyms': ['lettuce'], 'image_count': 705, 'id': 641, 'frequency': 'f', 'synset': 'lettuce.n.02'}, {'name': 'sunglasses', 'instance_count': 5603, 'def': 'spectacles that are darkened or polarized to protect the eyes from the glare of the sun', 'synonyms': ['sunglasses'], 'image_count': 1931, 'id': 1035, 'frequency': 'f', 'synset': 'sunglasses.n.01'}, {'name': 'magnet', 'instance_count': 5638, 'def': 'a device that attracts iron and produces a magnetic field', 'synonyms': ['magnet'], 'image_count': 334, 'id': 659, 'frequency': 'f', 'synset': 'magnet.n.01'}, {'name': 'banner', 'instance_count': 5907, 'def': 'long strip of cloth or paper used for decoration or advertising', 'synonyms': ['banner', 'streamer'], 'image_count': 1470, 'id': 50, 'frequency': 'f', 'synset': 'banner.n.01'}, {'name': 'glove', 'instance_count': 5951, 'def': 'handwear covering the hand', 'synonyms': ['glove'], 'image_count': 1890, 'id': 500, 'frequency': 'f', 'synset': 'glove.n.02'}, {'name': 'pillow', 'instance_count': 6115, 'def': 'a cushion to support the head of a sleeping person', 'synonyms': ['pillow'], 'image_count': 1912, 'id': 804, 'frequency': 'f', 'synset': 'pillow.n.01'}, {'name': 'mushroom', 'instance_count': 6257, 'def': 'a common mushroom', 'synonyms': ['mushroom'], 'image_count': 407, 'id': 709, 'frequency': 'f', 'synset': 'mushroom.n.02'}, {'name': 'grape', 'instance_count': 6377, 'def': 'any of various juicy fruit with green or purple skins; grow in clusters', 'synonyms': ['grape'], 'image_count': 233, 'id': 510, 'frequency': 'f', 'synset': 'grape.n.01'}, {'name': 'glass_(drink_container)', 'instance_count': 6420, 'def': 'a container for holding liquids while drinking', 'synonyms': ['glass_(drink_container)', 'drinking_glass'], 'image_count': 1920, 'id': 498, 'frequency': 'f', 'synset': 'glass.n.02'}, {'name': 'bread', 'instance_count': 6550, 'def': 'food made from dough of flour or meal and usually raised with yeast or baking powder and then baked', 'synonyms': ['bread'], 'image_count': 1567, 'id': 150, 'frequency': 'f', 'synset': 'bread.n.01'}, {'name': 'toy', 'instance_count': 6756, 'def': 'a device regarded as providing amusement', 'synonyms': ['toy'], 'image_count': 1149, 'id': 1110, 'frequency': 'f', 'synset': 'toy.n.03'}, {'name': 'sock', 'instance_count': 6866, 'def': 'cloth covering for the foot; worn inside the shoe; reaches to between the ankle and the knee', 'synonyms': ['sock'], 'image_count': 1945, 'id': 981, 'frequency': 'f', 'synset': 'sock.n.01'}, {'name': 'crossbar', 'instance_count': 6991, 'def': 'a horizontal bar that goes across something', 'synonyms': ['crossbar'], 'image_count': 1027, 'id': 330, 'frequency': 'f', 'synset': 'crossbar.n.01'}, {'name': 'flag', 'instance_count': 7007, 'def': 'emblem usually consisting of a rectangular piece of cloth of distinctive design (do not include pole)', 'synonyms': ['flag'], 'image_count': 1908, 'id': 451, 'frequency': 'f', 'synset': 'flag.n.01'}, {'name': 'lightbulb', 'instance_count': 7075, 'def': 'lightblub/source of light', 'synonyms': ['lightbulb'], 'image_count': 861, 'id': 645, 'frequency': 'f', 'synset': 'light_bulb.n.01'}, {'name': 'cushion', 'instance_count': 7174, 'def': 'a soft bag filled with air or padding such as feathers or foam rubber', 'synonyms': ['cushion'], 'image_count': 1240, 'id': 351, 'frequency': 'f', 'synset': 'cushion.n.03'}, {'name': 'hat', 'instance_count': 7213, 'def': 'headwear that protects the head from bad weather, sun, or worn for fashion', 'synonyms': ['hat'], 'image_count': 1932, 'id': 544, 'frequency': 'f', 'synset': 'hat.n.01'}, {'name': 'traffic_light', 'instance_count': 7298, 'def': 'a device to control vehicle traffic often consisting of three or more lights', 'synonyms': ['traffic_light'], 'image_count': 1890, 'id': 1112, 'frequency': 'f', 'synset': 'traffic_light.n.01'}, {'name': 'headlight', 'instance_count': 7326, 'def': 'a powerful light with reflector; attached to the front of an automobile or locomotive', 'synonyms': ['headlight', 'headlamp'], 'image_count': 1843, 'id': 549, 'frequency': 'f', 'synset': 'headlight.n.01'}, {'name': 'log', 'instance_count': 7363, 'def': 'a segment of the trunk of a tree when stripped of branches', 'synonyms': ['log'], 'image_count': 1167, 'id': 653, 'frequency': 'f', 'synset': 'log.n.01'}, {'name': 'cabinet', 'instance_count': 7371, 'def': 'a piece of furniture resembling a cupboard with doors and shelves and drawers', 'synonyms': ['cabinet'], 'image_count': 1659, 'id': 181, 'frequency': 'f', 'synset': 'cabinet.n.01'}, {'name': 'streetlight', 'instance_count': 7381, 'def': 'a lamp supported on a lamppost; for illuminating a street', 'synonyms': ['streetlight', 'street_lamp'], 'image_count': 1765, 'id': 1027, 'frequency': 'f', 'synset': 'streetlight.n.01'}, {'name': 'strap', 'instance_count': 7435, 'def': 'an elongated strip of material for binding things together or holding', 'synonyms': ['strap'], 'image_count': 1881, 'id': 1023, 'frequency': 'f', 'synset': 'strap.n.01'}, {'name': 'tag', 'instance_count': 7550, 'def': 'a label associated with something for the purpose of identification or information', 'synonyms': ['tag'], 'image_count': 1562, 'id': 1055, 'frequency': 'f', 'synset': 'tag.n.02'}, {'name': 'trousers', 'instance_count': 7806, 'def': 'a garment extending from the waist to the knee or ankle, covering each leg separately', 'synonyms': ['trousers', 'pants_(clothing)'], 'image_count': 1909, 'id': 1122, 'frequency': 'f', 'synset': 'trouser.n.01'}, {'name': 'box', 'instance_count': 7855, 'def': 'a (usually rectangular) container; may have a lid', 'synonyms': ['box'], 'image_count': 1828, 'id': 143, 'frequency': 'f', 'synset': 'box.n.01'}, {'name': 'button', 'instance_count': 7884, 'def': 'a round fastener sewn to shirts and coats etc to fit through buttonholes', 'synonyms': ['button'], 'image_count': 1884, 'id': 177, 'frequency': 'f', 'synset': 'button.n.01'}, {'name': 'drawer', 'instance_count': 7927, 'def': 'a boxlike container in a piece of furniture; made so as to slide in and out', 'synonyms': ['drawer'], 'image_count': 1942, 'id': 390, 'frequency': 'f', 'synset': 'drawer.n.01'}, {'name': 'bottle', 'instance_count': 7969, 'def': 'a glass or plastic vessel used for storing drinks or other liquids', 'synonyms': ['bottle'], 'image_count': 1901, 'id': 133, 'frequency': 'f', 'synset': 'bottle.n.01'}, {'name': 'jacket', 'instance_count': 8013, 'def': 'a waist-length coat', 'synonyms': ['jacket'], 'image_count': 1872, 'id': 589, 'frequency': 'f', 'synset': 'jacket.n.01'}, {'name': 'cow', 'instance_count': 8085, 'def': 'cattle/cow', 'synonyms': ['cow'], 'image_count': 1420, 'id': 80, 'frequency': 'f', 'synset': 'beef.n.01'}, {'name': 'signboard', 'instance_count': 8091, 'def': 'structure displaying a board on which advertisements can be posted', 'synonyms': ['signboard'], 'image_count': 1826, 'id': 959, 'frequency': 'f', 'synset': 'signboard.n.01'}, {'name': 'jersey', 'instance_count': 8117, 'def': 'a close-fitting pullover shirt', 'synonyms': ['jersey', 'T-shirt', 'tee_shirt'], 'image_count': 1945, 'id': 595, 'frequency': 'f', 'synset': 'jersey.n.03'}, {'name': 'ski_boot', 'instance_count': 8124, 'def': 'a stiff boot that is fastened to a ski with a ski binding', 'synonyms': ['ski_boot'], 'image_count': 1789, 'id': 965, 'frequency': 'f', 'synset': 'ski_boot.n.01'}, {'name': 'ski_pole', 'instance_count': 8263, 'def': 'a pole with metal points used as an aid in skiing', 'synonyms': ['ski_pole'], 'image_count': 1968, 'id': 967, 'frequency': 'f', 'synset': 'ski_pole.n.01'}, {'name': 'handle', 'instance_count': 8314, 'def': 'the appendage to an object that is designed to be held in order to use or move it', 'synonyms': ['handle', 'grip', 'handgrip'], 'image_count': 1886, 'id': 540, 'frequency': 'f', 'synset': 'handle.n.01'}, {'name': 'street_sign', 'instance_count': 8350, 'def': 'a sign visible from the street', 'synonyms': ['street_sign'], 'image_count': 1911, 'id': 1026, 'frequency': 'f', 'synset': 'street_sign.n.01'}, {'name': 'knob', 'instance_count': 8432, 'def': 'a round handle often found on a door', 'synonyms': ['knob'], 'image_count': 1567, 'id': 617, 'frequency': 'f', 'synset': 'knob.n.02'}, {'name': 'ski', 'instance_count': 8496, 'def': 'sports equipment for skiing on snow', 'synonyms': ['ski'], 'image_count': 1926, 'id': 964, 'frequency': 'f', 'synset': 'ski.n.01'}, {'name': 'suitcase', 'instance_count': 8537, 'def': 'cases used to carry belongings when traveling', 'synonyms': ['suitcase', 'baggage', 'luggage'], 'image_count': 1623, 'id': 36, 'frequency': 'f', 'synset': 'bag.n.06'}, {'name': 'baseball_cap', 'instance_count': 9028, 'def': 'a cap with a bill', 'synonyms': ['baseball_cap', 'jockey_cap', 'golf_cap'], 'image_count': 1934, 'id': 59, 'frequency': 'f', 'synset': 'baseball_cap.n.01'}, {'name': 'umbrella', 'instance_count': 9161, 'def': 'a lightweight handheld collapsible canopy', 'synonyms': ['umbrella'], 'image_count': 1924, 'id': 1133, 'frequency': 'f', 'synset': 'umbrella.n.01'}, {'name': 'taillight', 'instance_count': 9222, 'def': 'lamp (usually red) mounted at the rear of a motor vehicle', 'synonyms': ['taillight', 'rear_light'], 'image_count': 1885, 'id': 1056, 'frequency': 'f', 'synset': 'taillight.n.01'}, {'name': 'shoe', 'instance_count': 9374, 'def': 'common footwear covering the foot', 'synonyms': ['shoe', 'sneaker_(type_of_shoe)', 'tennis_shoe'], 'image_count': 1916, 'id': 948, 'frequency': 'f', 'synset': 'shoe.n.01'}, {'name': 'onion', 'instance_count': 9779, 'def': 'the bulb of an onion plant', 'synonyms': ['onion'], 'image_count': 647, 'id': 734, 'frequency': 'f', 'synset': 'onion.n.01'}, {'name': 'boat', 'instance_count': 9981, 'def': 'a vessel for travel on water', 'synonyms': ['boat', 'ship_(boat)'], 'image_count': 1758, 'id': 118, 'frequency': 'f', 'synset': 'boat.n.01'}, {'name': 'shirt', 'instance_count': 10177, 'def': 'a garment worn on the upper half of the body', 'synonyms': ['shirt'], 'image_count': 1942, 'id': 947, 'frequency': 'f', 'synset': 'shirt.n.01'}, {'name': 'car_(automobile)', 'instance_count': 10528, 'def': 'a motor vehicle with four wheels', 'synonyms': ['car_(automobile)', 'auto_(automobile)', 'automobile'], 'image_count': 1926, 'id': 207, 'frequency': 'f', 'synset': 'car.n.01'}, {'name': 'kite', 'instance_count': 11174, 'def': 'plaything consisting of a light frame covered with tissue paper; flown in wind at end of a string', 'synonyms': ['kite'], 'image_count': 1689, 'id': 611, 'frequency': 'f', 'synset': 'kite.n.03'}, {'name': 'bolt', 'instance_count': 11261, 'def': 'a screw that screws into a nut to form a fastener', 'synonyms': ['bolt'], 'image_count': 1510, 'id': 125, 'frequency': 'f', 'synset': 'bolt.n.06'}, {'name': 'wheel', 'instance_count': 11272, 'def': 'a circular frame with spokes (or a solid disc) that can rotate on a shaft or axle', 'synonyms': ['wheel'], 'image_count': 1924, 'id': 1178, 'frequency': 'f', 'synset': 'wheel.n.01'}, {'name': 'chair', 'instance_count': 11549, 'def': 'a seat for one person, with a support for the back', 'synonyms': ['chair'], 'image_count': 1927, 'id': 232, 'frequency': 'f', 'synset': 'chair.n.01'}, {'name': 'bird', 'instance_count': 11557, 'def': 'animal characterized by feathers and wings', 'synonyms': ['bird'], 'image_count': 1821, 'id': 99, 'frequency': 'f', 'synset': 'bird.n.01'}, {'name': 'doughnut', 'instance_count': 11911, 'def': 'a small ring-shaped friedcake', 'synonyms': ['doughnut', 'donut'], 'image_count': 1008, 'id': 387, 'frequency': 'f', 'synset': 'doughnut.n.02'}, {'name': 'broccoli', 'instance_count': 12166, 'def': 'plant with dense clusters of tight green flower buds', 'synonyms': ['broccoli'], 'image_count': 1309, 'id': 154, 'frequency': 'f', 'synset': 'broccoli.n.01'}, {'name': 'tomato', 'instance_count': 12338, 'def': 'mildly acid red or yellow pulpy fruit eaten as a vegetable', 'synonyms': ['tomato'], 'image_count': 1213, 'id': 1099, 'frequency': 'f', 'synset': 'tomato.n.01'}, {'name': 'orange_(fruit)', 'instance_count': 13034, 'def': 'orange (FRUIT of an orange tree)', 'synonyms': ['orange_(fruit)'], 'image_count': 824, 'id': 735, 'frequency': 'f', 'synset': 'orange.n.01'}, {'name': 'sheep', 'instance_count': 13304, 'def': 'woolly usually horned ruminant mammal related to the goat', 'synonyms': ['sheep'], 'image_count': 951, 'id': 943, 'frequency': 'f', 'synset': 'sheep.n.01'}, {'name': 'person', 'instance_count': 13439, 'def': 'a human being', 'synonyms': ['person', 'baby', 'child', 'boy', 'girl', 'man', 'woman', 'human'], 'image_count': 1928, 'id': 793, 'frequency': 'f', 'synset': 'person.n.01'}, {'name': 'pole', 'instance_count': 14276, 'def': 'a long (usually round) rod of wood or metal or plastic', 'synonyms': ['pole', 'post'], 'image_count': 1890, 'id': 827, 'frequency': 'f', 'synset': 'pole.n.01'}, {'name': 'apple', 'instance_count': 17451, 'def': 'fruit with red or yellow or green skin and sweet to tart crisp whitish flesh', 'synonyms': ['apple'], 'image_count': 1207, 'id': 12, 'frequency': 'f', 'synset': 'apple.n.01'}, {'name': 'carrot', 'instance_count': 18049, 'def': 'deep orange edible root of the cultivated carrot plant', 'synonyms': ['carrot'], 'image_count': 1222, 'id': 217, 'frequency': 'f', 'synset': 'carrot.n.01'}, {'name': 'book', 'instance_count': 33353, 'def': 'a written work or composition that has been published', 'synonyms': ['book'], 'image_count': 1903, 'id': 127, 'frequency': 'f', 'synset': 'book.n.01'}, {'name': 'banana', 'instance_count': 50552, 'def': 'elongated crescent-shaped yellow fruit with soft sweet flesh', 'synonyms': ['banana'], 'image_count': 1787, 'id': 45, 'frequency': 'f', 'synset': 'banana.n.02'}]  # noqa

LVIS_CLASS = ['lettuce', 'sunglasses', 'magnet', 'banner', 'glove', 'pillow', 'mushroom', 'grape', 'glass_(drink_container)', 'bread', 'toy', 'sock', 'crossbar', 'flag', 'lightbulb', 'cushion', 'hat', 'traffic_light', 'headlight', 'log', 'cabinet', 'streetlight', 'strap', 'tag', 'trousers', 'box', 'button', 'drawer', 'bottle', 'jacket', 'cow', 'signboard', 'jersey', 'ski_boot', 'ski_pole', 'handle', 'street_sign', 'knob', 'ski', 'suitcase', 'baseball_cap', 'umbrella', 'taillight', 'shoe', 'onion', 'boat', 'shirt', 'car_(automobile)', 'kite', 'bolt', 'wheel', 'chair', 'bird', 'doughnut', 'broccoli', 'tomato', 'orange_(fruit)', 'sheep', 'person', 'pole', 'apple', 'carrot', 'book', 'banana']  # noqa

COCO_SYNSET_CATEGORIES = [
    {"synset": "person.n.01", "coco_cat_id": 1},
    {"synset": "bicycle.n.01", "coco_cat_id": 2},
    {"synset": "car.n.01", "coco_cat_id": 3},
    {"synset": "motorcycle.n.01", "coco_cat_id": 4},
    {"synset": "airplane.n.01", "coco_cat_id": 5},
    {"synset": "bus.n.01", "coco_cat_id": 6},
    {"synset": "train.n.01", "coco_cat_id": 7},
    {"synset": "truck.n.01", "coco_cat_id": 8},
    {"synset": "boat.n.01", "coco_cat_id": 9},
    {"synset": "traffic_light.n.01", "coco_cat_id": 10},
    {"synset": "fireplug.n.01", "coco_cat_id": 11},
    {"synset": "stop_sign.n.01", "coco_cat_id": 13},
    {"synset": "parking_meter.n.01", "coco_cat_id": 14},
    {"synset": "bench.n.01", "coco_cat_id": 15},
    {"synset": "bird.n.01", "coco_cat_id": 16},
    {"synset": "cat.n.01", "coco_cat_id": 17},
    {"synset": "dog.n.01", "coco_cat_id": 18},
    {"synset": "horse.n.01", "coco_cat_id": 19},
    {"synset": "sheep.n.01", "coco_cat_id": 20},
    {"synset": "beef.n.01", "coco_cat_id": 21},
    {"synset": "elephant.n.01", "coco_cat_id": 22},
    {"synset": "bear.n.01", "coco_cat_id": 23},
    {"synset": "zebra.n.01", "coco_cat_id": 24},
    {"synset": "giraffe.n.01", "coco_cat_id": 25},
    {"synset": "backpack.n.01", "coco_cat_id": 27},
    {"synset": "umbrella.n.01", "coco_cat_id": 28},
    {"synset": "bag.n.04", "coco_cat_id": 31},
    {"synset": "necktie.n.01", "coco_cat_id": 32},
    {"synset": "bag.n.06", "coco_cat_id": 33},
    {"synset": "frisbee.n.01", "coco_cat_id": 34},
    {"synset": "ski.n.01", "coco_cat_id": 35},
    {"synset": "snowboard.n.01", "coco_cat_id": 36},
    {"synset": "ball.n.06", "coco_cat_id": 37},
    {"synset": "kite.n.03", "coco_cat_id": 38},
    {"synset": "baseball_bat.n.01", "coco_cat_id": 39},
    {"synset": "baseball_glove.n.01", "coco_cat_id": 40},
    {"synset": "skateboard.n.01", "coco_cat_id": 41},
    {"synset": "surfboard.n.01", "coco_cat_id": 42},
    {"synset": "tennis_racket.n.01", "coco_cat_id": 43},
    {"synset": "bottle.n.01", "coco_cat_id": 44},
    {"synset": "wineglass.n.01", "coco_cat_id": 46},
    {"synset": "cup.n.01", "coco_cat_id": 47},
    {"synset": "fork.n.01", "coco_cat_id": 48},
    {"synset": "knife.n.01", "coco_cat_id": 49},
    {"synset": "spoon.n.01", "coco_cat_id": 50},
    {"synset": "bowl.n.03", "coco_cat_id": 51},
    {"synset": "banana.n.02", "coco_cat_id": 52},
    {"synset": "apple.n.01", "coco_cat_id": 53},
    {"synset": "sandwich.n.01", "coco_cat_id": 54},
    {"synset": "orange.n.01", "coco_cat_id": 55},
    {"synset": "broccoli.n.01", "coco_cat_id": 56},
    {"synset": "carrot.n.01", "coco_cat_id": 57},
    {"synset": "frank.n.02", "coco_cat_id": 58},
    {"synset": "pizza.n.01", "coco_cat_id": 59},
    {"synset": "doughnut.n.02", "coco_cat_id": 60},
    {"synset": "cake.n.03", "coco_cat_id": 61},
    {"synset": "chair.n.01", "coco_cat_id": 62},
    {"synset": "sofa.n.01", "coco_cat_id": 63},
    {"synset": "pot.n.04", "coco_cat_id": 64},
    {"synset": "bed.n.01", "coco_cat_id": 65},
    {"synset": "dining_table.n.01", "coco_cat_id": 67},
    {"synset": "toilet.n.02", "coco_cat_id": 70},
    {"synset": "television_receiver.n.01", "coco_cat_id": 72},
    {"synset": "laptop.n.01", "coco_cat_id": 73},
    {"synset": "mouse.n.04", "coco_cat_id": 74},
    {"synset": "remote_control.n.01", "coco_cat_id": 75},
    {"synset": "computer_keyboard.n.01", "coco_cat_id": 76},
    {"synset": "cellular_telephone.n.01", "coco_cat_id": 77},
    {"synset": "microwave.n.02", "coco_cat_id": 78},
    {"synset": "oven.n.01", "coco_cat_id": 79},
    {"synset": "toaster.n.02", "coco_cat_id": 80},
    {"synset": "sink.n.01", "coco_cat_id": 81},
    {"synset": "electric_refrigerator.n.01", "coco_cat_id": 82},
    {"synset": "book.n.01", "coco_cat_id": 84},
    {"synset": "clock.n.01", "coco_cat_id": 85},
    {"synset": "vase.n.01", "coco_cat_id": 86},
    {"synset": "scissors.n.01", "coco_cat_id": 87},
    {"synset": "teddy.n.01", "coco_cat_id": 88},
    {"synset": "hand_blower.n.01", "coco_cat_id": 89},
    {"synset": "toothbrush.n.01", "coco_cat_id": 90},
]
# use COCO_SYNSET_CATEGORIES to build COCO_ID_SET FOR LVIS
# remove frank from the list because it is not in the COCO dataset
#COCO_ID_SET = set([x["coco_cat_id"] for x in COCO_SYNSET_CATEGORIES if x["synset"] != "frank.n.02"])
COCO_ID_SET = set([SYNSET2ID[x["synset"] ]for x in COCO_SYNSET_CATEGORIES if x["synset"] != "frank.n.02"])
IN_VOC_ID_SET = { NAME2ID[name] for name in LVIS_CLASS}
OUT_VOC_ID_SET = set(ID2NAME.keys()) - IN_VOC_ID_SET
IN_VOC_ID_SET = COCO_ID_SET | IN_VOC_ID_SET
OUT_VOC_ID_SET = OUT_VOC_ID_SET - IN_VOC_ID_SET
OUT_COCO_ID_SET = set(ID2NAME.keys()) - COCO_ID_SET
# ADD COCO_ID_SET TO LVIS_CLASS