Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- approach/ovod/APE/ape/data/datasets/__init__.pyAdded+19
- approach/ovod/APE/ape/data/datasets/coco.pyAdded+383
- approach/ovod/APE/ape/data/datasets/d_cube.pyAdded+275
- approach/ovod/APE/ape/data/datasets/flickr30k.pyAdded+68
- approach/ovod/APE/ape/data/datasets/gqa.pyAdded+60
- approach/ovod/APE/ape/data/datasets/grit.pyAdded+60
- approach/ovod/APE/ape/data/datasets/inst_categories.pyAdded+488
- approach/ovod/APE/ape/data/datasets/lvis_coco.pyAdded+284
- approach/ovod/APE/ape/data/datasets/lvis_coco_panoptic.pyAdded+192
- approach/ovod/APE/ape/data/datasets/lvis_v1_coco_category_image_count.pyAdded+20
- approach/ovod/APE/ape/data/datasets/objects365.pyAdded+799
- approach/ovod/APE/ape/data/datasets/odinw_categories.pyAdded+377
- approach/ovod/APE/ape/data/datasets/odinw_instance.pyAdded+824
- approach/ovod/APE/ape/data/datasets/odinw_prompts.pyAdded+75
- approach/ovod/APE/ape/data/datasets/oid.pyAdded+1573
- approach/ovod/APE/ape/data/datasets/openimages_v6_category_image_count.pyAdded+2
- approach/ovod/APE/ape/data/datasets/pascal_voc_external.pyAdded+1217
- approach/ovod/APE/ape/data/datasets/phrasecut.pyAdded+60
- approach/ovod/APE/ape/data/datasets/refcoco.pyAdded+337
- approach/ovod/APE/ape/data/datasets/register_bdd100k_panoseg.pyAdded+277
- approach/ovod/APE/ape/data/datasets/register_bdd100k_semseg.pyAdded+98
- approach/ovod/APE/ape/data/datasets/register_pascal_context.pyAdded+587
- approach/ovod/APE/ape/data/datasets/register_voc_seg.pyAdded+64
- approach/ovod/APE/ape/data/datasets/sa1b.pyAdded+44
- approach/ovod/APE/ape/data/datasets/seginw_categories.pyAdded+89
- approach/ovod/APE/ape/data/datasets/seginw_instance.pyAdded+142
- approach/ovod/APE/ape/data/datasets/visualgenome.pyAdded+220
- approach/ovod/APE/ape/data/datasets/visualgenome_categories.pyAdded
- approach/ovod/APE/ape/data/samplers/__init__.pyAdded+5
- approach/ovod/APE/ape/data/samplers/distributed_sampler_multi_dataset.pyAdded+137
- approach/ovod/APE/ape/data/transforms/__init__.pyAdded+5
- approach/ovod/APE/ape/data/transforms/augmentation_aa.pyAdded+39
- approach/ovod/APE/ape/data/transforms/augmentation_lsj.pyAdded+38
- approach/ovod/APE/ape/modeling/backbone/__init__.pyAdded
- approach/ovod/APE/ape/modeling/backbone/utils_eva.pyAdded+222
- approach/ovod/APE/ape/modeling/backbone/utils_eva02.pyAdded+347
- approach/ovod/APE/ape/modeling/backbone/vit.pyAdded+30
- approach/ovod/APE/ape/modeling/backbone/vit_eva.pyAdded+644
- approach/ovod/APE/ape/modeling/backbone/vit_eva02.pyAdded+625
- approach/ovod/APE/ape/modeling/backbone/vit_eva_clip.pyAdded+931
- approach/ovod/APE/ape/modeling/text/bert_wrapper.pyAdded+107
- approach/ovod/APE/ape/modeling/text/clip_wrapper.pyAdded+224
- approach/ovod/APE/ape/modeling/text/clip_wrapper_eva02.pyAdded+148
- approach/ovod/APE/ape/modeling/text/eva01_clip/README.mdAdded+79
- approach/ovod/APE/ape/modeling/text/eva01_clip/__init__.pyAdded+7
- approach/ovod/APE/ape/modeling/text/eva01_clip/clip.pyAdded+232
- approach/ovod/APE/ape/modeling/text/eva01_clip/eva_clip.pyAdded+173
- approach/ovod/APE/ape/modeling/text/eva01_clip/eva_model.pyAdded+368
- approach/ovod/APE/ape/modeling/text/eva01_clip/model.pyAdded+471
- approach/ovod/APE/ape/modeling/text/eva01_clip/model_configs/EVA_CLIP_g_14.jsonAdded+19
12345678910111213141516171819from . import d_cube as _d_cubefrom . import flickr30k as _flickr30kfrom . import gqa as _gqafrom . import grit as _gritfrom . import lvis_coco as _lvis_cocofrom . import lvis_coco_panoptic as _lvis_coco_panopticfrom . import objects365 as _objects365from . import odinw_instance as _odinw_instancefrom . import oid as _oidfrom . import pascal_voc_external as _pascal_voc_externalfrom . import phrasecut as _phrasecutfrom . import refcoco as _refcocofrom . import register_bdd100k_panoseg as _register_bdd100k_panosegfrom . import register_bdd100k_semseg as _register_bdd100k_semsegfrom . import register_pascal_context as _register_pascal_contextfrom . import register_voc_seg as _register_voc_segfrom . import sa1b as _sa1bfrom . import seginw_instance as _seginw_instancefrom . import visualgenome as _visualgenome123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383import contextlibimport ioimport loggingimport os
import pycocotools.mask as mask_util
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.structures import BoxModefrom detectron2.utils.file_io import PathManagerfrom fvcore.common.timer import Timer
"""This file contains functions to parse COCO-format annotations into dicts in "Detectron2 format"."""
logger = logging.getLogger(__name__)
__all__ = ["custom_load_coco_json", "custom_register_coco_instances"]
def custom_load_coco_json(json_file, image_root, dataset_name=None, extra_annotation_keys=None): """ Load a json file with COCO's instances annotation format. Currently supports instance detection, instance segmentation, and person keypoints annotations.
Args: json_file (str): full path to the json file in COCO instances annotation format. image_root (str or path-like): the directory where the images in this json file exists. dataset_name (str or None): the name of the dataset (e.g., coco_2017_train). When provided, this function will also do the following:
* Put "thing_classes" into the metadata associated with this dataset. * Map the category ids into a contiguous range (needed by standard dataset format), and add "thing_dataset_id_to_contiguous_id" to the metadata associated with this dataset.
This option should usually be provided, unless users need to load the original json content and apply more processing manually. extra_annotation_keys (list[str]): list of per-annotation keys that should also be loaded into the dataset dict (besides "iscrowd", "bbox", "keypoints", "category_id", "segmentation"). The values for these keys will be returned as-is. For example, the densepose annotations are loaded in this way.
Returns: list[dict]: a list of dicts in Detectron2 standard dataset dicts format (See `Using Custom Datasets </tutorials/datasets.html>`_ ) when `dataset_name` is not None. If `dataset_name` is None, the returned `category_ids` may be incontiguous and may not conform to the Detectron2 standard format.
Notes: 1. This function does not read the image files. The results do not have the "image" field. """ from pycocotools.coco import COCO
timer = Timer() json_file = PathManager.get_local_path(json_file) with contextlib.redirect_stdout(io.StringIO()): coco_api = COCO(json_file) if timer.seconds() > 1: logger.info("Loading {} takes {:.2f} seconds.".format(json_file, timer.seconds()))
id_map = None if dataset_name is not None: meta = MetadataCatalog.get(dataset_name) cat_ids = sorted(coco_api.getCatIds()) cats = coco_api.loadCats(cat_ids) # The categories in a custom json file may not be sorted. thing_classes = [c["name"] for c in sorted(cats, key=lambda x: x["id"])] meta.thing_classes = thing_classes
# In COCO, certain category ids are artificially removed, # and by convention they are always ignored. # We deal with COCO's id issue and translate # the category ids to contiguous ids in [0, 80).
# It works by looking at the "categories" field in the json, therefore # if users' own json also have incontiguous ids, we'll # apply this mapping as well but print a warning. if not (min(cat_ids) == 1 and max(cat_ids) == len(cat_ids)): if "coco" not in dataset_name: logger.warning( """Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.""" ) id_map = {v: i for i, v in enumerate(cat_ids)} meta.thing_dataset_id_to_contiguous_id = id_map
cat_ids = cat_ids + list(range(max(cat_ids) + 1, 100000)) id_map = {v: i for i, v in enumerate(cat_ids)}
# sort indices for reproducible results img_ids = sorted(coco_api.imgs.keys()) # imgs is a list of dicts, each looks something like: # {'license': 4, # 'url': 'http://farm6.staticflickr.com/5454/9413846304_881d5e5c3b_z.jpg', # 'file_name': 'COCO_val2014_000000001268.jpg', # 'height': 427, # 'width': 640, # 'date_captured': '2013-11-17 05:57:24', # 'id': 1268} imgs = coco_api.loadImgs(img_ids) # anns is a list[list[dict]], where each dict is an annotation # record for an object. The inner list enumerates the objects in an image # and the outer list enumerates over images. Example of anns[0]: # [{'segmentation': [[192.81, # 247.09, # ... # 219.03, # 249.06]], # 'area': 1035.749, # 'iscrowd': 0, # 'image_id': 1268, # 'bbox': [192.81, 224.8, 74.73, 33.43], # 'category_id': 16, # 'id': 42986}, # ...] anns = [coco_api.imgToAnns[img_id] for img_id in img_ids] total_num_valid_anns = sum([len(x) for x in anns]) total_num_anns = len(coco_api.anns) if total_num_valid_anns < total_num_anns: logger.warning( f"{json_file} contains {total_num_anns} annotations, but only " f"{total_num_valid_anns} of them match to images in the file." )
if "minival" not in json_file: # The popular valminusminival & minival annotations for COCO2014 contain this bug. # However the ratio of buggy annotations there is tiny and does not affect accuracy. # Therefore we explicitly white-list them. ann_ids = [ann["id"] for anns_per_image in anns for ann in anns_per_image] assert len(set(ann_ids)) == len(ann_ids), "Annotation ids in '{}' are not unique!".format( json_file )
imgs_anns = list(zip(imgs, anns)) logger.info("Loaded {} images in COCO format from {}".format(len(imgs_anns), json_file))
dataset_dicts = []
ann_keys = ["iscrowd", "bbox", "keypoints", "category_id"] + (extra_annotation_keys or [])
ann_keys += ["phrase", "isobject"]
num_instances_without_valid_segmentation = 0
for (img_dict, anno_dict_list) in imgs_anns: record = {} record["file_name"] = os.path.join(image_root, img_dict["file_name"]) record["height"] = img_dict["height"] record["width"] = img_dict["width"] image_id = record["image_id"] = img_dict["id"] if "neg_category_ids" in img_dict: record["neg_category_ids"] = [id_map[x] for x in img_dict["neg_category_ids"]]
objs = [] for anno in anno_dict_list: # Check that the image_id in this annotation is the same as # the image_id we're looking at. # This fails only when the data parsing logic or the annotation file is buggy.
# The original COCO valminusminival2014 & minival2014 annotation files # actually contains bugs that, together with certain ways of using COCO API, # can trigger this assertion. assert anno["image_id"] == image_id
assert anno.get("ignore", 0) == 0, '"ignore" in COCO json file is not supported.'
obj = {key: anno[key] for key in ann_keys if key in anno} if "bbox" in obj and len(obj["bbox"]) == 0: raise ValueError( f"One annotation of image {image_id} contains empty 'bbox' value! " "This json does not have valid COCO format." )
segm = anno.get("segmentation", None) if segm: # either list[list[float]] or dict(RLE) if isinstance(segm, dict): if isinstance(segm["counts"], list): # convert to compressed RLE segm = mask_util.frPyObjects(segm, *segm["size"]) else: # filter out invalid polygons (< 3 points) segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] if len(segm) == 0: num_instances_without_valid_segmentation += 1 continue # ignore this instance obj["segmentation"] = segm
keypts = anno.get("keypoints", None) if keypts: # list[int] for idx, v in enumerate(keypts): if idx % 3 != 2: # COCO's segmentation coordinates are floating points in [0, H or W], # but keypoint coordinates are integers in [0, H-1 or W-1] # Therefore we assume the coordinates are "pixel indices" and # add 0.5 to convert to floating point coordinates. keypts[idx] = v + 0.5 obj["keypoints"] = keypts
# phrase = anno.get("phrase", None) # if phrase: # obj["phrase"] = phrase
# isobject = anno.get("isobject", None) # if isobject: # obj["isobject"] = isobject
obj["bbox_mode"] = BoxMode.XYWH_ABS if id_map: annotation_category_id = obj["category_id"] try: obj["category_id"] = id_map[annotation_category_id] except KeyError as e: raise KeyError( f"Encountered category_id={annotation_category_id} " "but this id does not exist in 'categories' of the json file." ) from e objs.append(obj) record["annotations"] = objs dataset_dicts.append(record)
if num_instances_without_valid_segmentation > 0: logger.warning( "Filtered out {} instances without valid segmentation. ".format( num_instances_without_valid_segmentation ) + "There might be issues in your dataset generation process. Please " "check https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html carefully" ) return dataset_dicts
def custom_load_sem_seg(gt_root, image_root, gt_ext="png", image_ext="jpg"): """ Load semantic segmentation datasets. All files under "gt_root" with "gt_ext" extension are treated as ground truth annotations and all files under "image_root" with "image_ext" extension as input images. Ground truth and input images are matched using file paths relative to "gt_root" and "image_root" respectively without taking into account file extensions. This works for COCO as well as some other datasets.
Args: gt_root (str): full path to ground truth semantic segmentation files. Semantic segmentation annotations are stored as images with integer values in pixels that represent corresponding semantic labels. image_root (str): the directory where the input images are. gt_ext (str): file extension for ground truth annotations. image_ext (str): file extension for input images.
Returns: list[dict]: a list of dicts in detectron2 standard format without instance-level annotation.
Notes: 1. This function does not read the image and ground truth files. The results do not have the "image" and "sem_seg" fields. """
# We match input images with ground truth based on their relative filepaths (without file # extensions) starting from 'image_root' and 'gt_root' respectively. def file2id(folder_path, file_path): # extract relative path starting from `folder_path` image_id = os.path.normpath(os.path.relpath(file_path, start=folder_path)) # remove file extension image_id = os.path.splitext(image_id)[0] return image_id
input_files = sorted( (os.path.join(image_root, f) for f in PathManager.ls(image_root) if f.endswith(image_ext)), key=lambda file_path: file2id(image_root, file_path), ) gt_files = sorted( (os.path.join(gt_root, f) for f in PathManager.ls(gt_root) if f.endswith(gt_ext)), key=lambda file_path: file2id(gt_root, file_path), )
assert len(gt_files) > 0, "No annotations found in {}.".format(gt_root)
# Use the intersection, so that val2017_100 annotations can run smoothly with val2017 images if len(input_files) != len(gt_files): logger.warn( "Directory {} and {} has {} and {} files, respectively.".format( image_root, gt_root, len(input_files), len(gt_files) ) ) input_basenames = [os.path.basename(f)[: -len(image_ext)] for f in input_files] gt_basenames = [os.path.basename(f)[: -len(gt_ext)] for f in gt_files] intersect = list(set(input_basenames) & set(gt_basenames)) # sort, otherwise each worker may obtain a list[dict] in different order intersect = sorted(intersect) logger.warn("Will use their intersection of {} files.".format(len(intersect))) input_files = [os.path.join(image_root, f + image_ext) for f in intersect] gt_files = [os.path.join(gt_root, f + gt_ext) for f in intersect]
logger.info( "Loaded {} images with semantic segmentation from {}".format(len(input_files), image_root) )
dataset_dicts = [] for (img_path, gt_path) in zip(input_files, gt_files): record = {} record["file_name"] = img_path record["sem_seg_file_name"] = gt_path dataset_dicts.append(record)
return dataset_dicts
def custom_load_sem_seg_list(gt_root, image_root, gt_ext="png", image_ext="jpg"): if isinstance(image_root, list): image_roots = image_root else: image_roots = [image_root] if isinstance(gt_root, list): gt_roots = gt_root else: gt_roots = [gt_root]
dataset_dicts = [] for gt_root, image_root in zip(gt_roots, image_roots): dataset_dicts.extend(custom_load_sem_seg(gt_root, image_root, gt_ext, image_ext))
if len(image_roots) > 1: logger.info( "Loaded {} images with semantic segmentation from {}".format( len(dataset_dicts), image_roots ) )
return dataset_dicts
def custom_register_coco_instances(name, metadata, json_file, image_root): """ Register a dataset in COCO's json annotation format for instance detection, instance segmentation and keypoint detection. (i.e., Type 1 and 2 in http://cocodataset.org/#format-data. `instances*.json` and `person_keypoints*.json` in the dataset).
This is an example of how to register a new dataset. You can do something similar to this function, to register new datasets.
Args: name (str): the name that identifies a dataset, e.g. "coco_2014_train". metadata (dict): extra metadata associated with this dataset. You can leave it as an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ assert isinstance(name, str), name assert isinstance(json_file, (str, os.PathLike)), json_file assert isinstance(image_root, (str, os.PathLike)), image_root # 1. register a function which returns dicts DatasetCatalog.register(name, lambda: custom_load_coco_json(json_file, image_root, name))
# 2. Optionally, add metadata about this dataset, # since they might be useful in evaluation, visualization or logging MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="coco", **metadata )
def custom_register_coco_semseg(name, metadata, sem_seg_root, image_root): assert isinstance(name, str), name assert isinstance(sem_seg_root, (str, os.PathLike, list)), sem_seg_root assert isinstance(image_root, (str, os.PathLike, list)), image_root # 1. register a function which returns dicts DatasetCatalog.register(name, lambda: custom_load_sem_seg_list(sem_seg_root, image_root))
# 2. Optionally, add metadata about this dataset, # since they might be useful in evaluation, visualization or logging MetadataCatalog.get(name).set( sem_seg_root=sem_seg_root, image_root=image_root, evaluator_type="sem_seg", ignore_label=255, **metadata, )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275import loggingimport os
import pycocotools.mask as mask_util
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets.builtin_meta import _get_coco_instances_metafrom detectron2.data.datasets.lvis_v0_5_categories import LVIS_CATEGORIES as LVIS_V0_5_CATEGORIESfrom detectron2.data.datasets.lvis_v1_categories import LVIS_CATEGORIES as LVIS_V1_CATEGORIESfrom detectron2.structures import BoxModefrom detectron2.utils.file_io import PathManagerfrom fvcore.common.timer import Timer
from .lvis_v1_coco_category_image_count import LVIS_V1_COCO_CATEGORY_IMAGE_COUNT
"""This file contains functions to parse LVIS-format annotations into dicts in the"Detectron2 format"."""
logger = logging.getLogger(__name__)
__all__ = ["load_d3_json", "register_d3_instances"]
def register_d3_instances(name, metadata, json_file, image_root, anno_root): """ Register a dataset in LVIS's json annotation format for instance detection and segmentation.
Args: name (str): a name that identifies the dataset, e.g. "lvis_v0.5_train". metadata (dict): extra metadata associated with this dataset. It can be an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ DatasetCatalog.register(name, lambda: load_d3_json(json_file, image_root, anno_root, name)) MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="d3", **metadata )
def load_d3_json(json_file, image_root, anno_root, dataset_name=None, extra_annotation_keys=None): """ Load a json file in LVIS's annotation format.
Args: json_file (str): full path to the LVIS json annotation file. image_root (str): the directory where the images in this json file exists. dataset_name (str): the name of the dataset (e.g., "lvis_v0.5_train"). If provided, this function will put "thing_classes" into the metadata associated with this dataset. extra_annotation_keys (list[str]): list of per-annotation keys that should also be loaded into the dataset dict (besides "bbox", "bbox_mode", "category_id", "segmentation"). The values for these keys will be returned as-is.
Returns: list[dict]: a list of dicts in Detectron2 standard format. (See `Using Custom Datasets </tutorials/datasets.html>`_ )
Notes: 1. This function does not read the image files. The results do not have the "image" field. """ from d_cube import D3
timer = Timer()
d3 = D3(image_root, anno_root)
if timer.seconds() > 1: logger.info("Loading d3 takes {:.2f} seconds.".format(timer.seconds()))
id_map = None if dataset_name is not None: meta = MetadataCatalog.get(dataset_name) cat_ids = sorted(d3.get_sent_ids()) cats = d3.load_sents(cat_ids) # The categories in a custom json file may not be sorted. thing_classes = [c["raw_sent"] for c in sorted(cats, key=lambda x: x["id"])] meta.thing_classes = thing_classes
# In COCO, certain category ids are artificially removed, # and by convention they are always ignored. # We deal with COCO's id issue and translate # the category ids to contiguous ids in [0, 80).
# It works by looking at the "categories" field in the json, therefore # if users' own json also have incontiguous ids, we'll # apply this mapping as well but print a warning. if not (min(cat_ids) == 1 and max(cat_ids) == len(cat_ids)): if "coco" not in dataset_name: logger.warning( """Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.""" ) id_map = {v: i for i, v in enumerate(cat_ids)} meta.thing_dataset_id_to_contiguous_id = id_map
img_ids = d3.get_img_ids() imgs = d3.load_imgs(img_ids) anno_ids = [d3.get_anno_ids(img_ids=img_id) for img_id in img_ids] anns = [d3.load_annos(anno_ids=anno_id) for anno_id in anno_ids] total_num_valid_anns = sum([len(x) for x in anns]) total_num_anns = len(d3.load_annos()) if total_num_valid_anns < total_num_anns: logger.warning( f"{anno_root} contains {total_num_anns} annotations, but only " f"{total_num_valid_anns} of them match to images in the file." )
imgs_anns = list(zip(imgs, anns)) logger.info("Loaded {} images in COCO format from {}".format(len(imgs_anns), json_file))
dataset_dicts = []
ann_keys = ["iscrowd", "bbox", "keypoints", "sent_id"] + (extra_annotation_keys or [])
num_instances_without_valid_segmentation = 0
for (img_dict, anno_dict_list) in imgs_anns: record = {} record["file_name"] = os.path.join(image_root, img_dict["file_name"]) record["height"] = img_dict["height"] record["width"] = img_dict["width"] image_id = record["image_id"] = img_dict["id"]
if meta.group == "intra": group_ids = d3.get_group_ids(img_ids=[image_id]) sent_ids = d3.get_sent_ids(group_ids=group_ids) sent_list = d3.load_sents(sent_ids=sent_ids) # assert len(anno_dict_list) == len(sent_ids) elif meta.group == "inter": sent_ids = d3.get_sent_ids() sent_list = d3.load_sents(sent_ids=sent_ids) # sent_list = d3.load_sents() else: assert False ref_list = [sent["raw_sent"] for sent in sent_list] record["expressions"] = ref_list if id_map: record["sent_ids"] = [id_map[x] for x in sent_ids]
objs = [] for anno in anno_dict_list: # Check that the image_id in this annotation is the same as # the image_id we're looking at. # This fails only when the data parsing logic or the annotation file is buggy.
# The original COCO valminusminival2014 & minival2014 annotation files # actually contains bugs that, together with certain ways of using COCO API, # can trigger this assertion. assert anno["image_id"] == image_id
assert anno.get("ignore", 0) == 0, '"ignore" in COCO json file is not supported.'
obj = {key: anno[key] for key in ann_keys if key in anno} if "bbox" in obj and len(obj["bbox"]) == 0: raise ValueError( f"One annotation of image {image_id} contains empty 'bbox' value! " "This json does not have valid COCO format." )
assert len(obj["bbox"]) == 1 obj["bbox"] = list(obj["bbox"][0]) # assert len(obj["sent_id"]) == 1 obj["sent_id"] = obj["sent_id"][0]
segm = anno.get("segmentation", None) assert len(segm) == 1 segm = segm[0] if segm: # either list[list[float]] or dict(RLE) if isinstance(segm, dict): if isinstance(segm["counts"], list): # convert to compressed RLE segm = mask_util.frPyObjects(segm, *segm["size"]) else: # filter out invalid polygons (< 3 points) segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] if len(segm) == 0: num_instances_without_valid_segmentation += 1 continue # ignore this instance obj["segmentation"] = segm
keypts = anno.get("keypoints", None) if keypts: # list[int] for idx, v in enumerate(keypts): if idx % 3 != 2: # COCO's segmentation coordinates are floating points in [0, H or W], # but keypoint coordinates are integers in [0, H-1 or W-1] # Therefore we assume the coordinates are "pixel indices" and # add 0.5 to convert to floating point coordinates. keypts[idx] = v + 0.5 obj["keypoints"] = keypts
obj["bbox_mode"] = BoxMode.XYWH_ABS if id_map: annotation_category_id = obj["sent_id"] try: obj["sent_id"] = id_map[annotation_category_id] except KeyError as e: raise KeyError( f"Encountered sent_id={annotation_category_id} " "but this id does not exist in 'categories' of the json file." ) from e obj["category_id"] = obj["sent_id"] obj["iscrowd"] = 0 objs.append(obj) record["annotations"] = objs dataset_dicts.append(record)
if num_instances_without_valid_segmentation > 0: logger.warning( "Filtered out {} instances without valid segmentation. ".format( num_instances_without_valid_segmentation ) + "There might be issues in your dataset generation process. Please " "check https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html carefully" ) return dataset_dicts
def get_d3_instances_meta(dataset_name): if "intra_scenario" in dataset_name: group = "intra" elif "inter_scenario" in dataset_name: group = "inter" else: assert False return {"group": group}
_PREDEFINED_SPLITS_D3 = { "d3_inter_scenario": { "d3_inter_scenario": ( "D3/d3_images/", { "FULL": "D3/d3_json/d3_full_annotations.json", "PRES": "D3/d3_json/d3_pres_annotations.json", "ABS": "D3/d3_json/d3_abs_annotations.json", }, "D3/d3_pkl/", ), }, "d3_intra_scenario": { "d3_intra_scenario": ( "D3/d3_images/", { "FULL": "D3/d3_json/d3_full_annotations.json", "PRES": "D3/d3_json/d3_pres_annotations.json", "ABS": "D3/d3_json/d3_abs_annotations.json", }, "D3/d3_pkl/", ), },}
def register_all_D3(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_D3.items(): for key, (image_root, json_file, anno_root) in splits_per_dataset.items(): register_d3_instances( key, get_d3_instances_meta(dataset_name), # os.path.join(root, json_file) if "://" not in json_file else json_file, {k: os.path.join(root, v) for k, v in json_file.items()}, os.path.join(root, image_root), os.path.join(root, anno_root), )
if __name__.endswith(".d_cube"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_D3(_root)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import loggingimport os
from .coco import custom_register_coco_instances
logger = logging.getLogger(__name__)
def _get_builtin_metadata(dataset_name): return _get_flickr30k_metadata([])
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_flickr30k_metadata(categories): if len(categories) == 0: return {} id_to_name = {x["id"]: x["name"] for x in categories} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(categories))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_FLICKR30k = {}_PREDEFINED_SPLITS_FLICKR30k["flickr30k"] = { "flickr30k": ( "flickr30k/flickr30k-images", "flickr30k/flickr30k.json", ), "flickr30k_separateGT_train": ( "flickr30k/flickr30k-images", "flickr30k/flickr30k_separateGT_train.json", ), "flickr30k_separateGT_val": ( "flickr30k/flickr30k-images", "flickr30k/flickr30k_separateGT_val.json", ), "flickr30k_mergedGT_train": ( "flickr30k/flickr30k-images", "flickr30k/flickr30k_mergedGT_train.json", ), "flickr30k_mergedGT_val": ( "flickr30k/flickr30k-images", "flickr30k/flickr30k_mergedGT_val.json", ),}
def register_all_flickr30k(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_FLICKR30k.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
# True for open source;# Internally at fb, we register them elsewhereif __name__.endswith(".flickr30k"): # Assume pre-defined datasets live in `./datasets`. _root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets")) register_all_flickr30k(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import loggingimport os
from .coco import custom_register_coco_instances
logger = logging.getLogger(__name__)
def _get_builtin_metadata(dataset_name): return _get_gqa_metadata([])
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_gqa_metadata(categories): if len(categories) == 0: return {} id_to_name = {x["id"]: x["name"] for x in categories} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(categories))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_GQA = {}_PREDEFINED_SPLITS_GQA["gqa_region"] = { "gqa_region": ( "gqa/images", "gqa/gqa_region.json", ), "gqa_region_train": ( "gqa/images", "gqa/gqa_region_train.json", ), "gqa_region_val": ( "gqa/images", "gqa/gqa_region_val.json", ),}
def register_all_gqa(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_GQA.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
# True for open source;# Internally at fb, we register them elsewhereif __name__.endswith(".gqa"): # Assume pre-defined datasets live in `./datasets`. _root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets")) register_all_gqa(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import os
from .coco import custom_register_coco_instances
GRIT_CATEGORIES = [ {"id": 0, "name": "object"},]
def _get_builtin_metadata(dataset_name): id_to_name = {x["id"]: x["name"] for x in GRIT_CATEGORIES} thing_dataset_id_to_contiguous_id = {i: i for i in range(len(GRIT_CATEGORIES))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_GRIT = { "grit": ("GRIT/images", "GRIT/grit.json"), "grit_0_snappy": ("GRIT/images", "GRIT/grit_0_snappy.json"), "grit_1_snappy": ("GRIT/images", "GRIT/grit_1_snappy.json"), "grit_2_snappy": ("GRIT/images", "GRIT/grit_2_snappy.json"), "grit_3_snappy": ("GRIT/images", "GRIT/grit_3_snappy.json"), "grit_4_snappy": ("GRIT/images", "GRIT/grit_4_snappy.json"), "grit_5_snappy": ("GRIT/images", "GRIT/grit_5_snappy.json"), "grit_6_snappy": ("GRIT/images", "GRIT/grit_6_snappy.json"), "grit_7_snappy": ("GRIT/images", "GRIT/grit_7_snappy.json"), "grit_8_snappy": ("GRIT/images", "GRIT/grit_8_snappy.json"), "grit_9_snappy": ("GRIT/images", "GRIT/grit_9_snappy.json"), "grit_10_snappy": ("GRIT/images", "GRIT/grit_10_snappy.json"), "grit_11_snappy": ("GRIT/images", "GRIT/grit_11_snappy.json"), "grit_12_snappy": ("GRIT/images", "GRIT/grit_12_snappy.json"), "grit_13_snappy": ("GRIT/images", "GRIT/grit_13_snappy.json"), "grit_14_snappy": ("GRIT/images", "GRIT/grit_14_snappy.json"), "grit_15_snappy": ("GRIT/images", "GRIT/grit_15_snappy.json"), "grit_16_snappy": ("GRIT/images", "GRIT/grit_16_snappy.json"), "grit_17_snappy": ("GRIT/images", "GRIT/grit_17_snappy.json"), "grit_18_snappy": ("GRIT/images", "GRIT/grit_18_snappy.json"), "grit_19_snappy": ("GRIT/images", "GRIT/grit_19_snappy.json"), "grit_20_snappy": ("GRIT/images", "GRIT/grit_20_snappy.json"), "grit_21_snappy": ("GRIT/images", "GRIT/grit_21_snappy.json"),}
def register_all_GRIT(root): for key, (image_root, json_file) in _PREDEFINED_SPLITS_GRIT.items(): custom_register_coco_instances( key, _get_builtin_metadata(key), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".grit"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_GRIT(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488categories = { "coco": [ {"color": [220, 20, 60], "isthing": 1, "id": 1, "name": "person"}, {"color": [119, 11, 32], "isthing": 1, "id": 2, "name": "bicycle"}, {"color": [0, 0, 142], "isthing": 1, "id": 3, "name": "car"}, {"color": [0, 0, 230], "isthing": 1, "id": 4, "name": "motorcycle"}, {"color": [106, 0, 228], "isthing": 1, "id": 5, "name": "airplane"}, {"color": [0, 60, 100], "isthing": 1, "id": 6, "name": "bus"}, {"color": [0, 80, 100], "isthing": 1, "id": 7, "name": "train"}, {"color": [0, 0, 70], "isthing": 1, "id": 8, "name": "truck"}, {"color": [0, 0, 192], "isthing": 1, "id": 9, "name": "boat"}, {"color": [250, 170, 30], "isthing": 1, "id": 10, "name": "traffic light"}, {"color": [100, 170, 30], "isthing": 1, "id": 11, "name": "fire hydrant"}, {"color": [220, 220, 0], "isthing": 1, "id": 13, "name": "stop sign"}, {"color": [175, 116, 175], "isthing": 1, "id": 14, "name": "parking meter"}, {"color": [250, 0, 30], "isthing": 1, "id": 15, "name": "bench"}, {"color": [165, 42, 42], "isthing": 1, "id": 16, "name": "bird"}, {"color": [255, 77, 255], "isthing": 1, "id": 17, "name": "cat"}, {"color": [0, 226, 252], "isthing": 1, "id": 18, "name": "dog"}, {"color": [182, 182, 255], "isthing": 1, "id": 19, "name": "horse"}, {"color": [0, 82, 0], "isthing": 1, "id": 20, "name": "sheep"}, {"color": [120, 166, 157], "isthing": 1, "id": 21, "name": "cow"}, {"color": [110, 76, 0], "isthing": 1, "id": 22, "name": "elephant"}, {"color": [174, 57, 255], "isthing": 1, "id": 23, "name": "bear"}, {"color": [199, 100, 0], "isthing": 1, "id": 24, "name": "zebra"}, {"color": [72, 0, 118], "isthing": 1, "id": 25, "name": "giraffe"}, {"color": [255, 179, 240], "isthing": 1, "id": 27, "name": "backpack"}, {"color": [0, 125, 92], "isthing": 1, "id": 28, "name": "umbrella"}, {"color": [209, 0, 151], "isthing": 1, "id": 31, "name": "handbag"}, {"color": [188, 208, 182], "isthing": 1, "id": 32, "name": "tie"}, {"color": [0, 220, 176], "isthing": 1, "id": 33, "name": "suitcase"}, {"color": [255, 99, 164], "isthing": 1, "id": 34, "name": "frisbee"}, {"color": [92, 0, 73], "isthing": 1, "id": 35, "name": "skis"}, {"color": [133, 129, 255], "isthing": 1, "id": 36, "name": "snowboard"}, {"color": [78, 180, 255], "isthing": 1, "id": 37, "name": "sports ball"}, {"color": [0, 228, 0], "isthing": 1, "id": 38, "name": "kite"}, {"color": [174, 255, 243], "isthing": 1, "id": 39, "name": "baseball bat"}, {"color": [45, 89, 255], "isthing": 1, "id": 40, "name": "baseball glove"}, {"color": [134, 134, 103], "isthing": 1, "id": 41, "name": "skateboard"}, {"color": [145, 148, 174], "isthing": 1, "id": 42, "name": "surfboard"}, {"color": [255, 208, 186], "isthing": 1, "id": 43, "name": "tennis racket"}, {"color": [197, 226, 255], "isthing": 1, "id": 44, "name": "bottle"}, {"color": [171, 134, 1], "isthing": 1, "id": 46, "name": "wine glass"}, {"color": [109, 63, 54], "isthing": 1, "id": 47, "name": "cup"}, {"color": [207, 138, 255], "isthing": 1, "id": 48, "name": "fork"}, {"color": [151, 0, 95], "isthing": 1, "id": 49, "name": "knife"}, {"color": [9, 80, 61], "isthing": 1, "id": 50, "name": "spoon"}, {"color": [84, 105, 51], "isthing": 1, "id": 51, "name": "bowl"}, {"color": [74, 65, 105], "isthing": 1, "id": 52, "name": "banana"}, {"color": [166, 196, 102], "isthing": 1, "id": 53, "name": "apple"}, {"color": [208, 195, 210], "isthing": 1, "id": 54, "name": "sandwich"}, {"color": [255, 109, 65], "isthing": 1, "id": 55, "name": "orange"}, {"color": [0, 143, 149], "isthing": 1, "id": 56, "name": "broccoli"}, {"color": [179, 0, 194], "isthing": 1, "id": 57, "name": "carrot"}, {"color": [209, 99, 106], "isthing": 1, "id": 58, "name": "hot dog"}, {"color": [5, 121, 0], "isthing": 1, "id": 59, "name": "pizza"}, {"color": [227, 255, 205], "isthing": 1, "id": 60, "name": "donut"}, {"color": [147, 186, 208], "isthing": 1, "id": 61, "name": "cake"}, {"color": [153, 69, 1], "isthing": 1, "id": 62, "name": "chair"}, {"color": [3, 95, 161], "isthing": 1, "id": 63, "name": "couch"}, {"color": [163, 255, 0], "isthing": 1, "id": 64, "name": "potted plant"}, {"color": [119, 0, 170], "isthing": 1, "id": 65, "name": "bed"}, {"color": [0, 182, 199], "isthing": 1, "id": 67, "name": "dining table"}, {"color": [0, 165, 120], "isthing": 1, "id": 70, "name": "toilet"}, {"color": [183, 130, 88], "isthing": 1, "id": 72, "name": "tv"}, {"color": [95, 32, 0], "isthing": 1, "id": 73, "name": "laptop"}, {"color": [130, 114, 135], "isthing": 1, "id": 74, "name": "mouse"}, {"color": [110, 129, 133], "isthing": 1, "id": 75, "name": "remote"}, {"color": [166, 74, 118], "isthing": 1, "id": 76, "name": "keyboard"}, {"color": [219, 142, 185], "isthing": 1, "id": 77, "name": "cell phone"}, {"color": [79, 210, 114], "isthing": 1, "id": 78, "name": "microwave"}, {"color": [178, 90, 62], "isthing": 1, "id": 79, "name": "oven"}, {"color": [65, 70, 15], "isthing": 1, "id": 80, "name": "toaster"}, {"color": [127, 167, 115], "isthing": 1, "id": 81, "name": "sink"}, {"color": [59, 105, 106], "isthing": 1, "id": 82, "name": "refrigerator"}, {"color": [142, 108, 45], "isthing": 1, "id": 84, "name": "book"}, {"color": [196, 172, 0], "isthing": 1, "id": 85, "name": "clock"}, {"color": [95, 54, 80], "isthing": 1, "id": 86, "name": "vase"}, {"color": [128, 76, 255], "isthing": 1, "id": 87, "name": "scissors"}, {"color": [201, 57, 1], "isthing": 1, "id": 88, "name": "teddy bear"}, {"color": [246, 0, 122], "isthing": 1, "id": 89, "name": "hair drier"}, {"color": [191, 162, 208], "isthing": 1, "id": 90, "name": "toothbrush"}, ], "cityscapes": [ {"id": i + 1, "name": x} for i, x in enumerate( ["person", "rider", "car", "truck", "bus", "train", "motorcycle", "bicycle"] ) ], "mapillary": [ {"id": 1, "name": "animal--bird"}, {"id": 2, "name": "animal--ground-animal"}, {"id": 9, "name": "construction--flat--crosswalk-plain"}, {"id": 20, "name": "human--person"}, {"id": 21, "name": "human--rider--bicyclist"}, {"id": 22, "name": "human--rider--motorcyclist"}, {"id": 23, "name": "human--rider--other-rider"}, {"id": 24, "name": "marking--crosswalk-zebra"}, {"id": 33, "name": "object--banner"}, {"id": 34, "name": "object--bench"}, {"id": 35, "name": "object--bike-rack"}, {"id": 36, "name": "object--billboard"}, {"id": 37, "name": "object--catch-basin"}, {"id": 38, "name": "object--cctv-camera"}, {"id": 39, "name": "object--fire-hydrant"}, {"id": 40, "name": "object--junction-box"}, {"id": 41, "name": "object--mailbox"}, {"id": 42, "name": "object--manhole"}, {"id": 43, "name": "object--phone-booth"}, {"id": 45, "name": "object--street-light"}, {"id": 46, "name": "object--support--pole"}, {"id": 47, "name": "object--support--traffic-sign-frame"}, {"id": 48, "name": "object--support--utility-pole"}, {"id": 49, "name": "object--traffic-light"}, {"id": 50, "name": "object--traffic-sign--back"}, {"id": 51, "name": "object--traffic-sign--front"}, {"id": 52, "name": "object--trash-can"}, {"id": 53, "name": "object--vehicle--bicycle"}, {"id": 54, "name": "object--vehicle--boat"}, {"id": 55, "name": "object--vehicle--bus"}, {"id": 56, "name": "object--vehicle--car"}, {"id": 57, "name": "object--vehicle--caravan"}, {"id": 58, "name": "object--vehicle--motorcycle"}, {"id": 60, "name": "object--vehicle--other-vehicle"}, {"id": 61, "name": "object--vehicle--trailer"}, {"id": 62, "name": "object--vehicle--truck"}, {"id": 63, "name": "object--vehicle--wheeled-slow"}, ], "viper": [ {"id": 13, "name": "trafficlight", "supercategory": ""}, {"id": 16, "name": "firehydrant", "supercategory": ""}, {"id": 17, "name": "chair", "supercategory": ""}, {"id": 19, "name": "trashcan", "supercategory": ""}, {"id": 20, "name": "person", "supercategory": ""}, {"id": 23, "name": "motorcycle", "supercategory": ""}, {"id": 24, "name": "car", "supercategory": ""}, {"id": 25, "name": "van", "supercategory": ""}, {"id": 26, "name": "bus", "supercategory": ""}, {"id": 27, "name": "truck", "supercategory": ""}, ], "scannet": [ {"id": 3, "name": "cabinet", "supercategory": "furniture"}, {"id": 4, "name": "bed", "supercategory": "furniture"}, {"id": 5, "name": "chair", "supercategory": "furniture"}, {"id": 6, "name": "sofa", "supercategory": "furniture"}, {"id": 7, "name": "table", "supercategory": "furniture"}, {"id": 8, "name": "door", "supercategory": "furniture"}, {"id": 9, "name": "window", "supercategory": "furniture"}, {"id": 10, "name": "bookshelf", "supercategory": "furniture"}, {"id": 11, "name": "picture", "supercategory": "furniture"}, {"id": 12, "name": "counter", "supercategory": "furniture"}, {"id": 14, "name": "desk", "supercategory": "furniture"}, {"id": 16, "name": "curtain", "supercategory": "furniture"}, {"id": 24, "name": "refrigerator", "supercategory": "appliance"}, {"id": 28, "name": "shower curtain", "supercategory": "furniture"}, {"id": 33, "name": "toilet", "supercategory": "furniture"}, {"id": 34, "name": "sink", "supercategory": "appliance"}, {"id": 36, "name": "bathtub", "supercategory": "furniture"}, {"id": 39, "name": "otherfurniture", "supercategory": "furniture"}, ], "oid": [ {"id": 1, "name": "Screwdriver", "freebase_id": "/m/01bms0"}, {"id": 2, "name": "Light switch", "freebase_id": "/m/03jbxj"}, {"id": 3, "name": "Doughnut", "freebase_id": "/m/0jy4k"}, {"id": 4, "name": "Toilet paper", "freebase_id": "/m/09gtd"}, {"id": 5, "name": "Wrench", "freebase_id": "/m/01j5ks"}, {"id": 6, "name": "Toaster", "freebase_id": "/m/01k6s3"}, {"id": 7, "name": "Tennis ball", "freebase_id": "/m/05ctyq"}, {"id": 8, "name": "Radish", "freebase_id": "/m/015x5n"}, {"id": 9, "name": "Pomegranate", "freebase_id": "/m/0jwn_"}, {"id": 10, "name": "Kite", "freebase_id": "/m/02zt3"}, {"id": 11, "name": "Table tennis racket", "freebase_id": "/m/05_5p_0"}, {"id": 12, "name": "Hamster", "freebase_id": "/m/03qrc"}, {"id": 13, "name": "Barge", "freebase_id": "/m/01btn"}, {"id": 14, "name": "Shower", "freebase_id": "/m/02f9f_"}, {"id": 15, "name": "Printer", "freebase_id": "/m/01m4t"}, {"id": 16, "name": "Snowmobile", "freebase_id": "/m/01x3jk"}, {"id": 17, "name": "Fire hydrant", "freebase_id": "/m/01pns0"}, {"id": 18, "name": "Limousine", "freebase_id": "/m/01lcw4"}, {"id": 19, "name": "Whale", "freebase_id": "/m/084zz"}, {"id": 20, "name": "Microwave oven", "freebase_id": "/m/0fx9l"}, {"id": 21, "name": "Asparagus", "freebase_id": "/m/0cjs7"}, {"id": 22, "name": "Lion", "freebase_id": "/m/096mb"}, {"id": 23, "name": "Spatula", "freebase_id": "/m/02d1br"}, {"id": 24, "name": "Torch", "freebase_id": "/m/07dd4"}, {"id": 25, "name": "Volleyball", "freebase_id": "/m/02rgn06"}, {"id": 26, "name": "Ambulance", "freebase_id": "/m/012n7d"}, {"id": 27, "name": "Chopsticks", "freebase_id": "/m/01_5g"}, {"id": 28, "name": "Raccoon", "freebase_id": "/m/0dq75"}, {"id": 29, "name": "Blue jay", "freebase_id": "/m/01f8m5"}, {"id": 30, "name": "Lynx", "freebase_id": "/m/04g2r"}, {"id": 31, "name": "Dice", "freebase_id": "/m/029b3"}, {"id": 32, "name": "Filing cabinet", "freebase_id": "/m/047j0r"}, {"id": 33, "name": "Ruler", "freebase_id": "/m/0hdln"}, {"id": 34, "name": "Power plugs and sockets", "freebase_id": "/m/03bbps"}, {"id": 35, "name": "Bell pepper", "freebase_id": "/m/0jg57"}, {"id": 36, "name": "Binoculars", "freebase_id": "/m/0lt4_"}, {"id": 37, "name": "Pretzel", "freebase_id": "/m/01f91_"}, {"id": 38, "name": "Hot dog", "freebase_id": "/m/01b9xk"}, {"id": 39, "name": "Missile", "freebase_id": "/m/04ylt"}, {"id": 40, "name": "Common fig", "freebase_id": "/m/043nyj"}, {"id": 41, "name": "Croissant", "freebase_id": "/m/015wgc"}, {"id": 42, "name": "Adhesive tape", "freebase_id": "/m/03m3vtv"}, {"id": 43, "name": "Slow cooker", "freebase_id": "/m/02tsc9"}, {"id": 44, "name": "Dog bed", "freebase_id": "/m/0h8n6f9"}, {"id": 45, "name": "Harpsichord", "freebase_id": "/m/03q5t"}, {"id": 46, "name": "Billiard table", "freebase_id": "/m/04p0qw"}, {"id": 47, "name": "Alpaca", "freebase_id": "/m/0pcr"}, {"id": 48, "name": "Harbor seal", "freebase_id": "/m/02l8p9"}, {"id": 49, "name": "Grape", "freebase_id": "/m/0388q"}, {"id": 50, "name": "Nail", "freebase_id": "/m/05bm6"}, {"id": 51, "name": "Paper towel", "freebase_id": "/m/02w3r3"}, {"id": 52, "name": "Alarm clock", "freebase_id": "/m/046dlr"}, {"id": 53, "name": "Guacamole", "freebase_id": "/m/02g30s"}, {"id": 54, "name": "Starfish", "freebase_id": "/m/01h8tj"}, {"id": 55, "name": "Zebra", "freebase_id": "/m/0898b"}, {"id": 56, "name": "Segway", "freebase_id": "/m/076bq"}, {"id": 57, "name": "Sea turtle", "freebase_id": "/m/0120dh"}, {"id": 58, "name": "Scissors", "freebase_id": "/m/01lsmm"}, {"id": 59, "name": "Rhinoceros", "freebase_id": "/m/03d443"}, {"id": 60, "name": "Kangaroo", "freebase_id": "/m/04c0y"}, {"id": 61, "name": "Jaguar", "freebase_id": "/m/0449p"}, {"id": 62, "name": "Leopard", "freebase_id": "/m/0c29q"}, {"id": 63, "name": "Dumbbell", "freebase_id": "/m/04h8sr"}, {"id": 64, "name": "Envelope", "freebase_id": "/m/0frqm"}, {"id": 65, "name": "Winter melon", "freebase_id": "/m/02cvgx"}, {"id": 66, "name": "Teapot", "freebase_id": "/m/01fh4r"}, {"id": 67, "name": "Camel", "freebase_id": "/m/01x_v"}, {"id": 68, "name": "Beaker", "freebase_id": "/m/0d20w4"}, {"id": 69, "name": "Brown bear", "freebase_id": "/m/01dxs"}, {"id": 70, "name": "Toilet", "freebase_id": "/m/09g1w"}, {"id": 71, "name": "Teddy bear", "freebase_id": "/m/0kmg4"}, {"id": 72, "name": "Briefcase", "freebase_id": "/m/0584n8"}, {"id": 73, "name": "Stop sign", "freebase_id": "/m/02pv19"}, {"id": 74, "name": "Tiger", "freebase_id": "/m/07dm6"}, {"id": 75, "name": "Cabbage", "freebase_id": "/m/0fbw6"}, {"id": 76, "name": "Giraffe", "freebase_id": "/m/03bk1"}, {"id": 77, "name": "Polar bear", "freebase_id": "/m/0633h"}, {"id": 78, "name": "Shark", "freebase_id": "/m/0by6g"}, {"id": 79, "name": "Rabbit", "freebase_id": "/m/06mf6"}, {"id": 80, "name": "Swim cap", "freebase_id": "/m/04tn4x"}, {"id": 81, "name": "Pressure cooker", "freebase_id": "/m/0h8ntjv"}, {"id": 82, "name": "Kitchen knife", "freebase_id": "/m/058qzx"}, {"id": 83, "name": "Submarine sandwich", "freebase_id": "/m/06pcq"}, {"id": 84, "name": "Flashlight", "freebase_id": "/m/01kb5b"}, {"id": 85, "name": "Penguin", "freebase_id": "/m/05z6w"}, {"id": 86, "name": "Snake", "freebase_id": "/m/078jl"}, {"id": 87, "name": "Zucchini", "freebase_id": "/m/027pcv"}, {"id": 88, "name": "Bat", "freebase_id": "/m/01h44"}, {"id": 89, "name": "Food processor", "freebase_id": "/m/03y6mg"}, {"id": 90, "name": "Ostrich", "freebase_id": "/m/05n4y"}, {"id": 91, "name": "Sea lion", "freebase_id": "/m/0gd36"}, {"id": 92, "name": "Goldfish", "freebase_id": "/m/03fj2"}, {"id": 93, "name": "Elephant", "freebase_id": "/m/0bwd_0j"}, {"id": 94, "name": "Rocket", "freebase_id": "/m/09rvcxw"}, {"id": 95, "name": "Mouse", "freebase_id": "/m/04rmv"}, {"id": 96, "name": "Oyster", "freebase_id": "/m/0_cp5"}, {"id": 97, "name": "Digital clock", "freebase_id": "/m/06_72j"}, {"id": 98, "name": "Otter", "freebase_id": "/m/0cn6p"}, {"id": 99, "name": "Dolphin", "freebase_id": "/m/02hj4"}, {"id": 100, "name": "Punching bag", "freebase_id": "/m/0420v5"}, {"id": 101, "name": "Corded phone", "freebase_id": "/m/0h8lkj8"}, {"id": 102, "name": "Tennis racket", "freebase_id": "/m/0h8my_4"}, {"id": 103, "name": "Pancake", "freebase_id": "/m/01dwwc"}, {"id": 104, "name": "Mango", "freebase_id": "/m/0fldg"}, {"id": 105, "name": "Crocodile", "freebase_id": "/m/09f_2"}, {"id": 106, "name": "Waffle", "freebase_id": "/m/01dwsz"}, {"id": 107, "name": "Computer mouse", "freebase_id": "/m/020lf"}, {"id": 108, "name": "Kettle", "freebase_id": "/m/03s_tn"}, {"id": 109, "name": "Tart", "freebase_id": "/m/02zvsm"}, {"id": 110, "name": "Oven", "freebase_id": "/m/029bxz"}, {"id": 111, "name": "Banana", "freebase_id": "/m/09qck"}, {"id": 112, "name": "Cheetah", "freebase_id": "/m/0cd4d"}, {"id": 113, "name": "Raven", "freebase_id": "/m/06j2d"}, {"id": 114, "name": "Frying pan", "freebase_id": "/m/04v6l4"}, {"id": 115, "name": "Pear", "freebase_id": "/m/061_f"}, {"id": 116, "name": "Fox", "freebase_id": "/m/0306r"}, {"id": 117, "name": "Skateboard", "freebase_id": "/m/06_fw"}, {"id": 118, "name": "Rugby ball", "freebase_id": "/m/0wdt60w"}, {"id": 119, "name": "Watermelon", "freebase_id": "/m/0kpqd"}, {"id": 120, "name": "Flute", "freebase_id": "/m/0l14j_"}, {"id": 121, "name": "Canary", "freebase_id": "/m/0ccs93"}, {"id": 122, "name": "Door handle", "freebase_id": "/m/03c7gz"}, {"id": 123, "name": "Saxophone", "freebase_id": "/m/06ncr"}, {"id": 124, "name": "Burrito", "freebase_id": "/m/01j3zr"}, {"id": 125, "name": "Suitcase", "freebase_id": "/m/01s55n"}, {"id": 126, "name": "Roller skates", "freebase_id": "/m/02p3w7d"}, {"id": 127, "name": "Dagger", "freebase_id": "/m/02gzp"}, {"id": 128, "name": "Seat belt", "freebase_id": "/m/0dkzw"}, {"id": 129, "name": "Washing machine", "freebase_id": "/m/0174k2"}, {"id": 130, "name": "Jet ski", "freebase_id": "/m/01xs3r"}, {"id": 131, "name": "Sombrero", "freebase_id": "/m/02jfl0"}, {"id": 132, "name": "Pig", "freebase_id": "/m/068zj"}, {"id": 133, "name": "Drinking straw", "freebase_id": "/m/03v5tg"}, {"id": 134, "name": "Peach", "freebase_id": "/m/0dj6p"}, {"id": 135, "name": "Tortoise", "freebase_id": "/m/011k07"}, {"id": 136, "name": "Towel", "freebase_id": "/m/0162_1"}, {"id": 137, "name": "Tablet computer", "freebase_id": "/m/0bh9flk"}, {"id": 138, "name": "Cucumber", "freebase_id": "/m/015x4r"}, {"id": 139, "name": "Mule", "freebase_id": "/m/0dbzx"}, {"id": 140, "name": "Potato", "freebase_id": "/m/05vtc"}, {"id": 141, "name": "Frog", "freebase_id": "/m/09ld4"}, {"id": 142, "name": "Bear", "freebase_id": "/m/01dws"}, {"id": 143, "name": "Lighthouse", "freebase_id": "/m/04h7h"}, {"id": 144, "name": "Belt", "freebase_id": "/m/0176mf"}, {"id": 145, "name": "Baseball bat", "freebase_id": "/m/03g8mr"}, {"id": 146, "name": "Racket", "freebase_id": "/m/0dv9c"}, {"id": 147, "name": "Sword", "freebase_id": "/m/06y5r"}, {"id": 148, "name": "Bagel", "freebase_id": "/m/01fb_0"}, {"id": 149, "name": "Goat", "freebase_id": "/m/03fwl"}, {"id": 150, "name": "Lizard", "freebase_id": "/m/04m9y"}, {"id": 151, "name": "Parrot", "freebase_id": "/m/0gv1x"}, {"id": 152, "name": "Owl", "freebase_id": "/m/09d5_"}, {"id": 153, "name": "Turkey", "freebase_id": "/m/0jly1"}, {"id": 154, "name": "Cello", "freebase_id": "/m/01xqw"}, {"id": 155, "name": "Knife", "freebase_id": "/m/04ctx"}, {"id": 156, "name": "Handgun", "freebase_id": "/m/0gxl3"}, {"id": 157, "name": "Carrot", "freebase_id": "/m/0fj52s"}, {"id": 158, "name": "Hamburger", "freebase_id": "/m/0cdn1"}, {"id": 159, "name": "Grapefruit", "freebase_id": "/m/0hqkz"}, {"id": 160, "name": "Tap", "freebase_id": "/m/02jz0l"}, {"id": 161, "name": "Tea", "freebase_id": "/m/07clx"}, {"id": 162, "name": "Bull", "freebase_id": "/m/0cnyhnx"}, {"id": 163, "name": "Turtle", "freebase_id": "/m/09dzg"}, {"id": 164, "name": "Bust", "freebase_id": "/m/04yqq2"}, {"id": 165, "name": "Monkey", "freebase_id": "/m/08pbxl"}, {"id": 166, "name": "Wok", "freebase_id": "/m/084rd"}, {"id": 167, "name": "Broccoli", "freebase_id": "/m/0hkxq"}, {"id": 168, "name": "Pitcher", "freebase_id": "/m/054fyh"}, {"id": 169, "name": "Whiteboard", "freebase_id": "/m/02d9qx"}, {"id": 170, "name": "Squirrel", "freebase_id": "/m/071qp"}, {"id": 171, "name": "Jug", "freebase_id": "/m/08hvt4"}, {"id": 172, "name": "Woodpecker", "freebase_id": "/m/01dy8n"}, {"id": 173, "name": "Pizza", "freebase_id": "/m/0663v"}, {"id": 174, "name": "Surfboard", "freebase_id": "/m/019w40"}, {"id": 175, "name": "Sofa bed", "freebase_id": "/m/03m3pdh"}, {"id": 176, "name": "Sheep", "freebase_id": "/m/07bgp"}, {"id": 177, "name": "Candle", "freebase_id": "/m/0c06p"}, {"id": 178, "name": "Muffin", "freebase_id": "/m/01tcjp"}, {"id": 179, "name": "Cookie", "freebase_id": "/m/021mn"}, {"id": 180, "name": "Apple", "freebase_id": "/m/014j1m"}, {"id": 181, "name": "Chest of drawers", "freebase_id": "/m/05kyg_"}, {"id": 182, "name": "Skull", "freebase_id": "/m/016m2d"}, {"id": 183, "name": "Chicken", "freebase_id": "/m/09b5t"}, {"id": 184, "name": "Loveseat", "freebase_id": "/m/0703r8"}, {"id": 185, "name": "Baseball glove", "freebase_id": "/m/03grzl"}, {"id": 186, "name": "Piano", "freebase_id": "/m/05r5c"}, {"id": 187, "name": "Waste container", "freebase_id": "/m/0bjyj5"}, {"id": 188, "name": "Barrel", "freebase_id": "/m/02zn6n"}, {"id": 189, "name": "Swan", "freebase_id": "/m/0dftk"}, {"id": 190, "name": "Taxi", "freebase_id": "/m/0pg52"}, {"id": 191, "name": "Lemon", "freebase_id": "/m/09k_b"}, {"id": 192, "name": "Pumpkin", "freebase_id": "/m/05zsy"}, {"id": 193, "name": "Sparrow", "freebase_id": "/m/0h23m"}, {"id": 194, "name": "Orange", "freebase_id": "/m/0cyhj_"}, {"id": 195, "name": "Tank", "freebase_id": "/m/07cmd"}, {"id": 196, "name": "Sandwich", "freebase_id": "/m/0l515"}, {"id": 197, "name": "Coffee", "freebase_id": "/m/02vqfm"}, {"id": 198, "name": "Juice", "freebase_id": "/m/01z1kdw"}, {"id": 199, "name": "Coin", "freebase_id": "/m/0242l"}, {"id": 200, "name": "Pen", "freebase_id": "/m/0k1tl"}, {"id": 201, "name": "Watch", "freebase_id": "/m/0gjkl"}, {"id": 202, "name": "Eagle", "freebase_id": "/m/09csl"}, {"id": 203, "name": "Goose", "freebase_id": "/m/0dbvp"}, {"id": 204, "name": "Falcon", "freebase_id": "/m/0f6wt"}, {"id": 205, "name": "Christmas tree", "freebase_id": "/m/025nd"}, {"id": 206, "name": "Sunflower", "freebase_id": "/m/0ftb8"}, {"id": 207, "name": "Vase", "freebase_id": "/m/02s195"}, {"id": 208, "name": "Football", "freebase_id": "/m/01226z"}, {"id": 209, "name": "Canoe", "freebase_id": "/m/0ph39"}, {"id": 210, "name": "High heels", "freebase_id": "/m/06k2mb"}, {"id": 211, "name": "Spoon", "freebase_id": "/m/0cmx8"}, {"id": 212, "name": "Mug", "freebase_id": "/m/02jvh9"}, {"id": 213, "name": "Swimwear", "freebase_id": "/m/01gkx_"}, {"id": 214, "name": "Duck", "freebase_id": "/m/09ddx"}, {"id": 215, "name": "Cat", "freebase_id": "/m/01yrx"}, {"id": 216, "name": "Tomato", "freebase_id": "/m/07j87"}, {"id": 217, "name": "Cocktail", "freebase_id": "/m/024g6"}, {"id": 218, "name": "Clock", "freebase_id": "/m/01x3z"}, {"id": 219, "name": "Cowboy hat", "freebase_id": "/m/025rp__"}, {"id": 220, "name": "Miniskirt", "freebase_id": "/m/01cmb2"}, {"id": 221, "name": "Cattle", "freebase_id": "/m/01xq0k1"}, {"id": 222, "name": "Strawberry", "freebase_id": "/m/07fbm7"}, {"id": 223, "name": "Bronze sculpture", "freebase_id": "/m/01yx86"}, {"id": 224, "name": "Pillow", "freebase_id": "/m/034c16"}, {"id": 225, "name": "Squash", "freebase_id": "/m/0dv77"}, {"id": 226, "name": "Traffic light", "freebase_id": "/m/015qff"}, {"id": 227, "name": "Saucer", "freebase_id": "/m/03q5c7"}, {"id": 228, "name": "Reptile", "freebase_id": "/m/06bt6"}, {"id": 229, "name": "Cake", "freebase_id": "/m/0fszt"}, {"id": 230, "name": "Plastic bag", "freebase_id": "/m/05gqfk"}, {"id": 231, "name": "Studio couch", "freebase_id": "/m/026qbn5"}, {"id": 232, "name": "Beer", "freebase_id": "/m/01599"}, {"id": 233, "name": "Scarf", "freebase_id": "/m/02h19r"}, {"id": 234, "name": "Coffee cup", "freebase_id": "/m/02p5f1q"}, {"id": 235, "name": "Wine", "freebase_id": "/m/081qc"}, {"id": 236, "name": "Mushroom", "freebase_id": "/m/052sf"}, {"id": 237, "name": "Traffic sign", "freebase_id": "/m/01mqdt"}, {"id": 238, "name": "Camera", "freebase_id": "/m/0dv5r"}, {"id": 239, "name": "Rose", "freebase_id": "/m/06m11"}, {"id": 240, "name": "Couch", "freebase_id": "/m/02crq1"}, {"id": 241, "name": "Handbag", "freebase_id": "/m/080hkjn"}, {"id": 242, "name": "Fedora", "freebase_id": "/m/02fq_6"}, {"id": 243, "name": "Sock", "freebase_id": "/m/01nq26"}, {"id": 244, "name": "Computer keyboard", "freebase_id": "/m/01m2v"}, {"id": 245, "name": "Mobile phone", "freebase_id": "/m/050k8"}, {"id": 246, "name": "Ball", "freebase_id": "/m/018xm"}, {"id": 247, "name": "Balloon", "freebase_id": "/m/01j51"}, {"id": 248, "name": "Horse", "freebase_id": "/m/03k3r"}, {"id": 249, "name": "Boot", "freebase_id": "/m/01b638"}, {"id": 250, "name": "Fish", "freebase_id": "/m/0ch_cf"}, {"id": 251, "name": "Backpack", "freebase_id": "/m/01940j"}, {"id": 252, "name": "Skirt", "freebase_id": "/m/02wv6h6"}, {"id": 253, "name": "Van", "freebase_id": "/m/0h2r6"}, {"id": 254, "name": "Bread", "freebase_id": "/m/09728"}, {"id": 255, "name": "Glove", "freebase_id": "/m/0174n1"}, {"id": 256, "name": "Dog", "freebase_id": "/m/0bt9lr"}, {"id": 257, "name": "Airplane", "freebase_id": "/m/0cmf2"}, {"id": 258, "name": "Motorcycle", "freebase_id": "/m/04_sv"}, {"id": 259, "name": "Drink", "freebase_id": "/m/0271t"}, {"id": 260, "name": "Book", "freebase_id": "/m/0bt_c3"}, {"id": 261, "name": "Train", "freebase_id": "/m/07jdr"}, {"id": 262, "name": "Flower", "freebase_id": "/m/0c9ph5"}, {"id": 263, "name": "Carnivore", "freebase_id": "/m/01lrl"}, {"id": 264, "name": "Human ear", "freebase_id": "/m/039xj_"}, {"id": 265, "name": "Toy", "freebase_id": "/m/0138tl"}, {"id": 266, "name": "Box", "freebase_id": "/m/025dyy"}, {"id": 267, "name": "Truck", "freebase_id": "/m/07r04"}, {"id": 268, "name": "Wheel", "freebase_id": "/m/083wq"}, {"id": 269, "name": "Aircraft", "freebase_id": "/m/0k5j"}, {"id": 270, "name": "Bus", "freebase_id": "/m/01bjv"}, {"id": 271, "name": "Human mouth", "freebase_id": "/m/0283dt1"}, {"id": 272, "name": "Sculpture", "freebase_id": "/m/06msq"}, {"id": 273, "name": "Shirt", "freebase_id": "/m/01n4qj"}, {"id": 274, "name": "Hat", "freebase_id": "/m/02dl1y"}, {"id": 275, "name": "Vehicle registration plate", "freebase_id": "/m/01jfm_"}, {"id": 276, "name": "Guitar", "freebase_id": "/m/0342h"}, {"id": 277, "name": "Sun hat", "freebase_id": "/m/02wbtzl"}, {"id": 278, "name": "Bottle", "freebase_id": "/m/04dr76w"}, {"id": 279, "name": "Luggage and bags", "freebase_id": "/m/0hf58v5"}, {"id": 280, "name": "Trousers", "freebase_id": "/m/07mhn"}, {"id": 281, "name": "Bicycle wheel", "freebase_id": "/m/01bqk0"}, {"id": 282, "name": "Suit", "freebase_id": "/m/01xyhv"}, {"id": 283, "name": "Bowl", "freebase_id": "/m/04kkgm"}, {"id": 284, "name": "Man", "freebase_id": "/m/04yx4"}, {"id": 285, "name": "Flowerpot", "freebase_id": "/m/0fm3zh"}, {"id": 286, "name": "Laptop", "freebase_id": "/m/01c648"}, {"id": 287, "name": "Boy", "freebase_id": "/m/01bl7v"}, {"id": 288, "name": "Picture frame", "freebase_id": "/m/06z37_"}, {"id": 289, "name": "Bird", "freebase_id": "/m/015p6"}, {"id": 290, "name": "Car", "freebase_id": "/m/0k4j"}, {"id": 291, "name": "Shorts", "freebase_id": "/m/01bfm9"}, {"id": 292, "name": "Woman", "freebase_id": "/m/03bt1vf"}, {"id": 293, "name": "Platter", "freebase_id": "/m/099ssp"}, {"id": 294, "name": "Tie", "freebase_id": "/m/01rkbr"}, {"id": 295, "name": "Girl", "freebase_id": "/m/05r655"}, {"id": 296, "name": "Skyscraper", "freebase_id": "/m/079cl"}, {"id": 297, "name": "Person", "freebase_id": "/m/01g317"}, {"id": 298, "name": "Flag", "freebase_id": "/m/03120"}, {"id": 299, "name": "Jeans", "freebase_id": "/m/0fly7"}, {"id": 300, "name": "Dress", "freebase_id": "/m/01d40f"}, ], "kitti": [ {"id": 24, "name": "person"}, {"id": 25, "name": "rider"}, {"id": 26, "name": "car"}, {"id": 27, "name": "truck"}, {"id": 28, "name": "bus"}, {"id": 31, "name": "train"}, {"id": 32, "name": "motorcycle"}, {"id": 33, "name": "bicycle"}, ], "wilddash": [ {"id": 1, "name": "ego vehicle"}, {"id": 24, "name": "person"}, {"id": 25, "name": "rider"}, {"id": 26, "name": "car"}, {"id": 27, "name": "truck"}, {"id": 28, "name": "bus"}, {"id": 29, "name": "caravan"}, {"id": 30, "name": "trailer"}, {"id": 31, "name": "train"}, {"id": 32, "name": "motorcycle"}, {"id": 33, "name": "bicycle"}, {"id": 34, "name": "pickup"}, {"id": 35, "name": "van"}, ],}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284import loggingimport os
import pycocotools.mask as mask_util
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets.builtin_meta import _get_coco_instances_metafrom detectron2.data.datasets.lvis_v0_5_categories import LVIS_CATEGORIES as LVIS_V0_5_CATEGORIESfrom detectron2.data.datasets.lvis_v1_categories import LVIS_CATEGORIES as LVIS_V1_CATEGORIESfrom detectron2.structures import BoxModefrom detectron2.utils.file_io import PathManagerfrom fvcore.common.timer import Timer
from .lvis_v1_coco_category_image_count import LVIS_V1_COCO_CATEGORY_IMAGE_COUNT
"""This file contains functions to parse LVIS-format annotations into dicts in the"Detectron2 format"."""
logger = logging.getLogger(__name__)
__all__ = ["custom_load_lvis_json", "custom_register_lvis_instances"]
def custom_register_lvis_instances(name, metadata, json_file, image_root): """ Register a dataset in LVIS's json annotation format for instance detection and segmentation.
Args: name (str): a name that identifies the dataset, e.g. "lvis_v0.5_train". metadata (dict): extra metadata associated with this dataset. It can be an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ DatasetCatalog.register(name, lambda: custom_load_lvis_json(json_file, image_root, name)) MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="lvis", **metadata )
def custom_load_lvis_json(json_file, image_root, dataset_name=None, extra_annotation_keys=None): """ Load a json file in LVIS's annotation format.
Args: json_file (str): full path to the LVIS json annotation file. image_root (str): the directory where the images in this json file exists. dataset_name (str): the name of the dataset (e.g., "lvis_v0.5_train"). If provided, this function will put "thing_classes" into the metadata associated with this dataset. extra_annotation_keys (list[str]): list of per-annotation keys that should also be loaded into the dataset dict (besides "bbox", "bbox_mode", "category_id", "segmentation"). The values for these keys will be returned as-is.
Returns: list[dict]: a list of dicts in Detectron2 standard format. (See `Using Custom Datasets </tutorials/datasets.html>`_ )
Notes: 1. This function does not read the image files. The results do not have the "image" field. """ from lvis import LVIS
json_file = PathManager.get_local_path(json_file)
timer = Timer() lvis_api = LVIS(json_file) if timer.seconds() > 1: logger.info("Loading {} takes {:.2f} seconds.".format(json_file, timer.seconds()))
if dataset_name is not None: meta = get_lvis_instances_meta(dataset_name) MetadataCatalog.get(dataset_name).set(**meta)
# sort indices for reproducible results img_ids = sorted(lvis_api.imgs.keys()) # imgs is a list of dicts, each looks something like: # {'license': 4, # 'url': 'http://farm6.staticflickr.com/5454/9413846304_881d5e5c3b_z.jpg', # 'file_name': 'COCO_val2014_000000001268.jpg', # 'height': 427, # 'width': 640, # 'date_captured': '2013-11-17 05:57:24', # 'id': 1268} imgs = lvis_api.load_imgs(img_ids) # anns is a list[list[dict]], where each dict is an annotation # record for an object. The inner list enumerates the objects in an image # and the outer list enumerates over images. Example of anns[0]: # [{'segmentation': [[192.81, # 247.09, # ... # 219.03, # 249.06]], # 'area': 1035.749, # 'image_id': 1268, # 'bbox': [192.81, 224.8, 74.73, 33.43], # 'category_id': 16, # 'id': 42986}, # ...] anns = [lvis_api.img_ann_map[img_id] for img_id in img_ids]
# Sanity check that each annotation has a unique id ann_ids = [ann["id"] for anns_per_image in anns for ann in anns_per_image] assert len(set(ann_ids)) == len(ann_ids), "Annotation ids in '{}' are not unique".format( json_file )
imgs_anns = list(zip(imgs, anns))
logger.info("Loaded {} images in the LVIS format from {}".format(len(imgs_anns), json_file))
if extra_annotation_keys: logger.info( "The following extra annotation keys will be loaded: {} ".format(extra_annotation_keys) ) else: extra_annotation_keys = []
def get_file_name(img_root, img_dict): # Determine the path including the split folder ("train2017", "val2017", "test2017") from # the coco_url field. Example: # 'coco_url': 'http://images.cocodataset.org/train2017/000000155379.jpg' if "file_name" in img_dict: file_name = img_dict["file_name"] if img_dict["file_name"].startswith("COCO"): file_name = file_name[-16:] return os.path.join(image_root, file_name) split_folder, file_name = img_dict["coco_url"].split("/")[-2:] return os.path.join(img_root + split_folder, file_name)
dataset_dicts = []
for (img_dict, anno_dict_list) in imgs_anns: record = {} record["file_name"] = get_file_name(image_root, img_dict) record["height"] = img_dict["height"] record["width"] = img_dict["width"] record["not_exhaustive_category_ids"] = img_dict.get("not_exhaustive_category_ids", []) record["neg_category_ids"] = img_dict.get("neg_category_ids", []) record["pos_category_ids"] = img_dict.get("pos_category_ids", []) if dataset_name is not None and "thing_dataset_id_to_contiguous_id" in meta: record["neg_category_ids"] = [ meta["thing_dataset_id_to_contiguous_id"][x] for x in record["neg_category_ids"] ] record["pos_category_ids"] = [ meta["thing_dataset_id_to_contiguous_id"][x] for x in record["pos_category_ids"] ] else: record["neg_category_ids"] = [x - 1 for x in record["neg_category_ids"]] record["pos_category_ids"] = [x - 1 for x in record["pos_category_ids"]] if "captions" in img_dict: record["captions"] = img_dict["captions"] if "caption_features" in img_dict: record["caption_features"] = img_dict["caption_features"] image_id = record["image_id"] = img_dict["id"]
objs = [] for anno in anno_dict_list: assert anno["image_id"] == image_id if anno.get("iscrowd", 0) > 0: continue # Check that the image_id in this annotation is the same as # the image_id we're looking at. # This fails only when the data parsing logic or the annotation file is buggy. assert anno["image_id"] == image_id obj = {"bbox": anno["bbox"], "bbox_mode": BoxMode.XYWH_ABS} # LVIS data loader can be used to load COCO dataset categories. In this case `meta` # variable will have a field with COCO-specific category mapping. if dataset_name is not None and "thing_dataset_id_to_contiguous_id" in meta: obj["category_id"] = meta["thing_dataset_id_to_contiguous_id"][anno["category_id"]] else: obj["category_id"] = anno["category_id"] - 1 # Convert 1-indexed to 0-indexed # segm = anno["segmentation"] # list[list[float]] # # filter out invalid polygons (< 3 points) # valid_segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] # assert len(segm) == len( # valid_segm # ), "Annotation contains an invalid polygon with < 3 points" # assert len(segm) > 0 # obj["segmentation"] = segm segm = anno.get("segmentation", None) if segm: # either list[list[float]] or dict(RLE) if isinstance(segm, dict): if isinstance(segm["counts"], list): # convert to compressed RLE segm = mask_util.frPyObjects(segm, *segm["size"]) else: # filter out invalid polygons (< 3 points) segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] if len(segm) == 0: num_instances_without_valid_segmentation += 1 continue # ignore this instance obj["segmentation"] = segm
phrase = anno.get("phrase", None) if phrase: obj["phrase"] = phrase
for extra_ann_key in extra_annotation_keys: obj[extra_ann_key] = anno[extra_ann_key] objs.append(obj) record["annotations"] = objs dataset_dicts.append(record)
return dataset_dicts
def get_lvis_instances_meta(dataset_name): """ Load LVIS metadata.
Args: dataset_name (str): LVIS dataset name without the split name (e.g., "lvis_v0.5").
Returns: dict: LVIS metadata with keys: thing_classes """ if "cocofied" in dataset_name: return _get_coco_instances_meta() if "v0.5" in dataset_name: return _get_lvis_instances_meta_v0_5() elif "v1" in dataset_name: return _get_lvis_instances_meta_v1() logger.info("No built-in metadata for dataset {}".format(dataset_name)) return {} raise ValueError("No built-in metadata for dataset {}".format(dataset_name))
def _get_lvis_instances_meta_v0_5(): assert len(LVIS_V0_5_CATEGORIES) == 1230 cat_ids = [k["id"] for k in LVIS_V0_5_CATEGORIES] assert min(cat_ids) == 1 and max(cat_ids) == len( cat_ids ), "Category ids are not in [1, #categories], as expected" # Ensure that the category list is sorted by id lvis_categories = sorted(LVIS_V0_5_CATEGORIES, key=lambda x: x["id"]) thing_classes = [k["synonyms"][0] for k in lvis_categories] meta = {"thing_classes": thing_classes} return meta
def _get_lvis_instances_meta_v1(): assert len(LVIS_V1_CATEGORIES) == 1203 cat_ids = [k["id"] for k in LVIS_V1_CATEGORIES] assert min(cat_ids) == 1 and max(cat_ids) == len( cat_ids ), "Category ids are not in [1, #categories], as expected" # Ensure that the category list is sorted by id lvis_categories = sorted(LVIS_V1_CATEGORIES, key=lambda x: x["id"]) thing_classes = [k["synonyms"][0] for k in lvis_categories] meta = {"thing_classes": thing_classes, "class_image_count": LVIS_V1_COCO_CATEGORY_IMAGE_COUNT} return meta
_PREDEFINED_SPLITS_LVIS = { "lvis_v1_train+coco": { "lvis_v1_train+coco": ("coco/", "lvis/lvis_v1_train+coco_mask.json"), }, "lvis_v1_val+coco": { "lvis_v1_val+coco": ("coco/", "lvis/lvis_v1_val+coco_mask.json"), }, "lvis_v1_minival": { "lvis_v1_minival": ("coco/", "lvis/lvis_v1_minival_inserted_image_name.json"), },}
def register_all_lvis_coco(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_LVIS.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_lvis_instances( key, get_lvis_instances_meta(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".lvis_coco"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_lvis_coco(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192# Copyright (c) Facebook, Inc. and its affiliates.import copyimport jsonimport os
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets.builtin_meta import COCO_CATEGORIESfrom detectron2.data.datasets.coco import load_sem_segfrom detectron2.utils.file_io import PathManager
from .lvis_coco import custom_load_lvis_json, get_lvis_instances_meta
__all__ = ["register_lvis_panoptic_separated"]
def register_lvis_panoptic_separated( name, metadata, image_root, panoptic_root, panoptic_json, sem_seg_root, instances_json): """ Register a "separated" version of COCO panoptic segmentation dataset named `name`. The annotations in this registered dataset will contain both instance annotations and semantic annotations, each with its own contiguous ids. Hence it's called "separated".
It follows the setting used by the PanopticFPN paper:
1. The instance annotations directly come from polygons in the COCO instances annotation task, rather than from the masks in the COCO panoptic annotations.
The two format have small differences: Polygons in the instance annotations may have overlaps. The mask annotations are produced by labeling the overlapped polygons with depth ordering.
2. The semantic annotations are converted from panoptic annotations, where all "things" are assigned a semantic id of 0. All semantic categories will therefore have ids in contiguous range [1, #stuff_categories].
This function will also register a pure semantic segmentation dataset named ``name + '_stuffonly'``.
Args: name (str): the name that identifies a dataset, e.g. "coco_2017_train_panoptic" metadata (dict): extra metadata associated with this dataset. image_root (str): directory which contains all the images panoptic_root (str): directory which contains panoptic annotation images panoptic_json (str): path to the json panoptic annotation file sem_seg_root (str): directory which contains all the ground truth segmentation annotations. instances_json (str): path to the json instance annotation file """ panoptic_name = name + "_separated" split_folder = sem_seg_root.split("_")[-1] # datasets/coco/panoptic_stuff_train2017 DatasetCatalog.register( panoptic_name, lambda: merge_to_panoptic( custom_load_lvis_json(instances_json, image_root, panoptic_name), load_sem_seg(sem_seg_root, os.path.join(image_root, split_folder)), ), ) MetadataCatalog.get(panoptic_name).set( panoptic_root=panoptic_root, image_root=image_root, panoptic_json=panoptic_json, sem_seg_root=sem_seg_root, json_file=instances_json, # TODO rename evaluator_type="coco_panoptic_seg", ignore_label=255, **metadata, )
semantic_name = name + "_stuffonly" DatasetCatalog.register(semantic_name, lambda: load_sem_seg(sem_seg_root, image_root)) MetadataCatalog.get(semantic_name).set( sem_seg_root=sem_seg_root, image_root=image_root, evaluator_type="sem_seg", ignore_label=255, **metadata, )
def merge_to_panoptic(detection_dicts, sem_seg_dicts): """ Create dataset dicts for panoptic segmentation, by merging two dicts using "file_name" field to match their entries.
Args: detection_dicts (list[dict]): lists of dicts for object detection or instance segmentation. sem_seg_dicts (list[dict]): lists of dicts for semantic segmentation.
Returns: list[dict] (one per input image): Each dict contains all (key, value) pairs from dicts in both detection_dicts and sem_seg_dicts that correspond to the same image. The function assumes that the same key in different dicts has the same value. """ results = [] sem_seg_file_to_entry = {x["file_name"]: x for x in sem_seg_dicts} assert len(sem_seg_file_to_entry) > 0
for det_dict in detection_dicts: dic = copy.copy(det_dict) dic.update(sem_seg_file_to_entry[dic["file_name"]]) results.append(dic) return results
def _get_builtin_metadata(dataset_name): if dataset_name == "lvis_panoptic_separated": return _get_lvis_panoptic_separated_meta()
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_lvis_panoptic_separated_meta(): """ Returns metadata for "separated" version of the panoptic segmentation dataset. """ stuff_ids = [k["id"] for k in COCO_CATEGORIES if k["isthing"] == 0] assert len(stuff_ids) == 53, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 53], used in models) to ids in the dataset (used for processing results) # The id 0 is mapped to an extra category "thing". stuff_dataset_id_to_contiguous_id = {k: i + 1 for i, k in enumerate(stuff_ids)} # When converting COCO panoptic annotations to semantic annotations # We label the "thing" category to 0 stuff_dataset_id_to_contiguous_id[0] = 0
# 54 names for COCO stuff categories (including "things") stuff_classes = ["things"] + [ k["name"].replace("-other", "").replace("-merged", "").replace("-stuff", "") for k in COCO_CATEGORIES if k["isthing"] == 0 ]
# NOTE: I randomly picked a color for things stuff_colors = [[82, 18, 128]] + [k["color"] for k in COCO_CATEGORIES if k["isthing"] == 0] ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, "stuff_colors": stuff_colors, } ret.update(get_lvis_instances_meta("v1")) return ret
_PREDEFINED_SPLITS_LVIS_PANOPTIC = { "lvis_v1_train+coco_panoptic": ( # This is the original panoptic annotation directory "coco/panoptic_train2017", "coco/annotations/panoptic_train2017.json", # This directory contains semantic annotations that are # converted from panoptic annotations. # It is used by PanopticFPN. # You can use the script at detectron2/datasets/prepare_panoptic_fpn.py # to create these directories. "coco/panoptic_stuff_train2017", ), "lvis_v1_val+coco_panoptic": ( "coco/panoptic_val2017", "coco/annotations/panoptic_val2017.json", "coco/panoptic_stuff_val2017", ),}
def register_all_lvis_coco_panoptic(root): for ( prefix, (panoptic_root, panoptic_json, semantic_root), ) in _PREDEFINED_SPLITS_LVIS_PANOPTIC.items(): prefix_instances = prefix[: -len("_panoptic")] instances_meta = MetadataCatalog.get(prefix_instances) image_root, instances_json = instances_meta.image_root, instances_meta.json_file # The "separated" version of COCO panoptic segmentation dataset, # e.g. used by Panoptic FPN register_lvis_panoptic_separated( prefix, _get_builtin_metadata("lvis_panoptic_separated"), image_root, os.path.join(root, panoptic_root), os.path.join(root, panoptic_json), os.path.join(root, semantic_root), instances_json, )
if __name__.endswith(".lvis_coco_panoptic"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_lvis_coco_panoptic(_root)1234567891011121314151617181920# Copyright (c) Facebook, Inc. and its affiliates.# Autogen with# with open("lvis_v1_train.json", "r") as f:# a = json.load(f)# c = a["categories"]# for x in c:# del x["name"]# del x["instance_count"]# del x["def"]# del x["synonyms"]# del x["frequency"]# del x["synset"]# LVIS_CATEGORY_IMAGE_COUNT = repr(c) + " # noqa"# with open("/tmp/lvis_category_image_count.py", "wt") as f:# f.write(f"LVIS_CATEGORY_IMAGE_COUNT = {LVIS_CATEGORY_IMAGE_COUNT}")# Then paste the contents of that file below
# fmt: offLVIS_V1_COCO_CATEGORY_IMAGE_COUNT = [{'image_count': 64, 'id': 1}, {'image_count': 364, 'id': 2}, {'image_count': 2596, 'id': 3}, {'image_count': 149, 'id': 4}, {'image_count': 29, 'id': 5}, {'image_count': 26, 'id': 6}, {'image_count': 59, 'id': 7}, {'image_count': 22, 'id': 8}, {'image_count': 12, 'id': 9}, {'image_count': 28, 'id': 10}, {'image_count': 505, 'id': 11}, {'image_count': 1626, 'id': 12}, {'image_count': 4, 'id': 13}, {'image_count': 10, 'id': 14}, {'image_count': 500, 'id': 15}, {'image_count': 33, 'id': 16}, {'image_count': 3, 'id': 17}, {'image_count': 44, 'id': 18}, {'image_count': 561, 'id': 19}, {'image_count': 8, 'id': 20}, {'image_count': 9, 'id': 21}, {'image_count': 33, 'id': 22}, {'image_count': 1883, 'id': 23}, {'image_count': 98, 'id': 24}, {'image_count': 70, 'id': 25}, {'image_count': 46, 'id': 26}, {'image_count': 117, 'id': 27}, {'image_count': 41, 'id': 28}, {'image_count': 1395, 'id': 29}, {'image_count': 7, 'id': 30}, {'image_count': 1, 'id': 31}, {'image_count': 314, 'id': 32}, {'image_count': 31, 'id': 33}, {'image_count': 4965, 'id': 34}, {'image_count': 6090, 'id': 35}, {'image_count': 2183, 'id': 36}, {'image_count': 47, 'id': 37}, {'image_count': 3, 'id': 38}, {'image_count': 3, 'id': 39}, {'image_count': 1, 'id': 40}, {'image_count': 3780, 'id': 41}, {'image_count': 6, 'id': 42}, {'image_count': 210, 'id': 43}, {'image_count': 36, 'id': 44}, {'image_count': 2000, 'id': 45}, {'image_count': 17, 'id': 46}, {'image_count': 51, 'id': 47}, {'image_count': 138, 'id': 48}, {'image_count': 3, 'id': 49}, {'image_count': 1470, 'id': 50}, {'image_count': 3, 'id': 51}, {'image_count': 2, 'id': 52}, {'image_count': 186, 'id': 53}, {'image_count': 76, 'id': 54}, {'image_count': 26, 'id': 55}, {'image_count': 303, 'id': 56}, {'image_count': 738, 'id': 57}, {'image_count': 2216, 'id': 58}, {'image_count': 1934, 'id': 59}, {'image_count': 2287, 'id': 60}, {'image_count': 1622, 'id': 61}, {'image_count': 41, 'id': 62}, {'image_count': 4, 'id': 63}, {'image_count': 11, 'id': 64}, {'image_count': 270, 'id': 65}, {'image_count': 349, 'id': 66}, {'image_count': 42, 'id': 67}, {'image_count': 823, 'id': 68}, {'image_count': 6, 'id': 69}, {'image_count': 48, 'id': 70}, {'image_count': 3, 'id': 71}, {'image_count': 42, 'id': 72}, {'image_count': 24, 'id': 73}, {'image_count': 16, 'id': 74}, {'image_count': 605, 'id': 75}, {'image_count': 898, 'id': 76}, {'image_count': 3194, 'id': 77}, {'image_count': 2, 'id': 78}, {'image_count': 125, 'id': 79}, {'image_count': 1739, 'id': 80}, {'image_count': 140, 'id': 81}, {'image_count': 4, 'id': 82}, {'image_count': 322, 'id': 83}, {'image_count': 60, 'id': 84}, {'image_count': 2, 'id': 85}, {'image_count': 231, 'id': 86}, {'image_count': 333, 'id': 87}, {'image_count': 1941, 'id': 88}, {'image_count': 367, 'id': 89}, {'image_count': 4908, 'id': 90}, {'image_count': 18, 'id': 91}, {'image_count': 81, 'id': 92}, {'image_count': 1, 'id': 93}, {'image_count': 2940, 'id': 94}, {'image_count': 430, 'id': 95}, {'image_count': 247, 'id': 96}, {'image_count': 94, 'id': 97}, {'image_count': 21, 'id': 98}, {'image_count': 2950, 'id': 99}, {'image_count': 16, 'id': 100}, {'image_count': 12, 'id': 101}, {'image_count': 25, 'id': 102}, {'image_count': 41, 'id': 103}, {'image_count': 244, 'id': 104}, {'image_count': 7, 'id': 105}, {'image_count': 1, 'id': 106}, {'image_count': 40, 'id': 107}, {'image_count': 40, 'id': 108}, {'image_count': 104, 'id': 109}, {'image_count': 1671, 'id': 110}, {'image_count': 49, 'id': 111}, {'image_count': 243, 'id': 112}, {'image_count': 2, 'id': 113}, {'image_count': 242, 'id': 114}, {'image_count': 271, 'id': 115}, {'image_count': 104, 'id': 116}, {'image_count': 8, 'id': 117}, {'image_count': 2674, 'id': 118}, {'image_count': 1, 'id': 119}, {'image_count': 48, 'id': 120}, {'image_count': 14, 'id': 121}, {'image_count': 40, 'id': 122}, {'image_count': 1, 'id': 123}, {'image_count': 37, 'id': 124}, {'image_count': 1510, 'id': 125}, {'image_count': 6, 'id': 126}, {'image_count': 4808, 'id': 127}, {'image_count': 70, 'id': 128}, {'image_count': 86, 'id': 129}, {'image_count': 7, 'id': 130}, {'image_count': 5, 'id': 131}, {'image_count': 1406, 'id': 132}, {'image_count': 7655, 'id': 133}, {'image_count': 15, 'id': 134}, {'image_count': 28, 'id': 135}, {'image_count': 6, 'id': 136}, {'image_count': 494, 'id': 137}, {'image_count': 234, 'id': 138}, {'image_count': 6332, 'id': 139}, {'image_count': 1, 'id': 140}, {'image_count': 35, 'id': 141}, {'image_count': 5, 'id': 142}, {'image_count': 1828, 'id': 143}, {'image_count': 8, 'id': 144}, {'image_count': 63, 'id': 145}, {'image_count': 1668, 'id': 146}, {'image_count': 4, 'id': 147}, {'image_count': 95, 'id': 148}, {'image_count': 17, 'id': 149}, {'image_count': 1567, 'id': 150}, {'image_count': 2, 'id': 151}, {'image_count': 103, 'id': 152}, {'image_count': 50, 'id': 153}, {'image_count': 1678, 'id': 154}, {'image_count': 6, 'id': 155}, {'image_count': 92, 'id': 156}, {'image_count': 19, 'id': 157}, {'image_count': 37, 'id': 158}, {'image_count': 4, 'id': 159}, {'image_count': 709, 'id': 160}, {'image_count': 9, 'id': 161}, {'image_count': 82, 'id': 162}, {'image_count': 15, 'id': 163}, {'image_count': 3, 'id': 164}, {'image_count': 61, 'id': 165}, {'image_count': 51, 'id': 166}, {'image_count': 5, 'id': 167}, {'image_count': 13, 'id': 168}, {'image_count': 642, 'id': 169}, {'image_count': 24, 'id': 170}, {'image_count': 255, 'id': 171}, {'image_count': 9, 'id': 172}, {'image_count': 3431, 'id': 173}, {'image_count': 31, 'id': 174}, {'image_count': 158, 'id': 175}, {'image_count': 80, 'id': 176}, {'image_count': 1884, 'id': 177}, {'image_count': 158, 'id': 178}, {'image_count': 2, 'id': 179}, {'image_count': 12, 'id': 180}, {'image_count': 1659, 'id': 181}, {'image_count': 7, 'id': 182}, {'image_count': 2555, 'id': 183}, {'image_count': 57, 'id': 184}, {'image_count': 174, 'id': 185}, {'image_count': 95, 'id': 186}, {'image_count': 27, 'id': 187}, {'image_count': 22, 'id': 188}, {'image_count': 1391, 'id': 189}, {'image_count': 90, 'id': 190}, {'image_count': 40, 'id': 191}, {'image_count': 445, 'id': 192}, {'image_count': 21, 'id': 193}, {'image_count': 1132, 'id': 194}, {'image_count': 177, 'id': 195}, {'image_count': 4, 'id': 196}, {'image_count': 17, 'id': 197}, {'image_count': 84, 'id': 198}, {'image_count': 55, 'id': 199}, {'image_count': 30, 'id': 200}, {'image_count': 25, 'id': 201}, {'image_count': 2, 'id': 202}, {'image_count': 125, 'id': 203}, {'image_count': 1135, 'id': 204}, {'image_count': 19, 'id': 205}, {'image_count': 72, 'id': 206}, {'image_count': 10661, 'id': 207}, {'image_count': 159, 'id': 208}, {'image_count': 7, 'id': 209}, {'image_count': 1, 'id': 210}, {'image_count': 13, 'id': 211}, {'image_count': 35, 'id': 212}, {'image_count': 18, 'id': 213}, {'image_count': 8, 'id': 214}, {'image_count': 6, 'id': 215}, {'image_count': 35, 'id': 216}, {'image_count': 1531, 'id': 217}, {'image_count': 103, 'id': 218}, {'image_count': 28, 'id': 219}, {'image_count': 63, 'id': 220}, {'image_count': 28, 'id': 221}, {'image_count': 5, 'id': 222}, {'image_count': 7, 'id': 223}, {'image_count': 14, 'id': 224}, {'image_count': 3422, 'id': 225}, {'image_count': 133, 'id': 226}, {'image_count': 16, 'id': 227}, {'image_count': 27, 'id': 228}, {'image_count': 110, 'id': 229}, {'image_count': 4201, 'id': 230}, {'image_count': 4, 'id': 231}, {'image_count': 11104, 'id': 232}, {'image_count': 8, 'id': 233}, {'image_count': 1, 'id': 234}, {'image_count': 263, 'id': 235}, {'image_count': 10, 'id': 236}, {'image_count': 2, 'id': 237}, {'image_count': 3, 'id': 238}, {'image_count': 87, 'id': 239}, {'image_count': 9, 'id': 240}, {'image_count': 71, 'id': 241}, {'image_count': 13, 'id': 242}, {'image_count': 18, 'id': 243}, {'image_count': 2, 'id': 244}, {'image_count': 5, 'id': 245}, {'image_count': 45, 'id': 246}, {'image_count': 1, 'id': 247}, {'image_count': 23, 'id': 248}, {'image_count': 32, 'id': 249}, {'image_count': 4, 'id': 250}, {'image_count': 1, 'id': 251}, {'image_count': 858, 'id': 252}, {'image_count': 661, 'id': 253}, {'image_count': 168, 'id': 254}, {'image_count': 210, 'id': 255}, {'image_count': 65, 'id': 256}, {'image_count': 4, 'id': 257}, {'image_count': 2, 'id': 258}, {'image_count': 159, 'id': 259}, {'image_count': 31, 'id': 260}, {'image_count': 811, 'id': 261}, {'image_count': 1, 'id': 262}, {'image_count': 42, 'id': 263}, {'image_count': 27, 'id': 264}, {'image_count': 2, 'id': 265}, {'image_count': 5, 'id': 266}, {'image_count': 95, 'id': 267}, {'image_count': 32, 'id': 268}, {'image_count': 1, 'id': 269}, {'image_count': 1, 'id': 270}, {'image_count': 4053, 'id': 271}, {'image_count': 897, 'id': 272}, {'image_count': 31, 'id': 273}, {'image_count': 23, 'id': 274}, {'image_count': 1, 'id': 275}, {'image_count': 202, 'id': 276}, {'image_count': 746, 'id': 277}, {'image_count': 44, 'id': 278}, {'image_count': 14, 'id': 279}, {'image_count': 26, 'id': 280}, {'image_count': 1, 'id': 281}, {'image_count': 2, 'id': 282}, {'image_count': 25, 'id': 283}, {'image_count': 238, 'id': 284}, {'image_count': 592, 'id': 285}, {'image_count': 26, 'id': 286}, {'image_count': 5, 'id': 287}, {'image_count': 42, 'id': 288}, {'image_count': 13, 'id': 289}, {'image_count': 46, 'id': 290}, {'image_count': 1, 'id': 291}, {'image_count': 8, 'id': 292}, {'image_count': 34, 'id': 293}, {'image_count': 5, 'id': 294}, {'image_count': 1, 'id': 295}, {'image_count': 2356, 'id': 296}, {'image_count': 717, 'id': 297}, {'image_count': 1010, 'id': 298}, {'image_count': 679, 'id': 299}, {'image_count': 3, 'id': 300}, {'image_count': 4, 'id': 301}, {'image_count': 1, 'id': 302}, {'image_count': 166, 'id': 303}, {'image_count': 2, 'id': 304}, {'image_count': 266, 'id': 305}, {'image_count': 101, 'id': 306}, {'image_count': 6, 'id': 307}, {'image_count': 14, 'id': 308}, {'image_count': 133, 'id': 309}, {'image_count': 2, 'id': 310}, {'image_count': 38, 'id': 311}, {'image_count': 95, 'id': 312}, {'image_count': 1, 'id': 313}, {'image_count': 12, 'id': 314}, {'image_count': 49, 'id': 315}, {'image_count': 5, 'id': 316}, {'image_count': 5, 'id': 317}, {'image_count': 16, 'id': 318}, {'image_count': 216, 'id': 319}, {'image_count': 12, 'id': 320}, {'image_count': 1, 'id': 321}, {'image_count': 54, 'id': 322}, {'image_count': 5, 'id': 323}, {'image_count': 245, 'id': 324}, {'image_count': 12, 'id': 325}, {'image_count': 7, 'id': 326}, {'image_count': 35, 'id': 327}, {'image_count': 36, 'id': 328}, {'image_count': 32, 'id': 329}, {'image_count': 1027, 'id': 330}, {'image_count': 10, 'id': 331}, {'image_count': 12, 'id': 332}, {'image_count': 1, 'id': 333}, {'image_count': 67, 'id': 334}, {'image_count': 71, 'id': 335}, {'image_count': 30, 'id': 336}, {'image_count': 48, 'id': 337}, {'image_count': 249, 'id': 338}, {'image_count': 13, 'id': 339}, {'image_count': 29, 'id': 340}, {'image_count': 14, 'id': 341}, {'image_count': 236, 'id': 342}, {'image_count': 15, 'id': 343}, {'image_count': 8183, 'id': 344}, {'image_count': 25, 'id': 345}, {'image_count': 249, 'id': 346}, {'image_count': 139, 'id': 347}, {'image_count': 2, 'id': 348}, {'image_count': 2, 'id': 349}, {'image_count': 1890, 'id': 350}, {'image_count': 1240, 'id': 351}, {'image_count': 1, 'id': 352}, {'image_count': 9, 'id': 353}, {'image_count': 1, 'id': 354}, {'image_count': 3, 'id': 355}, {'image_count': 11, 'id': 356}, {'image_count': 4, 'id': 357}, {'image_count': 236, 'id': 358}, {'image_count': 44, 'id': 359}, {'image_count': 19, 'id': 360}, {'image_count': 1100, 'id': 361}, {'image_count': 7, 'id': 362}, {'image_count': 69, 'id': 363}, {'image_count': 2, 'id': 364}, {'image_count': 8, 'id': 365}, {'image_count': 5, 'id': 366}, {'image_count': 10225, 'id': 367}, {'image_count': 6, 'id': 368}, {'image_count': 106, 'id': 369}, {'image_count': 81, 'id': 370}, {'image_count': 17, 'id': 371}, {'image_count': 134, 'id': 372}, {'image_count': 312, 'id': 373}, {'image_count': 8, 'id': 374}, {'image_count': 271, 'id': 375}, {'image_count': 2, 'id': 376}, {'image_count': 103, 'id': 377}, {'image_count': 3758, 'id': 378}, {'image_count': 574, 'id': 379}, {'image_count': 120, 'id': 380}, {'image_count': 2, 'id': 381}, {'image_count': 2, 'id': 382}, {'image_count': 13, 'id': 383}, {'image_count': 29, 'id': 384}, {'image_count': 1710, 'id': 385}, {'image_count': 66, 'id': 386}, {'image_count': 1326, 'id': 387}, {'image_count': 1, 'id': 388}, {'image_count': 3, 'id': 389}, {'image_count': 1942, 'id': 390}, {'image_count': 19, 'id': 391}, {'image_count': 1488, 'id': 392}, {'image_count': 46, 'id': 393}, {'image_count': 106, 'id': 394}, {'image_count': 115, 'id': 395}, {'image_count': 19, 'id': 396}, {'image_count': 2, 'id': 397}, {'image_count': 1, 'id': 398}, {'image_count': 28, 'id': 399}, {'image_count': 9, 'id': 400}, {'image_count': 192, 'id': 401}, {'image_count': 12, 'id': 402}, {'image_count': 21, 'id': 403}, {'image_count': 247, 'id': 404}, {'image_count': 6, 'id': 405}, {'image_count': 64, 'id': 406}, {'image_count': 7, 'id': 407}, {'image_count': 40, 'id': 408}, {'image_count': 542, 'id': 409}, {'image_count': 2, 'id': 410}, {'image_count': 1898, 'id': 411}, {'image_count': 36, 'id': 412}, {'image_count': 4, 'id': 413}, {'image_count': 1, 'id': 414}, {'image_count': 191, 'id': 415}, {'image_count': 6, 'id': 416}, {'image_count': 41, 'id': 417}, {'image_count': 39, 'id': 418}, {'image_count': 46, 'id': 419}, {'image_count': 1, 'id': 420}, {'image_count': 2100, 'id': 421}, {'image_count': 1915, 'id': 422}, {'image_count': 11, 'id': 423}, {'image_count': 82, 'id': 424}, {'image_count': 18, 'id': 425}, {'image_count': 1, 'id': 426}, {'image_count': 7, 'id': 427}, {'image_count': 3, 'id': 428}, {'image_count': 575, 'id': 429}, {'image_count': 1907, 'id': 430}, {'image_count': 8, 'id': 431}, {'image_count': 4, 'id': 432}, {'image_count': 32, 'id': 433}, {'image_count': 11, 'id': 434}, {'image_count': 4, 'id': 435}, {'image_count': 54, 'id': 436}, {'image_count': 202, 'id': 437}, {'image_count': 32, 'id': 438}, {'image_count': 3, 'id': 439}, {'image_count': 130, 'id': 440}, {'image_count': 119, 'id': 441}, {'image_count': 141, 'id': 442}, {'image_count': 29, 'id': 443}, {'image_count': 525, 'id': 444}, {'image_count': 1537, 'id': 445}, {'image_count': 2, 'id': 446}, {'image_count': 113, 'id': 447}, {'image_count': 16, 'id': 448}, {'image_count': 7, 'id': 449}, {'image_count': 35, 'id': 450}, {'image_count': 1908, 'id': 451}, {'image_count': 353, 'id': 452}, {'image_count': 18, 'id': 453}, {'image_count': 14, 'id': 454}, {'image_count': 77, 'id': 455}, {'image_count': 8, 'id': 456}, {'image_count': 37, 'id': 457}, {'image_count': 1, 'id': 458}, {'image_count': 346, 'id': 459}, {'image_count': 19, 'id': 460}, {'image_count': 1779, 'id': 461}, {'image_count': 23, 'id': 462}, {'image_count': 25, 'id': 463}, {'image_count': 67, 'id': 464}, {'image_count': 19, 'id': 465}, {'image_count': 28, 'id': 466}, {'image_count': 4, 'id': 467}, {'image_count': 27, 'id': 468}, {'image_count': 3150, 'id': 469}, {'image_count': 11, 'id': 470}, {'image_count': 13, 'id': 471}, {'image_count': 13, 'id': 472}, {'image_count': 32, 'id': 473}, {'image_count': 1911, 'id': 474}, {'image_count': 42, 'id': 475}, {'image_count': 17, 'id': 476}, {'image_count': 128, 'id': 477}, {'image_count': 1, 'id': 478}, {'image_count': 9, 'id': 479}, {'image_count': 10, 'id': 480}, {'image_count': 4, 'id': 481}, {'image_count': 9, 'id': 482}, {'image_count': 18, 'id': 483}, {'image_count': 41, 'id': 484}, {'image_count': 28, 'id': 485}, {'image_count': 3, 'id': 486}, {'image_count': 65, 'id': 487}, {'image_count': 9, 'id': 488}, {'image_count': 23, 'id': 489}, {'image_count': 24, 'id': 490}, {'image_count': 1, 'id': 491}, {'image_count': 2, 'id': 492}, {'image_count': 59, 'id': 493}, {'image_count': 48, 'id': 494}, {'image_count': 17, 'id': 495}, {'image_count': 2056, 'id': 496}, {'image_count': 18, 'id': 497}, {'image_count': 1920, 'id': 498}, {'image_count': 50, 'id': 499}, {'image_count': 1890, 'id': 500}, {'image_count': 99, 'id': 501}, {'image_count': 1530, 'id': 502}, {'image_count': 3, 'id': 503}, {'image_count': 11, 'id': 504}, {'image_count': 19, 'id': 505}, {'image_count': 3, 'id': 506}, {'image_count': 63, 'id': 507}, {'image_count': 5, 'id': 508}, {'image_count': 6, 'id': 509}, {'image_count': 233, 'id': 510}, {'image_count': 54, 'id': 511}, {'image_count': 36, 'id': 512}, {'image_count': 10, 'id': 513}, {'image_count': 124, 'id': 514}, {'image_count': 101, 'id': 515}, {'image_count': 3, 'id': 516}, {'image_count': 363, 'id': 517}, {'image_count': 3, 'id': 518}, {'image_count': 30, 'id': 519}, {'image_count': 18, 'id': 520}, {'image_count': 199, 'id': 521}, {'image_count': 97, 'id': 522}, {'image_count': 32, 'id': 523}, {'image_count': 121, 'id': 524}, {'image_count': 16, 'id': 525}, {'image_count': 12, 'id': 526}, {'image_count': 2, 'id': 527}, {'image_count': 214, 'id': 528}, {'image_count': 48, 'id': 529}, {'image_count': 26, 'id': 530}, {'image_count': 13, 'id': 531}, {'image_count': 4, 'id': 532}, {'image_count': 11, 'id': 533}, {'image_count': 171, 'id': 534}, {'image_count': 7, 'id': 535}, {'image_count': 200, 'id': 536}, {'image_count': 91, 'id': 537}, {'image_count': 9, 'id': 538}, {'image_count': 72, 'id': 539}, {'image_count': 1886, 'id': 540}, {'image_count': 4, 'id': 541}, {'image_count': 1, 'id': 542}, {'image_count': 1, 'id': 543}, {'image_count': 1932, 'id': 544}, {'image_count': 4, 'id': 545}, {'image_count': 56, 'id': 546}, {'image_count': 854, 'id': 547}, {'image_count': 755, 'id': 548}, {'image_count': 1843, 'id': 549}, {'image_count': 96, 'id': 550}, {'image_count': 7, 'id': 551}, {'image_count': 74, 'id': 552}, {'image_count': 66, 'id': 553}, {'image_count': 57, 'id': 554}, {'image_count': 44, 'id': 555}, {'image_count': 1905, 'id': 556}, {'image_count': 4, 'id': 557}, {'image_count': 90, 'id': 558}, {'image_count': 1635, 'id': 559}, {'image_count': 8, 'id': 560}, {'image_count': 5, 'id': 561}, {'image_count': 50, 'id': 562}, {'image_count': 545, 'id': 563}, {'image_count': 20, 'id': 564}, {'image_count': 193, 'id': 565}, {'image_count': 285, 'id': 566}, {'image_count': 3, 'id': 567}, {'image_count': 1, 'id': 568}, {'image_count': 2488, 'id': 569}, {'image_count': 294, 'id': 570}, {'image_count': 3, 'id': 571}, {'image_count': 5, 'id': 572}, {'image_count': 24, 'id': 573}, {'image_count': 2, 'id': 574}, {'image_count': 2, 'id': 575}, {'image_count': 16, 'id': 576}, {'image_count': 8, 'id': 577}, {'image_count': 154, 'id': 578}, {'image_count': 66, 'id': 579}, {'image_count': 1, 'id': 580}, {'image_count': 24, 'id': 581}, {'image_count': 1, 'id': 582}, {'image_count': 4, 'id': 583}, {'image_count': 75, 'id': 584}, {'image_count': 6, 'id': 585}, {'image_count': 126, 'id': 586}, {'image_count': 24, 'id': 587}, {'image_count': 22, 'id': 588}, {'image_count': 1872, 'id': 589}, {'image_count': 16, 'id': 590}, {'image_count': 423, 'id': 591}, {'image_count': 1927, 'id': 592}, {'image_count': 38, 'id': 593}, {'image_count': 3, 'id': 594}, {'image_count': 1945, 'id': 595}, {'image_count': 35, 'id': 596}, {'image_count': 1, 'id': 597}, {'image_count': 13, 'id': 598}, {'image_count': 9, 'id': 599}, {'image_count': 14, 'id': 600}, {'image_count': 37, 'id': 601}, {'image_count': 3, 'id': 602}, {'image_count': 4, 'id': 603}, {'image_count': 100, 'id': 604}, {'image_count': 195, 'id': 605}, {'image_count': 1, 'id': 606}, {'image_count': 12, 'id': 607}, {'image_count': 24, 'id': 608}, {'image_count': 489, 'id': 609}, {'image_count': 10, 'id': 610}, {'image_count': 1921, 'id': 611}, {'image_count': 42, 'id': 612}, {'image_count': 81, 'id': 613}, {'image_count': 894, 'id': 614}, {'image_count': 3839, 'id': 615}, {'image_count': 7, 'id': 616}, {'image_count': 1567, 'id': 617}, {'image_count': 10, 'id': 618}, {'image_count': 8, 'id': 619}, {'image_count': 7, 'id': 620}, {'image_count': 629, 'id': 621}, {'image_count': 89, 'id': 622}, {'image_count': 15, 'id': 623}, {'image_count': 134, 'id': 624}, {'image_count': 4, 'id': 625}, {'image_count': 1802, 'id': 626}, {'image_count': 595, 'id': 627}, {'image_count': 1210, 'id': 628}, {'image_count': 48, 'id': 629}, {'image_count': 418, 'id': 630}, {'image_count': 3050, 'id': 631}, {'image_count': 5, 'id': 632}, {'image_count': 221, 'id': 633}, {'image_count': 10, 'id': 634}, {'image_count': 7, 'id': 635}, {'image_count': 76, 'id': 636}, {'image_count': 22, 'id': 637}, {'image_count': 10, 'id': 638}, {'image_count': 341, 'id': 639}, {'image_count': 1, 'id': 640}, {'image_count': 705, 'id': 641}, {'image_count': 1900, 'id': 642}, {'image_count': 188, 'id': 643}, {'image_count': 227, 'id': 644}, {'image_count': 861, 'id': 645}, {'image_count': 6, 'id': 646}, {'image_count': 115, 'id': 647}, {'image_count': 5, 'id': 648}, {'image_count': 43, 'id': 649}, {'image_count': 14, 'id': 650}, {'image_count': 6, 'id': 651}, {'image_count': 15, 'id': 652}, {'image_count': 1167, 'id': 653}, {'image_count': 15, 'id': 654}, {'image_count': 994, 'id': 655}, {'image_count': 28, 'id': 656}, {'image_count': 2, 'id': 657}, {'image_count': 338, 'id': 658}, {'image_count': 334, 'id': 659}, {'image_count': 15, 'id': 660}, {'image_count': 102, 'id': 661}, {'image_count': 1, 'id': 662}, {'image_count': 8, 'id': 663}, {'image_count': 1, 'id': 664}, {'image_count': 1, 'id': 665}, {'image_count': 28, 'id': 666}, {'image_count': 91, 'id': 667}, {'image_count': 260, 'id': 668}, {'image_count': 131, 'id': 669}, {'image_count': 128, 'id': 670}, {'image_count': 3, 'id': 671}, {'image_count': 10, 'id': 672}, {'image_count': 39, 'id': 673}, {'image_count': 2, 'id': 674}, {'image_count': 925, 'id': 675}, {'image_count': 354, 'id': 676}, {'image_count': 31, 'id': 677}, {'image_count': 10, 'id': 678}, {'image_count': 215, 'id': 679}, {'image_count': 71, 'id': 680}, {'image_count': 43, 'id': 681}, {'image_count': 28, 'id': 682}, {'image_count': 34, 'id': 683}, {'image_count': 16, 'id': 684}, {'image_count': 273, 'id': 685}, {'image_count': 2, 'id': 686}, {'image_count': 1388, 'id': 687}, {'image_count': 4, 'id': 688}, {'image_count': 107, 'id': 689}, {'image_count': 2, 'id': 690}, {'image_count': 1, 'id': 691}, {'image_count': 454, 'id': 692}, {'image_count': 9, 'id': 693}, {'image_count': 1901, 'id': 694}, {'image_count': 61, 'id': 695}, {'image_count': 91, 'id': 696}, {'image_count': 46, 'id': 697}, {'image_count': 1402, 'id': 698}, {'image_count': 74, 'id': 699}, {'image_count': 421, 'id': 700}, {'image_count': 226, 'id': 701}, {'image_count': 10, 'id': 702}, {'image_count': 3011, 'id': 703}, {'image_count': 261, 'id': 704}, {'image_count': 1671, 'id': 705}, {'image_count': 293, 'id': 706}, {'image_count': 62, 'id': 707}, {'image_count': 814, 'id': 708}, {'image_count': 407, 'id': 709}, {'image_count': 6, 'id': 710}, {'image_count': 16, 'id': 711}, {'image_count': 7, 'id': 712}, {'image_count': 1791, 'id': 713}, {'image_count': 2, 'id': 714}, {'image_count': 1915, 'id': 715}, {'image_count': 3327, 'id': 716}, {'image_count': 13, 'id': 717}, {'image_count': 16, 'id': 718}, {'image_count': 448, 'id': 719}, {'image_count': 12, 'id': 720}, {'image_count': 18, 'id': 721}, {'image_count': 4, 'id': 722}, {'image_count': 71, 'id': 723}, {'image_count': 189, 'id': 724}, {'image_count': 74, 'id': 725}, {'image_count': 103, 'id': 726}, {'image_count': 3, 'id': 727}, {'image_count': 110, 'id': 728}, {'image_count': 5, 'id': 729}, {'image_count': 9, 'id': 730}, {'image_count': 15, 'id': 731}, {'image_count': 25, 'id': 732}, {'image_count': 7, 'id': 733}, {'image_count': 647, 'id': 734}, {'image_count': 1510, 'id': 735}, {'image_count': 100, 'id': 736}, {'image_count': 47, 'id': 737}, {'image_count': 121, 'id': 738}, {'image_count': 2530, 'id': 739}, {'image_count': 73, 'id': 740}, {'image_count': 49, 'id': 741}, {'image_count': 23, 'id': 742}, {'image_count': 4, 'id': 743}, {'image_count': 62, 'id': 744}, {'image_count': 118, 'id': 745}, {'image_count': 99, 'id': 746}, {'image_count': 40, 'id': 747}, {'image_count': 1036, 'id': 748}, {'image_count': 105, 'id': 749}, {'image_count': 21, 'id': 750}, {'image_count': 229, 'id': 751}, {'image_count': 7, 'id': 752}, {'image_count': 72, 'id': 753}, {'image_count': 9, 'id': 754}, {'image_count': 10, 'id': 755}, {'image_count': 328, 'id': 756}, {'image_count': 468, 'id': 757}, {'image_count': 1, 'id': 758}, {'image_count': 2, 'id': 759}, {'image_count': 24, 'id': 760}, {'image_count': 11, 'id': 761}, {'image_count': 72, 'id': 762}, {'image_count': 17, 'id': 763}, {'image_count': 10, 'id': 764}, {'image_count': 17, 'id': 765}, {'image_count': 626, 'id': 766}, {'image_count': 47, 'id': 767}, {'image_count': 93, 'id': 768}, {'image_count': 1, 'id': 769}, {'image_count': 12, 'id': 770}, {'image_count': 228, 'id': 771}, {'image_count': 5, 'id': 772}, {'image_count': 76, 'id': 773}, {'image_count': 71, 'id': 774}, {'image_count': 30, 'id': 775}, {'image_count': 109, 'id': 776}, {'image_count': 14, 'id': 777}, {'image_count': 1, 'id': 778}, {'image_count': 8, 'id': 779}, {'image_count': 26, 'id': 780}, {'image_count': 339, 'id': 781}, {'image_count': 153, 'id': 782}, {'image_count': 2, 'id': 783}, {'image_count': 3, 'id': 784}, {'image_count': 8, 'id': 785}, {'image_count': 47, 'id': 786}, {'image_count': 8, 'id': 787}, {'image_count': 6, 'id': 788}, {'image_count': 116, 'id': 789}, {'image_count': 69, 'id': 790}, {'image_count': 13, 'id': 791}, {'image_count': 6, 'id': 792}, {'image_count': 54790, 'id': 793}, {'image_count': 79, 'id': 794}, {'image_count': 14, 'id': 795}, {'image_count': 7, 'id': 796}, {'image_count': 20, 'id': 797}, {'image_count': 114, 'id': 798}, {'image_count': 221, 'id': 799}, {'image_count': 502, 'id': 800}, {'image_count': 62, 'id': 801}, {'image_count': 87, 'id': 802}, {'image_count': 4, 'id': 803}, {'image_count': 1912, 'id': 804}, {'image_count': 7, 'id': 805}, {'image_count': 186, 'id': 806}, {'image_count': 18, 'id': 807}, {'image_count': 4, 'id': 808}, {'image_count': 3, 'id': 809}, {'image_count': 7, 'id': 810}, {'image_count': 1413, 'id': 811}, {'image_count': 7, 'id': 812}, {'image_count': 12, 'id': 813}, {'image_count': 248, 'id': 814}, {'image_count': 4, 'id': 815}, {'image_count': 2732, 'id': 816}, {'image_count': 529, 'id': 817}, {'image_count': 1932, 'id': 818}, {'image_count': 50, 'id': 819}, {'image_count': 3, 'id': 820}, {'image_count': 28, 'id': 821}, {'image_count': 10, 'id': 822}, {'image_count': 5, 'id': 823}, {'image_count': 5, 'id': 824}, {'image_count': 18, 'id': 825}, {'image_count': 14, 'id': 826}, {'image_count': 1890, 'id': 827}, {'image_count': 660, 'id': 828}, {'image_count': 8, 'id': 829}, {'image_count': 25, 'id': 830}, {'image_count': 10, 'id': 831}, {'image_count': 218, 'id': 832}, {'image_count': 36, 'id': 833}, {'image_count': 16, 'id': 834}, {'image_count': 808, 'id': 835}, {'image_count': 479, 'id': 836}, {'image_count': 3999, 'id': 837}, {'image_count': 307, 'id': 838}, {'image_count': 57, 'id': 839}, {'image_count': 28, 'id': 840}, {'image_count': 80, 'id': 841}, {'image_count': 11, 'id': 842}, {'image_count': 92, 'id': 843}, {'image_count': 20, 'id': 844}, {'image_count': 194, 'id': 845}, {'image_count': 23, 'id': 846}, {'image_count': 52, 'id': 847}, {'image_count': 673, 'id': 848}, {'image_count': 2, 'id': 849}, {'image_count': 2, 'id': 850}, {'image_count': 1, 'id': 851}, {'image_count': 2, 'id': 852}, {'image_count': 8, 'id': 853}, {'image_count': 80, 'id': 854}, {'image_count': 3, 'id': 855}, {'image_count': 3, 'id': 856}, {'image_count': 15, 'id': 857}, {'image_count': 2, 'id': 858}, {'image_count': 10, 'id': 859}, {'image_count': 386, 'id': 860}, {'image_count': 65, 'id': 861}, {'image_count': 3, 'id': 862}, {'image_count': 35, 'id': 863}, {'image_count': 5, 'id': 864}, {'image_count': 180, 'id': 865}, {'image_count': 99, 'id': 866}, {'image_count': 49, 'id': 867}, {'image_count': 28, 'id': 868}, {'image_count': 1, 'id': 869}, {'image_count': 52, 'id': 870}, {'image_count': 36, 'id': 871}, {'image_count': 70, 'id': 872}, {'image_count': 6, 'id': 873}, {'image_count': 29, 'id': 874}, {'image_count': 24, 'id': 875}, {'image_count': 1115, 'id': 876}, {'image_count': 61, 'id': 877}, {'image_count': 18, 'id': 878}, {'image_count': 18, 'id': 879}, {'image_count': 665, 'id': 880}, {'image_count': 2753, 'id': 881}, {'image_count': 29, 'id': 882}, {'image_count': 8, 'id': 883}, {'image_count': 14, 'id': 884}, {'image_count': 1622, 'id': 885}, {'image_count': 2, 'id': 886}, {'image_count': 3, 'id': 887}, {'image_count': 32, 'id': 888}, {'image_count': 55, 'id': 889}, {'image_count': 1, 'id': 890}, {'image_count': 10, 'id': 891}, {'image_count': 10, 'id': 892}, {'image_count': 47, 'id': 893}, {'image_count': 3, 'id': 894}, {'image_count': 29, 'id': 895}, {'image_count': 342, 'id': 896}, {'image_count': 25, 'id': 897}, {'image_count': 1469, 'id': 898}, {'image_count': 521, 'id': 899}, {'image_count': 347, 'id': 900}, {'image_count': 35, 'id': 901}, {'image_count': 7, 'id': 902}, {'image_count': 207, 'id': 903}, {'image_count': 108, 'id': 904}, {'image_count': 2, 'id': 905}, {'image_count': 34, 'id': 906}, {'image_count': 12, 'id': 907}, {'image_count': 10, 'id': 908}, {'image_count': 13, 'id': 909}, {'image_count': 361, 'id': 910}, {'image_count': 1023, 'id': 911}, {'image_count': 2074, 'id': 912}, {'image_count': 2, 'id': 913}, {'image_count': 5, 'id': 914}, {'image_count': 247, 'id': 915}, {'image_count': 1197, 'id': 916}, {'image_count': 4, 'id': 917}, {'image_count': 8, 'id': 918}, {'image_count': 158, 'id': 919}, {'image_count': 3, 'id': 920}, {'image_count': 752, 'id': 921}, {'image_count': 64, 'id': 922}, {'image_count': 840, 'id': 923}, {'image_count': 143, 'id': 924}, {'image_count': 1, 'id': 925}, {'image_count': 49, 'id': 926}, {'image_count': 126, 'id': 927}, {'image_count': 76, 'id': 928}, {'image_count': 11, 'id': 929}, {'image_count': 11, 'id': 930}, {'image_count': 4, 'id': 931}, {'image_count': 39, 'id': 932}, {'image_count': 11, 'id': 933}, {'image_count': 13, 'id': 934}, {'image_count': 91, 'id': 935}, {'image_count': 14, 'id': 936}, {'image_count': 5, 'id': 937}, {'image_count': 3, 'id': 938}, {'image_count': 10, 'id': 939}, {'image_count': 18, 'id': 940}, {'image_count': 9, 'id': 941}, {'image_count': 6, 'id': 942}, {'image_count': 1283, 'id': 943}, {'image_count': 2, 'id': 944}, {'image_count': 1, 'id': 945}, {'image_count': 19, 'id': 946}, {'image_count': 1942, 'id': 947}, {'image_count': 1916, 'id': 948}, {'image_count': 139, 'id': 949}, {'image_count': 43, 'id': 950}, {'image_count': 1969, 'id': 951}, {'image_count': 5, 'id': 952}, {'image_count': 134, 'id': 953}, {'image_count': 74, 'id': 954}, {'image_count': 381, 'id': 955}, {'image_count': 1, 'id': 956}, {'image_count': 381, 'id': 957}, {'image_count': 6, 'id': 958}, {'image_count': 1826, 'id': 959}, {'image_count': 28, 'id': 960}, {'image_count': 4082, 'id': 961}, {'image_count': 2943, 'id': 962}, {'image_count': 16, 'id': 963}, {'image_count': 2716, 'id': 964}, {'image_count': 1789, 'id': 965}, {'image_count': 401, 'id': 966}, {'image_count': 1968, 'id': 967}, {'image_count': 1167, 'id': 968}, {'image_count': 1, 'id': 969}, {'image_count': 56, 'id': 970}, {'image_count': 17, 'id': 971}, {'image_count': 1, 'id': 972}, {'image_count': 58, 'id': 973}, {'image_count': 9, 'id': 974}, {'image_count': 8, 'id': 975}, {'image_count': 1438, 'id': 976}, {'image_count': 31, 'id': 977}, {'image_count': 16, 'id': 978}, {'image_count': 491, 'id': 979}, {'image_count': 432, 'id': 980}, {'image_count': 1945, 'id': 981}, {'image_count': 3826, 'id': 982}, {'image_count': 5, 'id': 983}, {'image_count': 28, 'id': 984}, {'image_count': 7, 'id': 985}, {'image_count': 146, 'id': 986}, {'image_count': 1, 'id': 987}, {'image_count': 25, 'id': 988}, {'image_count': 22, 'id': 989}, {'image_count': 1, 'id': 990}, {'image_count': 10, 'id': 991}, {'image_count': 9, 'id': 992}, {'image_count': 308, 'id': 993}, {'image_count': 4, 'id': 994}, {'image_count': 1969, 'id': 995}, {'image_count': 45, 'id': 996}, {'image_count': 12, 'id': 997}, {'image_count': 1, 'id': 998}, {'image_count': 85, 'id': 999}, {'image_count': 3117, 'id': 1000}, {'image_count': 11, 'id': 1001}, {'image_count': 60, 'id': 1002}, {'image_count': 1, 'id': 1003}, {'image_count': 16, 'id': 1004}, {'image_count': 1, 'id': 1005}, {'image_count': 65, 'id': 1006}, {'image_count': 13, 'id': 1007}, {'image_count': 655, 'id': 1008}, {'image_count': 51, 'id': 1009}, {'image_count': 1, 'id': 1010}, {'image_count': 673, 'id': 1011}, {'image_count': 5, 'id': 1012}, {'image_count': 36, 'id': 1013}, {'image_count': 54, 'id': 1014}, {'image_count': 5, 'id': 1015}, {'image_count': 8, 'id': 1016}, {'image_count': 305, 'id': 1017}, {'image_count': 297, 'id': 1018}, {'image_count': 1508, 'id': 1019}, {'image_count': 223, 'id': 1020}, {'image_count': 1037, 'id': 1021}, {'image_count': 63, 'id': 1022}, {'image_count': 1881, 'id': 1023}, {'image_count': 507, 'id': 1024}, {'image_count': 333, 'id': 1025}, {'image_count': 1911, 'id': 1026}, {'image_count': 1765, 'id': 1027}, {'image_count': 1, 'id': 1028}, {'image_count': 5, 'id': 1029}, {'image_count': 1, 'id': 1030}, {'image_count': 9, 'id': 1031}, {'image_count': 2, 'id': 1032}, {'image_count': 151, 'id': 1033}, {'image_count': 82, 'id': 1034}, {'image_count': 1931, 'id': 1035}, {'image_count': 41, 'id': 1036}, {'image_count': 2877, 'id': 1037}, {'image_count': 24, 'id': 1038}, {'image_count': 22, 'id': 1039}, {'image_count': 35, 'id': 1040}, {'image_count': 69, 'id': 1041}, {'image_count': 962, 'id': 1042}, {'image_count': 588, 'id': 1043}, {'image_count': 21, 'id': 1044}, {'image_count': 825, 'id': 1045}, {'image_count': 52, 'id': 1046}, {'image_count': 5, 'id': 1047}, {'image_count': 5, 'id': 1048}, {'image_count': 5, 'id': 1049}, {'image_count': 1860, 'id': 1050}, {'image_count': 56, 'id': 1051}, {'image_count': 1582, 'id': 1052}, {'image_count': 7, 'id': 1053}, {'image_count': 2, 'id': 1054}, {'image_count': 1562, 'id': 1055}, {'image_count': 1885, 'id': 1056}, {'image_count': 1, 'id': 1057}, {'image_count': 5, 'id': 1058}, {'image_count': 137, 'id': 1059}, {'image_count': 1094, 'id': 1060}, {'image_count': 134, 'id': 1061}, {'image_count': 29, 'id': 1062}, {'image_count': 22, 'id': 1063}, {'image_count': 522, 'id': 1064}, {'image_count': 50, 'id': 1065}, {'image_count': 68, 'id': 1066}, {'image_count': 16, 'id': 1067}, {'image_count': 40, 'id': 1068}, {'image_count': 35, 'id': 1069}, {'image_count': 135, 'id': 1070}, {'image_count': 1866, 'id': 1071}, {'image_count': 772, 'id': 1072}, {'image_count': 50, 'id': 1073}, {'image_count': 1015, 'id': 1074}, {'image_count': 1, 'id': 1075}, {'image_count': 65, 'id': 1076}, {'image_count': 3978, 'id': 1077}, {'image_count': 1302, 'id': 1078}, {'image_count': 2925, 'id': 1079}, {'image_count': 2, 'id': 1080}, {'image_count': 29, 'id': 1081}, {'image_count': 36, 'id': 1082}, {'image_count': 138, 'id': 1083}, {'image_count': 4, 'id': 1084}, {'image_count': 67, 'id': 1085}, {'image_count': 26, 'id': 1086}, {'image_count': 25, 'id': 1087}, {'image_count': 33, 'id': 1088}, {'image_count': 37, 'id': 1089}, {'image_count': 50, 'id': 1090}, {'image_count': 270, 'id': 1091}, {'image_count': 12, 'id': 1092}, {'image_count': 316, 'id': 1093}, {'image_count': 41, 'id': 1094}, {'image_count': 299, 'id': 1095}, {'image_count': 105, 'id': 1096}, {'image_count': 2879, 'id': 1097}, {'image_count': 1021, 'id': 1098}, {'image_count': 1213, 'id': 1099}, {'image_count': 172, 'id': 1100}, {'image_count': 28, 'id': 1101}, {'image_count': 899, 'id': 1102}, {'image_count': 187, 'id': 1103}, {'image_count': 147, 'id': 1104}, {'image_count': 136, 'id': 1105}, {'image_count': 34, 'id': 1106}, {'image_count': 41, 'id': 1107}, {'image_count': 636, 'id': 1108}, {'image_count': 570, 'id': 1109}, {'image_count': 1149, 'id': 1110}, {'image_count': 61, 'id': 1111}, {'image_count': 3556, 'id': 1112}, {'image_count': 18, 'id': 1113}, {'image_count': 143, 'id': 1114}, {'image_count': 2951, 'id': 1115}, {'image_count': 7, 'id': 1116}, {'image_count': 943, 'id': 1117}, {'image_count': 6, 'id': 1118}, {'image_count': 1, 'id': 1119}, {'image_count': 11, 'id': 1120}, {'image_count': 101, 'id': 1121}, {'image_count': 1909, 'id': 1122}, {'image_count': 5302, 'id': 1123}, {'image_count': 1, 'id': 1124}, {'image_count': 44, 'id': 1125}, {'image_count': 3, 'id': 1126}, {'image_count': 44, 'id': 1127}, {'image_count': 31, 'id': 1128}, {'image_count': 7, 'id': 1129}, {'image_count': 20, 'id': 1130}, {'image_count': 11, 'id': 1131}, {'image_count': 13, 'id': 1132}, {'image_count': 3452, 'id': 1133}, {'image_count': 113, 'id': 1134}, {'image_count': 2, 'id': 1135}, {'image_count': 139, 'id': 1136}, {'image_count': 12, 'id': 1137}, {'image_count': 37, 'id': 1138}, {'image_count': 3213, 'id': 1139}, {'image_count': 47, 'id': 1140}, {'image_count': 1468, 'id': 1141}, {'image_count': 729, 'id': 1142}, {'image_count': 24, 'id': 1143}, {'image_count': 1, 'id': 1144}, {'image_count': 10, 'id': 1145}, {'image_count': 3, 'id': 1146}, {'image_count': 14, 'id': 1147}, {'image_count': 4, 'id': 1148}, {'image_count': 29, 'id': 1149}, {'image_count': 4, 'id': 1150}, {'image_count': 70, 'id': 1151}, {'image_count': 46, 'id': 1152}, {'image_count': 14, 'id': 1153}, {'image_count': 48, 'id': 1154}, {'image_count': 1855, 'id': 1155}, {'image_count': 113, 'id': 1156}, {'image_count': 1, 'id': 1157}, {'image_count': 1, 'id': 1158}, {'image_count': 10, 'id': 1159}, {'image_count': 54, 'id': 1160}, {'image_count': 1923, 'id': 1161}, {'image_count': 630, 'id': 1162}, {'image_count': 31, 'id': 1163}, {'image_count': 69, 'id': 1164}, {'image_count': 7, 'id': 1165}, {'image_count': 11, 'id': 1166}, {'image_count': 1, 'id': 1167}, {'image_count': 30, 'id': 1168}, {'image_count': 50, 'id': 1169}, {'image_count': 45, 'id': 1170}, {'image_count': 28, 'id': 1171}, {'image_count': 114, 'id': 1172}, {'image_count': 193, 'id': 1173}, {'image_count': 21, 'id': 1174}, {'image_count': 91, 'id': 1175}, {'image_count': 31, 'id': 1176}, {'image_count': 1469, 'id': 1177}, {'image_count': 1924, 'id': 1178}, {'image_count': 87, 'id': 1179}, {'image_count': 77, 'id': 1180}, {'image_count': 11, 'id': 1181}, {'image_count': 47, 'id': 1182}, {'image_count': 21, 'id': 1183}, {'image_count': 47, 'id': 1184}, {'image_count': 70, 'id': 1185}, {'image_count': 1838, 'id': 1186}, {'image_count': 19, 'id': 1187}, {'image_count': 531, 'id': 1188}, {'image_count': 11, 'id': 1189}, {'image_count': 2179, 'id': 1190}, {'image_count': 113, 'id': 1191}, {'image_count': 26, 'id': 1192}, {'image_count': 5, 'id': 1193}, {'image_count': 56, 'id': 1194}, {'image_count': 73, 'id': 1195}, {'image_count': 32, 'id': 1196}, {'image_count': 128, 'id': 1197}, {'image_count': 623, 'id': 1198}, {'image_count': 12, 'id': 1199}, {'image_count': 52, 'id': 1200}, {'image_count': 11, 'id': 1201}, {'image_count': 1687, 'id': 1202}, {'image_count': 81, 'id': 1203}] # noqa# fmt: on123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799import os
from detectron2.data.datasets.register_coco import register_coco_instances
OBJECTS365_CATEGORIES_FIXNAME = [ {"id": 1, "name": "Person"}, {"id": 2, "name": "Sneakers"}, {"id": 3, "name": "Chair"}, {"id": 4, "name": "Other Shoes"}, {"id": 5, "name": "Hat"}, {"id": 6, "name": "Car"}, {"id": 7, "name": "Lamp"}, {"id": 8, "name": "Glasses"}, {"id": 9, "name": "Bottle"}, {"id": 10, "name": "Desk"}, {"id": 11, "name": "Cup"}, {"id": 12, "name": "Street Lights"}, {"id": 13, "name": "Cabinet/shelf"}, {"id": 14, "name": "Handbag/Satchel"}, {"id": 15, "name": "Bracelet"}, {"id": 16, "name": "Plate"}, {"id": 17, "name": "Picture/Frame"}, {"id": 18, "name": "Helmet"}, {"id": 19, "name": "Book"}, {"id": 20, "name": "Gloves"}, {"id": 21, "name": "Storage box"}, {"id": 22, "name": "Boat"}, {"id": 23, "name": "Leather Shoes"}, {"id": 24, "name": "Flower"}, {"id": 25, "name": "Bench"}, {"id": 26, "name": "Potted Plant"}, {"id": 27, "name": "Bowl/Basin"}, {"id": 28, "name": "Flag"}, {"id": 29, "name": "Pillow"}, {"id": 30, "name": "Boots"}, {"id": 31, "name": "Vase"}, {"id": 32, "name": "Microphone"}, {"id": 33, "name": "Necklace"}, {"id": 34, "name": "Ring"}, {"id": 35, "name": "SUV"}, {"id": 36, "name": "Wine Glass"}, {"id": 37, "name": "Belt"}, {"id": 38, "name": "Monitor/TV"}, {"id": 39, "name": "Backpack"}, {"id": 40, "name": "Umbrella"}, {"id": 41, "name": "Traffic Light"}, {"id": 42, "name": "Speaker"}, {"id": 43, "name": "Watch"}, {"id": 44, "name": "Tie"}, {"id": 45, "name": "Trash bin Can"}, {"id": 46, "name": "Slippers"}, {"id": 47, "name": "Bicycle"}, {"id": 48, "name": "Stool"}, {"id": 49, "name": "Barrel/bucket"}, {"id": 50, "name": "Van"}, {"id": 51, "name": "Couch"}, {"id": 52, "name": "Sandals"}, {"id": 53, "name": "Basket"}, {"id": 54, "name": "Drum"}, {"id": 55, "name": "Pen/Pencil"}, {"id": 56, "name": "Bus"}, {"id": 57, "name": "Wild Bird"}, {"id": 58, "name": "High Heels"}, {"id": 59, "name": "Motorcycle"}, {"id": 60, "name": "Guitar"}, {"id": 61, "name": "Carpet"}, {"id": 62, "name": "Cell Phone"}, {"id": 63, "name": "Bread"}, {"id": 64, "name": "Camera"}, {"id": 65, "name": "Canned"}, {"id": 66, "name": "Truck"}, {"id": 67, "name": "Traffic cone"}, {"id": 68, "name": "Cymbal"}, {"id": 69, "name": "Lifesaver"}, {"id": 70, "name": "Towel"}, {"id": 71, "name": "Stuffed Toy"}, {"id": 72, "name": "Candle"}, {"id": 73, "name": "Sailboat"}, {"id": 74, "name": "Laptop"}, {"id": 75, "name": "Awning"}, {"id": 76, "name": "Bed"}, {"id": 77, "name": "Faucet"}, {"id": 78, "name": "Tent"}, {"id": 79, "name": "Horse"}, {"id": 80, "name": "Mirror"}, {"id": 81, "name": "Power outlet"}, {"id": 82, "name": "Sink"}, {"id": 83, "name": "Apple"}, {"id": 84, "name": "Air Conditioner"}, {"id": 85, "name": "Knife"}, {"id": 86, "name": "Hockey Stick"}, {"id": 87, "name": "Paddle"}, {"id": 88, "name": "Pickup Truck"}, {"id": 89, "name": "Fork"}, {"id": 90, "name": "Traffic Sign"}, {"id": 91, "name": "Ballon"}, {"id": 92, "name": "Tripod"}, {"id": 93, "name": "Dog"}, {"id": 94, "name": "Spoon"}, {"id": 95, "name": "Clock"}, {"id": 96, "name": "Pot"}, {"id": 97, "name": "Cow"}, {"id": 98, "name": "Cake"}, {"id": 99, "name": "Dining Table"}, {"id": 100, "name": "Sheep"}, {"id": 101, "name": "Hanger"}, {"id": 102, "name": "Blackboard/Whiteboard"}, {"id": 103, "name": "Napkin"}, {"id": 104, "name": "Other Fish"}, {"id": 105, "name": "Orange/Tangerine"}, {"id": 106, "name": "Toiletry"}, {"id": 107, "name": "Keyboard"}, {"id": 108, "name": "Tomato"}, {"id": 109, "name": "Lantern"}, {"id": 110, "name": "Machinery Vehicle"}, {"id": 111, "name": "Fan"}, {"id": 112, "name": "Green Vegetables"}, {"id": 113, "name": "Banana"}, {"id": 114, "name": "Baseball Glove"}, {"id": 115, "name": "Airplane"}, {"id": 116, "name": "Mouse"}, {"id": 117, "name": "Train"}, {"id": 118, "name": "Pumpkin"}, {"id": 119, "name": "Soccer"}, {"id": 120, "name": "Skiboard"}, {"id": 121, "name": "Luggage"}, {"id": 122, "name": "Nightstand"}, {"id": 123, "name": "Teapot"}, {"id": 124, "name": "Telephone"}, {"id": 125, "name": "Trolley"}, {"id": 126, "name": "Head Phone"}, {"id": 127, "name": "Sports Car"}, {"id": 128, "name": "Stop Sign"}, {"id": 129, "name": "Dessert"}, {"id": 130, "name": "Scooter"}, {"id": 131, "name": "Stroller"}, {"id": 132, "name": "Crane"}, {"id": 133, "name": "Remote"}, {"id": 134, "name": "Refrigerator"}, {"id": 135, "name": "Oven"}, {"id": 136, "name": "Lemon"}, {"id": 137, "name": "Duck"}, {"id": 138, "name": "Baseball Bat"}, {"id": 139, "name": "Surveillance Camera"}, {"id": 140, "name": "Cat"}, {"id": 141, "name": "Jug"}, {"id": 142, "name": "Broccoli"}, {"id": 143, "name": "Piano"}, {"id": 144, "name": "Pizza"}, {"id": 145, "name": "Elephant"}, {"id": 146, "name": "Skateboard"}, {"id": 147, "name": "Surfboard"}, {"id": 148, "name": "Gun"}, {"id": 149, "name": "Skating and Skiing shoes"}, {"id": 150, "name": "Gas stove"}, {"id": 151, "name": "Donut"}, {"id": 152, "name": "Bow Tie"}, {"id": 153, "name": "Carrot"}, {"id": 154, "name": "Toilet"}, {"id": 155, "name": "Kite"}, {"id": 156, "name": "Strawberry"}, {"id": 157, "name": "Other Balls"}, {"id": 158, "name": "Shovel"}, {"id": 159, "name": "Pepper"}, {"id": 160, "name": "Computer Box"}, {"id": 161, "name": "Toilet Paper"}, {"id": 162, "name": "Cleaning Products"}, {"id": 163, "name": "Chopsticks"}, {"id": 164, "name": "Microwave"}, {"id": 165, "name": "Pigeon"}, {"id": 166, "name": "Baseball"}, {"id": 167, "name": "Cutting/chopping Board"}, {"id": 168, "name": "Coffee Table"}, {"id": 169, "name": "Side Table"}, {"id": 170, "name": "Scissors"}, {"id": 171, "name": "Marker"}, {"id": 172, "name": "Pie"}, {"id": 173, "name": "Ladder"}, {"id": 174, "name": "Snowboard"}, {"id": 175, "name": "Cookies"}, {"id": 176, "name": "Radiator"}, {"id": 177, "name": "Fire Hydrant"}, {"id": 178, "name": "Basketball"}, {"id": 179, "name": "Zebra"}, {"id": 180, "name": "Grape"}, {"id": 181, "name": "Giraffe"}, {"id": 182, "name": "Potato"}, {"id": 183, "name": "Sausage"}, {"id": 184, "name": "Tricycle"}, {"id": 185, "name": "Violin"}, {"id": 186, "name": "Egg"}, {"id": 187, "name": "Fire Extinguisher"}, {"id": 188, "name": "Candy"}, {"id": 189, "name": "Fire Truck"}, {"id": 190, "name": "Billards"}, {"id": 191, "name": "Converter"}, {"id": 192, "name": "Bathtub"}, {"id": 193, "name": "Wheelchair"}, {"id": 194, "name": "Golf Club"}, {"id": 195, "name": "Briefcase"}, {"id": 196, "name": "Cucumber"}, {"id": 197, "name": "Cigar/Cigarette "}, {"id": 198, "name": "Paint Brush"}, {"id": 199, "name": "Pear"}, {"id": 200, "name": "Heavy Truck"}, {"id": 201, "name": "Hamburger"}, {"id": 202, "name": "Extractor"}, {"id": 203, "name": "Extension Cord"}, {"id": 204, "name": "Tong"}, {"id": 205, "name": "Tennis Racket"}, {"id": 206, "name": "Folder"}, {"id": 207, "name": "American Football"}, {"id": 208, "name": "earphone"}, {"id": 209, "name": "Mask"}, {"id": 210, "name": "Kettle"}, {"id": 211, "name": "Tennis"}, {"id": 212, "name": "Ship"}, {"id": 213, "name": "Swing"}, {"id": 214, "name": "Coffee Machine"}, {"id": 215, "name": "Slide"}, {"id": 216, "name": "Carriage"}, {"id": 217, "name": "Onion"}, {"id": 218, "name": "Green beans"}, {"id": 219, "name": "Projector"}, {"id": 220, "name": "Frisbee"}, {"id": 221, "name": "Washing Machine/Drying Machine"}, {"id": 222, "name": "Chicken"}, {"id": 223, "name": "Printer"}, {"id": 224, "name": "Watermelon"}, {"id": 225, "name": "Saxophone"}, {"id": 226, "name": "Tissue"}, {"id": 227, "name": "Toothbrush"}, {"id": 228, "name": "Ice cream"}, {"id": 229, "name": "Hot air balloon"}, {"id": 230, "name": "Cello"}, {"id": 231, "name": "French Fries"}, {"id": 232, "name": "Scale"}, {"id": 233, "name": "Trophy"}, {"id": 234, "name": "Cabbage"}, {"id": 235, "name": "Hot dog"}, {"id": 236, "name": "Blender"}, {"id": 237, "name": "Peach"}, {"id": 238, "name": "Rice"}, {"id": 239, "name": "Wallet/Purse"}, {"id": 240, "name": "Volleyball"}, {"id": 241, "name": "Deer"}, {"id": 242, "name": "Goose"}, {"id": 243, "name": "Tape"}, {"id": 244, "name": "Tablet"}, {"id": 245, "name": "Cosmetics"}, {"id": 246, "name": "Trumpet"}, {"id": 247, "name": "Pineapple"}, {"id": 248, "name": "Golf Ball"}, {"id": 249, "name": "Ambulance"}, {"id": 250, "name": "Parking meter"}, {"id": 251, "name": "Mango"}, {"id": 252, "name": "Key"}, {"id": 253, "name": "Hurdle"}, {"id": 254, "name": "Fishing Rod"}, {"id": 255, "name": "Medal"}, {"id": 256, "name": "Flute"}, {"id": 257, "name": "Brush"}, {"id": 258, "name": "Penguin"}, {"id": 259, "name": "Megaphone"}, {"id": 260, "name": "Corn"}, {"id": 261, "name": "Lettuce"}, {"id": 262, "name": "Garlic"}, {"id": 263, "name": "Swan"}, {"id": 264, "name": "Helicopter"}, {"id": 265, "name": "Green Onion"}, {"id": 266, "name": "Sandwich"}, {"id": 267, "name": "Nuts"}, {"id": 268, "name": "Speed Limit Sign"}, {"id": 269, "name": "Induction Cooker"}, {"id": 270, "name": "Broom"}, {"id": 271, "name": "Trombone"}, {"id": 272, "name": "Plum"}, {"id": 273, "name": "Rickshaw"}, {"id": 274, "name": "Goldfish"}, {"id": 275, "name": "Kiwi fruit"}, {"id": 276, "name": "Router/modem"}, {"id": 277, "name": "Poker Card"}, {"id": 278, "name": "Toaster"}, {"id": 279, "name": "Shrimp"}, {"id": 280, "name": "Sushi"}, {"id": 281, "name": "Cheese"}, {"id": 282, "name": "Notepaper"}, {"id": 283, "name": "Cherry"}, {"id": 284, "name": "Pliers"}, {"id": 285, "name": "CD"}, {"id": 286, "name": "Pasta"}, {"id": 287, "name": "Hammer"}, {"id": 288, "name": "Cue"}, {"id": 289, "name": "Avocado"}, {"id": 290, "name": "Hami melon"}, {"id": 291, "name": "Flask"}, {"id": 292, "name": "Mushroom"}, {"id": 293, "name": "Screwdriver"}, {"id": 294, "name": "Soap"}, {"id": 295, "name": "Recorder"}, {"id": 296, "name": "Bear"}, {"id": 297, "name": "Eggplant"}, {"id": 298, "name": "Board Eraser"}, {"id": 299, "name": "Coconut"}, {"id": 300, "name": "Tape Measure/ Ruler"}, {"id": 301, "name": "Pig"}, {"id": 302, "name": "Showerhead"}, {"id": 303, "name": "Globe"}, {"id": 304, "name": "Chips"}, {"id": 305, "name": "Steak"}, {"id": 306, "name": "Crosswalk Sign"}, {"id": 307, "name": "Stapler"}, {"id": 308, "name": "Camel"}, {"id": 309, "name": "Formula 1 "}, {"id": 310, "name": "Pomegranate"}, {"id": 311, "name": "Dishwasher"}, {"id": 312, "name": "Crab"}, {"id": 313, "name": "Hoverboard"}, {"id": 314, "name": "Meatball"}, {"id": 315, "name": "Rice Cooker"}, {"id": 316, "name": "Tuba"}, {"id": 317, "name": "Calculator"}, {"id": 318, "name": "Papaya"}, {"id": 319, "name": "Antelope"}, {"id": 320, "name": "Parrot"}, {"id": 321, "name": "Seal"}, {"id": 322, "name": "Butterfly"}, {"id": 323, "name": "Dumbbell"}, {"id": 324, "name": "Donkey"}, {"id": 325, "name": "Lion"}, {"id": 326, "name": "Urinal"}, {"id": 327, "name": "Dolphin"}, {"id": 328, "name": "Electric Drill"}, {"id": 329, "name": "Hair Dryer"}, {"id": 330, "name": "Egg tart"}, {"id": 331, "name": "Jellyfish"}, {"id": 332, "name": "Treadmill"}, {"id": 333, "name": "Lighter"}, {"id": 334, "name": "Grapefruit"}, {"id": 335, "name": "Game board"}, {"id": 336, "name": "Mop"}, {"id": 337, "name": "Radish"}, {"id": 338, "name": "Baozi"}, {"id": 339, "name": "Target"}, {"id": 340, "name": "French"}, {"id": 341, "name": "Spring Rolls"}, {"id": 342, "name": "Monkey"}, {"id": 343, "name": "Rabbit"}, {"id": 344, "name": "Pencil Case"}, {"id": 345, "name": "Yak"}, {"id": 346, "name": "Red Cabbage"}, {"id": 347, "name": "Binoculars"}, {"id": 348, "name": "Asparagus"}, {"id": 349, "name": "Barbell"}, {"id": 350, "name": "Scallop"}, {"id": 351, "name": "Noddles"}, {"id": 352, "name": "Comb"}, {"id": 353, "name": "Dumpling"}, {"id": 354, "name": "Oyster"}, {"id": 355, "name": "Table Tennis paddle"}, {"id": 356, "name": "Cosmetics Brush/Eyeliner Pencil"}, {"id": 357, "name": "Chainsaw"}, {"id": 358, "name": "Eraser"}, {"id": 359, "name": "Lobster"}, {"id": 360, "name": "Durian"}, {"id": 361, "name": "Okra"}, {"id": 362, "name": "Lipstick"}, {"id": 363, "name": "Cosmetics Mirror"}, {"id": 364, "name": "Curling"}, {"id": 365, "name": "Table Tennis "},]
OBJECTS365_CATEGORIES = [ {"id": 1, "name": "Person"}, {"id": 2, "name": "Sneakers"}, {"id": 3, "name": "Chair"}, {"id": 4, "name": "Other Shoes"}, {"id": 5, "name": "Hat"}, {"id": 6, "name": "Car"}, {"id": 7, "name": "Lamp"}, {"id": 8, "name": "Glasses"}, {"id": 9, "name": "Bottle"}, {"id": 10, "name": "Desk"}, {"id": 11, "name": "Cup"}, {"id": 12, "name": "Street Lights"}, {"id": 13, "name": "Cabinet/shelf"}, {"id": 14, "name": "Handbag/Satchel"}, {"id": 15, "name": "Bracelet"}, {"id": 16, "name": "Plate"}, {"id": 17, "name": "Picture/Frame"}, {"id": 18, "name": "Helmet"}, {"id": 19, "name": "Book"}, {"id": 20, "name": "Gloves"}, {"id": 21, "name": "Storage box"}, {"id": 22, "name": "Boat"}, {"id": 23, "name": "Leather Shoes"}, {"id": 24, "name": "Flower"}, {"id": 25, "name": "Bench"}, {"id": 26, "name": "Potted Plant"}, {"id": 27, "name": "Bowl/Basin"}, {"id": 28, "name": "Flag"}, {"id": 29, "name": "Pillow"}, {"id": 30, "name": "Boots"}, {"id": 31, "name": "Vase"}, {"id": 32, "name": "Microphone"}, {"id": 33, "name": "Necklace"}, {"id": 34, "name": "Ring"}, {"id": 35, "name": "SUV"}, {"id": 36, "name": "Wine Glass"}, {"id": 37, "name": "Belt"}, {"id": 38, "name": "Moniter/TV"}, {"id": 39, "name": "Backpack"}, {"id": 40, "name": "Umbrella"}, {"id": 41, "name": "Traffic Light"}, {"id": 42, "name": "Speaker"}, {"id": 43, "name": "Watch"}, {"id": 44, "name": "Tie"}, {"id": 45, "name": "Trash bin Can"}, {"id": 46, "name": "Slippers"}, {"id": 47, "name": "Bicycle"}, {"id": 48, "name": "Stool"}, {"id": 49, "name": "Barrel/bucket"}, {"id": 50, "name": "Van"}, {"id": 51, "name": "Couch"}, {"id": 52, "name": "Sandals"}, {"id": 53, "name": "Bakset"}, {"id": 54, "name": "Drum"}, {"id": 55, "name": "Pen/Pencil"}, {"id": 56, "name": "Bus"}, {"id": 57, "name": "Wild Bird"}, {"id": 58, "name": "High Heels"}, {"id": 59, "name": "Motorcycle"}, {"id": 60, "name": "Guitar"}, {"id": 61, "name": "Carpet"}, {"id": 62, "name": "Cell Phone"}, {"id": 63, "name": "Bread"}, {"id": 64, "name": "Camera"}, {"id": 65, "name": "Canned"}, {"id": 66, "name": "Truck"}, {"id": 67, "name": "Traffic cone"}, {"id": 68, "name": "Cymbal"}, {"id": 69, "name": "Lifesaver"}, {"id": 70, "name": "Towel"}, {"id": 71, "name": "Stuffed Toy"}, {"id": 72, "name": "Candle"}, {"id": 73, "name": "Sailboat"}, {"id": 74, "name": "Laptop"}, {"id": 75, "name": "Awning"}, {"id": 76, "name": "Bed"}, {"id": 77, "name": "Faucet"}, {"id": 78, "name": "Tent"}, {"id": 79, "name": "Horse"}, {"id": 80, "name": "Mirror"}, {"id": 81, "name": "Power outlet"}, {"id": 82, "name": "Sink"}, {"id": 83, "name": "Apple"}, {"id": 84, "name": "Air Conditioner"}, {"id": 85, "name": "Knife"}, {"id": 86, "name": "Hockey Stick"}, {"id": 87, "name": "Paddle"}, {"id": 88, "name": "Pickup Truck"}, {"id": 89, "name": "Fork"}, {"id": 90, "name": "Traffic Sign"}, {"id": 91, "name": "Ballon"}, {"id": 92, "name": "Tripod"}, {"id": 93, "name": "Dog"}, {"id": 94, "name": "Spoon"}, {"id": 95, "name": "Clock"}, {"id": 96, "name": "Pot"}, {"id": 97, "name": "Cow"}, {"id": 98, "name": "Cake"}, {"id": 99, "name": "Dinning Table"}, {"id": 100, "name": "Sheep"}, {"id": 101, "name": "Hanger"}, {"id": 102, "name": "Blackboard/Whiteboard"}, {"id": 103, "name": "Napkin"}, {"id": 104, "name": "Other Fish"}, {"id": 105, "name": "Orange/Tangerine"}, {"id": 106, "name": "Toiletry"}, {"id": 107, "name": "Keyboard"}, {"id": 108, "name": "Tomato"}, {"id": 109, "name": "Lantern"}, {"id": 110, "name": "Machinery Vehicle"}, {"id": 111, "name": "Fan"}, {"id": 112, "name": "Green Vegetables"}, {"id": 113, "name": "Banana"}, {"id": 114, "name": "Baseball Glove"}, {"id": 115, "name": "Airplane"}, {"id": 116, "name": "Mouse"}, {"id": 117, "name": "Train"}, {"id": 118, "name": "Pumpkin"}, {"id": 119, "name": "Soccer"}, {"id": 120, "name": "Skiboard"}, {"id": 121, "name": "Luggage"}, {"id": 122, "name": "Nightstand"}, {"id": 123, "name": "Tea pot"}, {"id": 124, "name": "Telephone"}, {"id": 125, "name": "Trolley"}, {"id": 126, "name": "Head Phone"}, {"id": 127, "name": "Sports Car"}, {"id": 128, "name": "Stop Sign"}, {"id": 129, "name": "Dessert"}, {"id": 130, "name": "Scooter"}, {"id": 131, "name": "Stroller"}, {"id": 132, "name": "Crane"}, {"id": 133, "name": "Remote"}, {"id": 134, "name": "Refrigerator"}, {"id": 135, "name": "Oven"}, {"id": 136, "name": "Lemon"}, {"id": 137, "name": "Duck"}, {"id": 138, "name": "Baseball Bat"}, {"id": 139, "name": "Surveillance Camera"}, {"id": 140, "name": "Cat"}, {"id": 141, "name": "Jug"}, {"id": 142, "name": "Broccoli"}, {"id": 143, "name": "Piano"}, {"id": 144, "name": "Pizza"}, {"id": 145, "name": "Elephant"}, {"id": 146, "name": "Skateboard"}, {"id": 147, "name": "Surfboard"}, {"id": 148, "name": "Gun"}, {"id": 149, "name": "Skating and Skiing shoes"}, {"id": 150, "name": "Gas stove"}, {"id": 151, "name": "Donut"}, {"id": 152, "name": "Bow Tie"}, {"id": 153, "name": "Carrot"}, {"id": 154, "name": "Toilet"}, {"id": 155, "name": "Kite"}, {"id": 156, "name": "Strawberry"}, {"id": 157, "name": "Other Balls"}, {"id": 158, "name": "Shovel"}, {"id": 159, "name": "Pepper"}, {"id": 160, "name": "Computer Box"}, {"id": 161, "name": "Toilet Paper"}, {"id": 162, "name": "Cleaning Products"}, {"id": 163, "name": "Chopsticks"}, {"id": 164, "name": "Microwave"}, {"id": 165, "name": "Pigeon"}, {"id": 166, "name": "Baseball"}, {"id": 167, "name": "Cutting/chopping Board"}, {"id": 168, "name": "Coffee Table"}, {"id": 169, "name": "Side Table"}, {"id": 170, "name": "Scissors"}, {"id": 171, "name": "Marker"}, {"id": 172, "name": "Pie"}, {"id": 173, "name": "Ladder"}, {"id": 174, "name": "Snowboard"}, {"id": 175, "name": "Cookies"}, {"id": 176, "name": "Radiator"}, {"id": 177, "name": "Fire Hydrant"}, {"id": 178, "name": "Basketball"}, {"id": 179, "name": "Zebra"}, {"id": 180, "name": "Grape"}, {"id": 181, "name": "Giraffe"}, {"id": 182, "name": "Potato"}, {"id": 183, "name": "Sausage"}, {"id": 184, "name": "Tricycle"}, {"id": 185, "name": "Violin"}, {"id": 186, "name": "Egg"}, {"id": 187, "name": "Fire Extinguisher"}, {"id": 188, "name": "Candy"}, {"id": 189, "name": "Fire Truck"}, {"id": 190, "name": "Billards"}, {"id": 191, "name": "Converter"}, {"id": 192, "name": "Bathtub"}, {"id": 193, "name": "Wheelchair"}, {"id": 194, "name": "Golf Club"}, {"id": 195, "name": "Briefcase"}, {"id": 196, "name": "Cucumber"}, {"id": 197, "name": "Cigar/Cigarette "}, {"id": 198, "name": "Paint Brush"}, {"id": 199, "name": "Pear"}, {"id": 200, "name": "Heavy Truck"}, {"id": 201, "name": "Hamburger"}, {"id": 202, "name": "Extractor"}, {"id": 203, "name": "Extention Cord"}, {"id": 204, "name": "Tong"}, {"id": 205, "name": "Tennis Racket"}, {"id": 206, "name": "Folder"}, {"id": 207, "name": "American Football"}, {"id": 208, "name": "earphone"}, {"id": 209, "name": "Mask"}, {"id": 210, "name": "Kettle"}, {"id": 211, "name": "Tennis"}, {"id": 212, "name": "Ship"}, {"id": 213, "name": "Swing"}, {"id": 214, "name": "Coffee Machine"}, {"id": 215, "name": "Slide"}, {"id": 216, "name": "Carriage"}, {"id": 217, "name": "Onion"}, {"id": 218, "name": "Green beans"}, {"id": 219, "name": "Projector"}, {"id": 220, "name": "Frisbee"}, {"id": 221, "name": "Washing Machine/Drying Machine"}, {"id": 222, "name": "Chicken"}, {"id": 223, "name": "Printer"}, {"id": 224, "name": "Watermelon"}, {"id": 225, "name": "Saxophone"}, {"id": 226, "name": "Tissue"}, {"id": 227, "name": "Toothbrush"}, {"id": 228, "name": "Ice cream"}, {"id": 229, "name": "Hotair ballon"}, {"id": 230, "name": "Cello"}, {"id": 231, "name": "French Fries"}, {"id": 232, "name": "Scale"}, {"id": 233, "name": "Trophy"}, {"id": 234, "name": "Cabbage"}, {"id": 235, "name": "Hot dog"}, {"id": 236, "name": "Blender"}, {"id": 237, "name": "Peach"}, {"id": 238, "name": "Rice"}, {"id": 239, "name": "Wallet/Purse"}, {"id": 240, "name": "Volleyball"}, {"id": 241, "name": "Deer"}, {"id": 242, "name": "Goose"}, {"id": 243, "name": "Tape"}, {"id": 244, "name": "Tablet"}, {"id": 245, "name": "Cosmetics"}, {"id": 246, "name": "Trumpet"}, {"id": 247, "name": "Pineapple"}, {"id": 248, "name": "Golf Ball"}, {"id": 249, "name": "Ambulance"}, {"id": 250, "name": "Parking meter"}, {"id": 251, "name": "Mango"}, {"id": 252, "name": "Key"}, {"id": 253, "name": "Hurdle"}, {"id": 254, "name": "Fishing Rod"}, {"id": 255, "name": "Medal"}, {"id": 256, "name": "Flute"}, {"id": 257, "name": "Brush"}, {"id": 258, "name": "Penguin"}, {"id": 259, "name": "Megaphone"}, {"id": 260, "name": "Corn"}, {"id": 261, "name": "Lettuce"}, {"id": 262, "name": "Garlic"}, {"id": 263, "name": "Swan"}, {"id": 264, "name": "Helicopter"}, {"id": 265, "name": "Green Onion"}, {"id": 266, "name": "Sandwich"}, {"id": 267, "name": "Nuts"}, {"id": 268, "name": "Speed Limit Sign"}, {"id": 269, "name": "Induction Cooker"}, {"id": 270, "name": "Broom"}, {"id": 271, "name": "Trombone"}, {"id": 272, "name": "Plum"}, {"id": 273, "name": "Rickshaw"}, {"id": 274, "name": "Goldfish"}, {"id": 275, "name": "Kiwi fruit"}, {"id": 276, "name": "Router/modem"}, {"id": 277, "name": "Poker Card"}, {"id": 278, "name": "Toaster"}, {"id": 279, "name": "Shrimp"}, {"id": 280, "name": "Sushi"}, {"id": 281, "name": "Cheese"}, {"id": 282, "name": "Notepaper"}, {"id": 283, "name": "Cherry"}, {"id": 284, "name": "Pliers"}, {"id": 285, "name": "CD"}, {"id": 286, "name": "Pasta"}, {"id": 287, "name": "Hammer"}, {"id": 288, "name": "Cue"}, {"id": 289, "name": "Avocado"}, {"id": 290, "name": "Hamimelon"}, {"id": 291, "name": "Flask"}, {"id": 292, "name": "Mushroon"}, {"id": 293, "name": "Screwdriver"}, {"id": 294, "name": "Soap"}, {"id": 295, "name": "Recorder"}, {"id": 296, "name": "Bear"}, {"id": 297, "name": "Eggplant"}, {"id": 298, "name": "Board Eraser"}, {"id": 299, "name": "Coconut"}, {"id": 300, "name": "Tape Measur/ Ruler"}, {"id": 301, "name": "Pig"}, {"id": 302, "name": "Showerhead"}, {"id": 303, "name": "Globe"}, {"id": 304, "name": "Chips"}, {"id": 305, "name": "Steak"}, {"id": 306, "name": "Crosswalk Sign"}, {"id": 307, "name": "Stapler"}, {"id": 308, "name": "Campel"}, {"id": 309, "name": "Formula 1 "}, {"id": 310, "name": "Pomegranate"}, {"id": 311, "name": "Dishwasher"}, {"id": 312, "name": "Crab"}, {"id": 313, "name": "Hoverboard"}, {"id": 314, "name": "Meat ball"}, {"id": 315, "name": "Rice Cooker"}, {"id": 316, "name": "Tuba"}, {"id": 317, "name": "Calculator"}, {"id": 318, "name": "Papaya"}, {"id": 319, "name": "Antelope"}, {"id": 320, "name": "Parrot"}, {"id": 321, "name": "Seal"}, {"id": 322, "name": "Buttefly"}, {"id": 323, "name": "Dumbbell"}, {"id": 324, "name": "Donkey"}, {"id": 325, "name": "Lion"}, {"id": 326, "name": "Urinal"}, {"id": 327, "name": "Dolphin"}, {"id": 328, "name": "Electric Drill"}, {"id": 329, "name": "Hair Dryer"}, {"id": 330, "name": "Egg tart"}, {"id": 331, "name": "Jellyfish"}, {"id": 332, "name": "Treadmill"}, {"id": 333, "name": "Lighter"}, {"id": 334, "name": "Grapefruit"}, {"id": 335, "name": "Game board"}, {"id": 336, "name": "Mop"}, {"id": 337, "name": "Radish"}, {"id": 338, "name": "Baozi"}, {"id": 339, "name": "Target"}, {"id": 340, "name": "French"}, {"id": 341, "name": "Spring Rolls"}, {"id": 342, "name": "Monkey"}, {"id": 343, "name": "Rabbit"}, {"id": 344, "name": "Pencil Case"}, {"id": 345, "name": "Yak"}, {"id": 346, "name": "Red Cabbage"}, {"id": 347, "name": "Binoculars"}, {"id": 348, "name": "Asparagus"}, {"id": 349, "name": "Barbell"}, {"id": 350, "name": "Scallop"}, {"id": 351, "name": "Noddles"}, {"id": 352, "name": "Comb"}, {"id": 353, "name": "Dumpling"}, {"id": 354, "name": "Oyster"}, {"id": 355, "name": "Table Teniis paddle"}, {"id": 356, "name": "Cosmetics Brush/Eyeliner Pencil"}, {"id": 357, "name": "Chainsaw"}, {"id": 358, "name": "Eraser"}, {"id": 359, "name": "Lobster"}, {"id": 360, "name": "Durian"}, {"id": 361, "name": "Okra"}, {"id": 362, "name": "Lipstick"}, {"id": 363, "name": "Cosmetics Mirror"}, {"id": 364, "name": "Curling"}, {"id": 365, "name": "Table Tennis "},]
def _get_builtin_metadata(key): # return {} if "fixname" in key: id_to_name = {x["id"]: x["name"] for x in OBJECTS365_CATEGORIES_FIXNAME} thing_dataset_id_to_contiguous_id = { i + 1: i for i in range(len(OBJECTS365_CATEGORIES_FIXNAME)) } else: id_to_name = {x["id"]: x["name"] for x in OBJECTS365_CATEGORIES} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(OBJECTS365_CATEGORIES))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_OBJECTS365 = { "objects365_train": ("objects365/train", "objects365/annotations/objects365_train.json"), "objects365_val": ("objects365/val", "objects365/annotations/objects365_val.json"), "objects365_minival": ("objects365/val", "objects365/annotations/objects365_minival.json"), "objects365_train_fixname": ( "objects365/train", "objects365/annotations/objects365_train_fixname.json", ), "objects365_val_fixname": ( "objects365/val", "objects365/annotations/objects365_val_fixname.json", ), "objects365_minival_fixname": ( "objects365/val", "objects365/annotations/objects365_minival_fixname.json", ), "objects365_train_fixname_fixmiss": ( "objects365/train", "objects365/annotations/objects365_train_fixname_fixmiss.json", ), "objects365_val_fixname_fixmiss": ( "objects365/val", "objects365/annotations/objects365_val_fixname_fixmiss.json", ),}
def register_all_objects365(root): for key, (image_root, json_file) in _PREDEFINED_SPLITS_OBJECTS365.items(): register_coco_instances( key, _get_builtin_metadata(key), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".objects365"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_objects365(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377ODINW_CATEGORIES = { "AerialMaritimeDrone": [ {"id": 1, "name": "boat", "supercategory": "movable-objects"}, {"id": 2, "name": "car", "supercategory": "movable-objects"}, {"id": 3, "name": "dock", "supercategory": "movable-objects"}, {"id": 4, "name": "jetski", "supercategory": "movable-objects"}, {"id": 5, "name": "lift", "supercategory": "movable-objects"}, ], "AmericanSignLanguageLetters": [ {"id": 1, "name": "A", "supercategory": "Letters"}, {"id": 2, "name": "B", "supercategory": "Letters"}, {"id": 3, "name": "C", "supercategory": "Letters"}, {"id": 4, "name": "D", "supercategory": "Letters"}, {"id": 5, "name": "E", "supercategory": "Letters"}, {"id": 6, "name": "F", "supercategory": "Letters"}, {"id": 7, "name": "G", "supercategory": "Letters"}, {"id": 8, "name": "H", "supercategory": "Letters"}, {"id": 9, "name": "I", "supercategory": "Letters"}, {"id": 10, "name": "J", "supercategory": "Letters"}, {"id": 11, "name": "K", "supercategory": "Letters"}, {"id": 12, "name": "L", "supercategory": "Letters"}, {"id": 13, "name": "M", "supercategory": "Letters"}, {"id": 14, "name": "N", "supercategory": "Letters"}, {"id": 15, "name": "O", "supercategory": "Letters"}, {"id": 16, "name": "P", "supercategory": "Letters"}, {"id": 17, "name": "Q", "supercategory": "Letters"}, {"id": 18, "name": "R", "supercategory": "Letters"}, {"id": 19, "name": "S", "supercategory": "Letters"}, {"id": 20, "name": "T", "supercategory": "Letters"}, {"id": 21, "name": "U", "supercategory": "Letters"}, {"id": 22, "name": "V", "supercategory": "Letters"}, {"id": 23, "name": "W", "supercategory": "Letters"}, {"id": 24, "name": "X", "supercategory": "Letters"}, {"id": 25, "name": "Y", "supercategory": "Letters"}, {"id": 26, "name": "Z", "supercategory": "Letters"}, ], "Aquarium": [ {"id": 1, "name": "fish", "supercategory": "creatures"}, {"id": 2, "name": "jellyfish", "supercategory": "creatures"}, {"id": 3, "name": "penguin", "supercategory": "creatures"}, {"id": 4, "name": "puffin", "supercategory": "creatures"}, {"id": 5, "name": "shark", "supercategory": "creatures"}, {"id": 6, "name": "starfish", "supercategory": "creatures"}, {"id": 7, "name": "stingray", "supercategory": "creatures"}, ], "BCCD": [ {"id": 1, "name": "Platelets", "supercategory": "cells"}, {"id": 2, "name": "RBC", "supercategory": "cells"}, {"id": 3, "name": "WBC", "supercategory": "cells"}, ], "boggleBoards": [ {"id": 1, "name": "Q", "supercategory": "letters"}, {"id": 2, "name": "a", "supercategory": "letters"}, {"id": 3, "name": "an", "supercategory": "letters"}, {"id": 4, "name": "b", "supercategory": "letters"}, {"id": 5, "name": "c", "supercategory": "letters"}, {"id": 6, "name": "d", "supercategory": "letters"}, {"id": 7, "name": "e", "supercategory": "letters"}, {"id": 8, "name": "er", "supercategory": "letters"}, {"id": 9, "name": "f", "supercategory": "letters"}, {"id": 10, "name": "g", "supercategory": "letters"}, {"id": 11, "name": "h", "supercategory": "letters"}, {"id": 12, "name": "he", "supercategory": "letters"}, {"id": 13, "name": "i", "supercategory": "letters"}, {"id": 14, "name": "in", "supercategory": "letters"}, {"id": 15, "name": "j", "supercategory": "letters"}, {"id": 16, "name": "k", "supercategory": "letters"}, {"id": 17, "name": "l", "supercategory": "letters"}, {"id": 18, "name": "m", "supercategory": "letters"}, {"id": 19, "name": "n", "supercategory": "letters"}, {"id": 20, "name": "o", "supercategory": "letters"}, {"id": 21, "name": "o ", "supercategory": "letters"}, {"id": 22, "name": "p", "supercategory": "letters"}, {"id": 23, "name": "q", "supercategory": "letters"}, {"id": 24, "name": "qu", "supercategory": "letters"}, {"id": 25, "name": "r", "supercategory": "letters"}, {"id": 26, "name": "s", "supercategory": "letters"}, {"id": 27, "name": "t", "supercategory": "letters"}, {"id": 28, "name": "t\\", "supercategory": "letters"}, {"id": 29, "name": "th", "supercategory": "letters"}, {"id": 30, "name": "u", "supercategory": "letters"}, {"id": 31, "name": "v", "supercategory": "letters"}, {"id": 32, "name": "w", "supercategory": "letters"}, {"id": 33, "name": "wild", "supercategory": "letters"}, {"id": 34, "name": "x", "supercategory": "letters"}, {"id": 35, "name": "y", "supercategory": "letters"}, {"id": 36, "name": "z", "supercategory": "letters"}, ], "brackishUnderwater": [ {"id": 1, "name": "crab", "supercategory": "animals"}, {"id": 2, "name": "fish", "supercategory": "animals"}, {"id": 3, "name": "jellyfish", "supercategory": "animals"}, {"id": 4, "name": "shrimp", "supercategory": "animals"}, {"id": 5, "name": "small_fish", "supercategory": "animals"}, {"id": 6, "name": "starfish", "supercategory": "animals"}, ], "ChessPieces": [ {"id": 1, "name": "bishop", "supercategory": "pieces"}, {"id": 2, "name": "black-bishop", "supercategory": "pieces"}, {"id": 3, "name": "black-king", "supercategory": "pieces"}, {"id": 4, "name": "black-knight", "supercategory": "pieces"}, {"id": 5, "name": "black-pawn", "supercategory": "pieces"}, {"id": 6, "name": "black-queen", "supercategory": "pieces"}, {"id": 7, "name": "black-rook", "supercategory": "pieces"}, {"id": 8, "name": "white-bishop", "supercategory": "pieces"}, {"id": 9, "name": "white-king", "supercategory": "pieces"}, {"id": 10, "name": "white-knight", "supercategory": "pieces"}, {"id": 11, "name": "white-pawn", "supercategory": "pieces"}, {"id": 12, "name": "white-queen", "supercategory": "pieces"}, {"id": 13, "name": "white-rook", "supercategory": "pieces"}, ], "CottontailRabbits": [ {"id": 1, "name": "Cottontail-Rabbit", "supercategory": "Cottontail-Rabbit"} ], "dice": [ {"id": 1, "name": "1", "supercategory": "dice"}, {"id": 2, "name": "2", "supercategory": "dice"}, {"id": 3, "name": "3", "supercategory": "dice"}, {"id": 4, "name": "4", "supercategory": "dice"}, {"id": 5, "name": "5", "supercategory": "dice"}, {"id": 6, "name": "6", "supercategory": "dice"}, ], "DroneControl": [ {"id": 1, "name": "follow", "supercategory": "actions"}, {"id": 2, "name": "follow_hand", "supercategory": "actions"}, {"id": 3, "name": "land", "supercategory": "actions"}, {"id": 4, "name": "land_hand", "supercategory": "actions"}, {"id": 5, "name": "null", "supercategory": "actions"}, {"id": 6, "name": "object", "supercategory": "actions"}, {"id": 7, "name": "takeoff", "supercategory": "actions"}, {"id": 8, "name": "takeoff-hand", "supercategory": "actions"}, ], "EgoHands-generic": [ {"id": 1, "name": "hand", "supercategory": "hands"}, ], "EgoHands-specific": [ {"id": 1, "name": "myleft", "supercategory": "hands"}, {"id": 2, "name": "myright", "supercategory": "hands"}, {"id": 3, "name": "yourleft", "supercategory": "hands"}, {"id": 4, "name": "yourright", "supercategory": "hands"}, ], "HardHatWorkers": [ {"id": 1, "name": "head", "supercategory": "Workers"}, {"id": 2, "name": "helmet", "supercategory": "Workers"}, {"id": 3, "name": "person", "supercategory": "Workers"}, ], "MaskWearing": [ {"id": 1, "name": "mask", "supercategory": "People"}, {"id": 2, "name": "no-mask", "supercategory": "People"}, ], "MountainDewCommercial": [ {"id": 1, "name": "bottle", "supercategory": "bottles"}, ], "NorthAmericaMushrooms": [ {"id": 1, "name": "CoW", "supercategory": "mushroom"}, {"id": 2, "name": "chanterelle", "supercategory": "mushroom"}, ], "openPoetryVision": [ {"id": 1, "name": "American Typewriter", "supercategory": "text"}, {"id": 2, "name": "Andale Mono", "supercategory": "text"}, {"id": 3, "name": "Apple Chancery", "supercategory": "text"}, {"id": 4, "name": "Arial", "supercategory": "text"}, {"id": 5, "name": "Avenir", "supercategory": "text"}, {"id": 6, "name": "Baskerville", "supercategory": "text"}, {"id": 7, "name": "Big Caslon", "supercategory": "text"}, {"id": 8, "name": "Bradley Hand", "supercategory": "text"}, {"id": 9, "name": "Brush Script MT", "supercategory": "text"}, {"id": 10, "name": "Chalkboard", "supercategory": "text"}, {"id": 11, "name": "Comic Sans MS", "supercategory": "text"}, {"id": 12, "name": "Copperplate", "supercategory": "text"}, {"id": 13, "name": "Courier", "supercategory": "text"}, {"id": 14, "name": "Didot", "supercategory": "text"}, {"id": 15, "name": "Futura", "supercategory": "text"}, {"id": 16, "name": "Geneva", "supercategory": "text"}, {"id": 17, "name": "Georgia", "supercategory": "text"}, {"id": 18, "name": "Gill Sans", "supercategory": "text"}, {"id": 19, "name": "Helvetica", "supercategory": "text"}, {"id": 20, "name": "Herculanum", "supercategory": "text"}, {"id": 21, "name": "Impact", "supercategory": "text"}, {"id": 22, "name": "Kefa", "supercategory": "text"}, {"id": 23, "name": "Lucida Grande", "supercategory": "text"}, {"id": 24, "name": "Luminari", "supercategory": "text"}, {"id": 25, "name": "Marker Felt", "supercategory": "text"}, {"id": 26, "name": "Menlo", "supercategory": "text"}, {"id": 27, "name": "Monaco", "supercategory": "text"}, {"id": 28, "name": "Noteworthy", "supercategory": "text"}, {"id": 29, "name": "Optima", "supercategory": "text"}, {"id": 30, "name": "PT Sans", "supercategory": "text"}, {"id": 31, "name": "PT Serif", "supercategory": "text"}, {"id": 32, "name": "Palatino", "supercategory": "text"}, {"id": 33, "name": "Papyrus", "supercategory": "text"}, {"id": 34, "name": "Phosphate", "supercategory": "text"}, {"id": 35, "name": "Rockwell", "supercategory": "text"}, {"id": 36, "name": "SF Pro", "supercategory": "text"}, {"id": 37, "name": "SignPainter", "supercategory": "text"}, {"id": 38, "name": "Skia", "supercategory": "text"}, {"id": 39, "name": "Snell Roundhand", "supercategory": "text"}, {"id": 40, "name": "Tahoma", "supercategory": "text"}, {"id": 41, "name": "Times New Roman", "supercategory": "text"}, {"id": 42, "name": "Trebuchet MS", "supercategory": "text"}, {"id": 43, "name": "Verdana", "supercategory": "text"}, ], "OxfordPets-by-breed": [ {"id": 1, "name": "cat-Abyssinian", "supercategory": "pets"}, {"id": 2, "name": "cat-Bengal", "supercategory": "pets"}, {"id": 3, "name": "cat-Birman", "supercategory": "pets"}, {"id": 4, "name": "cat-Bombay", "supercategory": "pets"}, {"id": 5, "name": "cat-British_Shorthair", "supercategory": "pets"}, {"id": 6, "name": "cat-Egyptian_Mau", "supercategory": "pets"}, {"id": 7, "name": "cat-Maine_Coon", "supercategory": "pets"}, {"id": 8, "name": "cat-Persian", "supercategory": "pets"}, {"id": 9, "name": "cat-Ragdoll", "supercategory": "pets"}, {"id": 10, "name": "cat-Russian_Blue", "supercategory": "pets"}, {"id": 11, "name": "cat-Siamese", "supercategory": "pets"}, {"id": 12, "name": "cat-Sphynx", "supercategory": "pets"}, {"id": 13, "name": "dog-american_bulldog", "supercategory": "pets"}, {"id": 14, "name": "dog-american_pit_bull_terrier", "supercategory": "pets"}, {"id": 15, "name": "dog-basset_hound", "supercategory": "pets"}, {"id": 16, "name": "dog-beagle", "supercategory": "pets"}, {"id": 17, "name": "dog-boxer", "supercategory": "pets"}, {"id": 18, "name": "dog-chihuahua", "supercategory": "pets"}, {"id": 19, "name": "dog-english_cocker_spaniel", "supercategory": "pets"}, {"id": 20, "name": "dog-english_setter", "supercategory": "pets"}, {"id": 21, "name": "dog-german_shorthaired", "supercategory": "pets"}, {"id": 22, "name": "dog-great_pyrenees", "supercategory": "pets"}, {"id": 23, "name": "dog-havanese", "supercategory": "pets"}, {"id": 24, "name": "dog-japanese_chin", "supercategory": "pets"}, {"id": 25, "name": "dog-keeshond", "supercategory": "pets"}, {"id": 26, "name": "dog-leonberger", "supercategory": "pets"}, {"id": 27, "name": "dog-miniature_pinscher", "supercategory": "pets"}, {"id": 28, "name": "dog-newfoundland", "supercategory": "pets"}, {"id": 29, "name": "dog-pomeranian", "supercategory": "pets"}, {"id": 30, "name": "dog-pug", "supercategory": "pets"}, {"id": 31, "name": "dog-saint_bernard", "supercategory": "pets"}, {"id": 32, "name": "dog-samoyed", "supercategory": "pets"}, {"id": 33, "name": "dog-scottish_terrier", "supercategory": "pets"}, {"id": 34, "name": "dog-shiba_inu", "supercategory": "pets"}, {"id": 35, "name": "dog-staffordshire_bull_terrier", "supercategory": "pets"}, {"id": 36, "name": "dog-wheaten_terrier", "supercategory": "pets"}, {"id": 37, "name": "dog-yorkshire_terrier", "supercategory": "pets"}, ], "OxfordPets-by-species": [ {"id": 1, "name": "cat", "supercategory": "pets"}, {"id": 2, "name": "dog", "supercategory": "pets"}, ], "Packages": [{"id": 1, "name": "package", "supercategory": "packages"}], "PascalVOC": [ {"id": 1, "name": "aeroplane", "supercategory": "VOC"}, {"id": 2, "name": "bicycle", "supercategory": "VOC"}, {"id": 3, "name": "bird", "supercategory": "VOC"}, {"id": 4, "name": "boat", "supercategory": "VOC"}, {"id": 5, "name": "bottle", "supercategory": "VOC"}, {"id": 6, "name": "bus", "supercategory": "VOC"}, {"id": 7, "name": "car", "supercategory": "VOC"}, {"id": 8, "name": "cat", "supercategory": "VOC"}, {"id": 9, "name": "chair", "supercategory": "VOC"}, {"id": 10, "name": "cow", "supercategory": "VOC"}, {"id": 11, "name": "diningtable", "supercategory": "VOC"}, {"id": 12, "name": "dog", "supercategory": "VOC"}, {"id": 13, "name": "horse", "supercategory": "VOC"}, {"id": 14, "name": "motorbike", "supercategory": "VOC"}, {"id": 15, "name": "person", "supercategory": "VOC"}, {"id": 16, "name": "pottedplant", "supercategory": "VOC"}, {"id": 17, "name": "sheep", "supercategory": "VOC"}, {"id": 18, "name": "sofa", "supercategory": "VOC"}, {"id": 19, "name": "train", "supercategory": "VOC"}, {"id": 20, "name": "tvmonitor", "supercategory": "VOC"}, ], "pistols": [ {"id": 1, "name": "pistol", "supercategory": "Guns"}, ], "PKLot": [ {"id": 1, "name": "space-empty", "supercategory": "spaces"}, {"id": 2, "name": "space-occupied", "supercategory": "spaces"}, ], "plantdoc": [ {"id": 1, "name": "Apple Scab Leaf", "supercategory": "leaves"}, {"id": 2, "name": "Apple leaf", "supercategory": "leaves"}, {"id": 3, "name": "Apple rust leaf", "supercategory": "leaves"}, {"id": 4, "name": "Bell_pepper leaf", "supercategory": "leaves"}, {"id": 5, "name": "Bell_pepper leaf spot", "supercategory": "leaves"}, {"id": 6, "name": "Blueberry leaf", "supercategory": "leaves"}, {"id": 7, "name": "Cherry leaf", "supercategory": "leaves"}, {"id": 8, "name": "Corn Gray leaf spot", "supercategory": "leaves"}, {"id": 9, "name": "Corn leaf blight", "supercategory": "leaves"}, {"id": 10, "name": "Corn rust leaf", "supercategory": "leaves"}, {"id": 11, "name": "Peach leaf", "supercategory": "leaves"}, {"id": 12, "name": "Potato leaf", "supercategory": "leaves"}, {"id": 13, "name": "Potato leaf early blight", "supercategory": "leaves"}, {"id": 14, "name": "Potato leaf late blight", "supercategory": "leaves"}, {"id": 15, "name": "Raspberry leaf", "supercategory": "leaves"}, {"id": 16, "name": "Soyabean leaf", "supercategory": "leaves"}, {"id": 17, "name": "Soybean leaf", "supercategory": "leaves"}, {"id": 18, "name": "Squash Powdery mildew leaf", "supercategory": "leaves"}, {"id": 19, "name": "Strawberry leaf", "supercategory": "leaves"}, {"id": 20, "name": "Tomato Early blight leaf", "supercategory": "leaves"}, {"id": 21, "name": "Tomato Septoria leaf spot", "supercategory": "leaves"}, {"id": 22, "name": "Tomato leaf", "supercategory": "leaves"}, {"id": 23, "name": "Tomato leaf bacterial spot", "supercategory": "leaves"}, {"id": 24, "name": "Tomato leaf late blight", "supercategory": "leaves"}, {"id": 25, "name": "Tomato leaf mosaic virus", "supercategory": "leaves"}, {"id": 26, "name": "Tomato leaf yellow virus", "supercategory": "leaves"}, {"id": 27, "name": "Tomato mold leaf", "supercategory": "leaves"}, {"id": 28, "name": "Tomato two spotted spider mites leaf", "supercategory": "leaves"}, {"id": 29, "name": "grape leaf", "supercategory": "leaves"}, {"id": 30, "name": "grape leaf black rot", "supercategory": "leaves"}, ], "pothole": [ {"id": 1, "name": "pothole", "supercategory": "potholes"}, ], "Raccoon": [ {"id": 1, "name": "raccoon", "supercategory": "raccoons"}, ], "selfdrivingCar": [ {"id": 1, "name": "biker", "supercategory": "obstacles"}, {"id": 2, "name": "car", "supercategory": "obstacles"}, {"id": 3, "name": "pedestrian", "supercategory": "obstacles"}, {"id": 4, "name": "trafficLight", "supercategory": "obstacles"}, {"id": 5, "name": "trafficLight-Green", "supercategory": "obstacles"}, {"id": 6, "name": "trafficLight-GreenLeft", "supercategory": "obstacles"}, {"id": 7, "name": "trafficLight-Red", "supercategory": "obstacles"}, {"id": 8, "name": "trafficLight-RedLeft", "supercategory": "obstacles"}, {"id": 9, "name": "trafficLight-Yellow", "supercategory": "obstacles"}, {"id": 10, "name": "trafficLight-YellowLeft", "supercategory": "obstacles"}, {"id": 11, "name": "truck", "supercategory": "obstacles"}, ], "ShellfishOpenImages": [ {"id": 1, "name": "Crab", "supercategory": "shellfish"}, {"id": 2, "name": "Lobster", "supercategory": "shellfish"}, {"id": 3, "name": "Shrimp", "supercategory": "shellfish"}, ], "ThermalCheetah": [ {"id": 1, "name": "cheetah", "supercategory": "cheetah"}, {"id": 2, "name": "human", "supercategory": "cheetah"}, ], "thermalDogsAndPeople": [ {"id": 1, "name": "dog", "supercategory": "dogs-person"}, {"id": 2, "name": "person", "supercategory": "dogs-person"}, ], "UnoCards": [ {"id": 1, "name": "0", "supercategory": "Card-Types"}, {"id": 2, "name": "1", "supercategory": "Card-Types"}, {"id": 3, "name": "2", "supercategory": "Card-Types"}, {"id": 4, "name": "3", "supercategory": "Card-Types"}, {"id": 5, "name": "4", "supercategory": "Card-Types"}, {"id": 6, "name": "5", "supercategory": "Card-Types"}, {"id": 7, "name": "6", "supercategory": "Card-Types"}, {"id": 8, "name": "7", "supercategory": "Card-Types"}, {"id": 9, "name": "8", "supercategory": "Card-Types"}, {"id": 10, "name": "9", "supercategory": "Card-Types"}, {"id": 11, "name": "10", "supercategory": "Card-Types"}, {"id": 12, "name": "11", "supercategory": "Card-Types"}, {"id": 13, "name": "12", "supercategory": "Card-Types"}, {"id": 14, "name": "13", "supercategory": "Card-Types"}, {"id": 15, "name": "14", "supercategory": "Card-Types"}, ], "VehiclesOpenImages": [ {"id": 1, "name": "Ambulance", "supercategory": "vehicles"}, {"id": 2, "name": "Bus", "supercategory": "vehicles"}, {"id": 3, "name": "Car", "supercategory": "vehicles"}, {"id": 4, "name": "Motorcycle", "supercategory": "vehicles"}, {"id": 5, "name": "Truck", "supercategory": "vehicles"}, ], "websiteScreenshots": [ {"id": 1, "name": "button", "supercategory": "elements"}, {"id": 2, "name": "field", "supercategory": "elements"}, {"id": 3, "name": "heading", "supercategory": "elements"}, {"id": 4, "name": "iframe", "supercategory": "elements"}, {"id": 5, "name": "image", "supercategory": "elements"}, {"id": 6, "name": "label", "supercategory": "elements"}, {"id": 7, "name": "link", "supercategory": "elements"}, {"id": 8, "name": "text", "supercategory": "elements"}, ], "WildfireSmoke": [ {"id": 1, "name": "smoke", "supercategory": "Smoke"}, ],}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824import contextlibimport ioimport loggingimport os
import pycocotools.mask as mask_util
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.structures import BoxModefrom detectron2.utils.file_io import PathManagerfrom fvcore.common.timer import Timer
from .odinw_categories import ODINW_CATEGORIESfrom .odinw_prompts import ODINW_PROMPTS
logger = logging.getLogger(__name__)
def load_coco_json(json_file, image_root, dataset_name=None, extra_annotation_keys=None): """ Load a json file with COCO's instances annotation format. Currently supports instance detection, instance segmentation, and person keypoints annotations.
Args: json_file (str): full path to the json file in COCO instances annotation format. image_root (str or path-like): the directory where the images in this json file exists. dataset_name (str or None): the name of the dataset (e.g., coco_2017_train). When provided, this function will also do the following:
* Put "thing_classes" into the metadata associated with this dataset. * Map the category ids into a contiguous range (needed by standard dataset format), and add "thing_dataset_id_to_contiguous_id" to the metadata associated with this dataset.
This option should usually be provided, unless users need to load the original json content and apply more processing manually. extra_annotation_keys (list[str]): list of per-annotation keys that should also be loaded into the dataset dict (besides "iscrowd", "bbox", "keypoints", "category_id", "segmentation"). The values for these keys will be returned as-is. For example, the densepose annotations are loaded in this way.
Returns: list[dict]: a list of dicts in Detectron2 standard dataset dicts format (See `Using Custom Datasets </tutorials/datasets.html>`_ ) when `dataset_name` is not None. If `dataset_name` is None, the returned `category_ids` may be incontiguous and may not conform to the Detectron2 standard format.
Notes: 1. This function does not read the image files. The results do not have the "image" field. """ from pycocotools.coco import COCO
timer = Timer() json_file = PathManager.get_local_path(json_file) with contextlib.redirect_stdout(io.StringIO()): coco_api = COCO(json_file) if timer.seconds() > 1: logger.info("Loading {} takes {:.2f} seconds.".format(json_file, timer.seconds()))
id_map = None if dataset_name is not None: meta = MetadataCatalog.get(dataset_name) cat_ids = sorted(coco_api.getCatIds()) # cats = coco_api.loadCats(cat_ids) # The categories in a custom json file may not be sorted. # thing_classes = [c["name"] for c in sorted(cats, key=lambda x: x["id"])] # meta.thing_classes = thing_classes
# In COCO, certain category ids are artificially removed, # and by convention they are always ignored. # We deal with COCO's id issue and translate # the category ids to contiguous ids in [0, 80).
# It works by looking at the "categories" field in the json, therefore # if users' own json also have incontiguous ids, we'll # apply this mapping as well but print a warning. if not (min(cat_ids) == 1 and max(cat_ids) == len(cat_ids)): if "coco" not in dataset_name: logger.warning( """Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.""" ) id_map = {v: i for i, v in enumerate(cat_ids)} meta.thing_dataset_id_to_contiguous_id = id_map
# sort indices for reproducible results img_ids = sorted(coco_api.imgs.keys()) # imgs is a list of dicts, each looks something like: # {'license': 4, # 'url': 'http://farm6.staticflickr.com/5454/9413846304_881d5e5c3b_z.jpg', # 'file_name': 'COCO_val2014_000000001268.jpg', # 'height': 427, # 'width': 640, # 'date_captured': '2013-11-17 05:57:24', # 'id': 1268} imgs = coco_api.loadImgs(img_ids) # anns is a list[list[dict]], where each dict is an annotation # record for an object. The inner list enumerates the objects in an image # and the outer list enumerates over images. Example of anns[0]: # [{'segmentation': [[192.81, # 247.09, # ... # 219.03, # 249.06]], # 'area': 1035.749, # 'iscrowd': 0, # 'image_id': 1268, # 'bbox': [192.81, 224.8, 74.73, 33.43], # 'category_id': 16, # 'id': 42986}, # ...] anns = [coco_api.imgToAnns[img_id] for img_id in img_ids] total_num_valid_anns = sum([len(x) for x in anns]) total_num_anns = len(coco_api.anns) if total_num_valid_anns < total_num_anns: logger.warning( f"{json_file} contains {total_num_anns} annotations, but only " f"{total_num_valid_anns} of them match to images in the file." )
if "minival" not in json_file: # The popular valminusminival & minival annotations for COCO2014 contain this bug. # However the ratio of buggy annotations there is tiny and does not affect accuracy. # Therefore we explicitly white-list them. ann_ids = [ann["id"] for anns_per_image in anns for ann in anns_per_image] assert len(set(ann_ids)) == len(ann_ids), "Annotation ids in '{}' are not unique!".format( json_file )
imgs_anns = list(zip(imgs, anns)) logger.info("Loaded {} images in COCO format from {}".format(len(imgs_anns), json_file))
dataset_dicts = []
ann_keys = ["iscrowd", "bbox", "keypoints", "category_id"] + (extra_annotation_keys or [])
num_instances_without_valid_segmentation = 0
for (img_dict, anno_dict_list) in imgs_anns: record = {} record["file_name"] = os.path.join(image_root, img_dict["file_name"]) # record["height"] = img_dict["height"] # record["width"] = img_dict["width"] image_id = record["image_id"] = img_dict["id"]
objs = [] for anno in anno_dict_list: # Check that the image_id in this annotation is the same as # the image_id we're looking at. # This fails only when the data parsing logic or the annotation file is buggy.
# The original COCO valminusminival2014 & minival2014 annotation files # actually contains bugs that, together with certain ways of using COCO API, # can trigger this assertion. assert anno["image_id"] == image_id
assert anno.get("ignore", 0) == 0, '"ignore" in COCO json file is not supported.'
obj = {key: anno[key] for key in ann_keys if key in anno} if "bbox" in obj and len(obj["bbox"]) == 0: raise ValueError( f"One annotation of image {image_id} contains empty 'bbox' value! " "This json does not have valid COCO format." )
segm = anno.get("segmentation", None) if segm: # either list[list[float]] or dict(RLE) if isinstance(segm, dict): if isinstance(segm["counts"], list): # convert to compressed RLE segm = mask_util.frPyObjects(segm, *segm["size"]) else: # filter out invalid polygons (< 3 points) segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] if len(segm) == 0: num_instances_without_valid_segmentation += 1 continue # ignore this instance obj["segmentation"] = segm
keypts = anno.get("keypoints", None) if keypts: # list[int] for idx, v in enumerate(keypts): if idx % 3 != 2: # COCO's segmentation coordinates are floating points in [0, H or W], # but keypoint coordinates are integers in [0, H-1 or W-1] # Therefore we assume the coordinates are "pixel indices" and # add 0.5 to convert to floating point coordinates. keypts[idx] = v + 0.5 obj["keypoints"] = keypts
obj["bbox_mode"] = BoxMode.XYWH_ABS if id_map: annotation_category_id = obj["category_id"] try: obj["category_id"] = id_map[annotation_category_id] except KeyError as e: raise KeyError( f"Encountered category_id={annotation_category_id} " "but this id does not exist in 'categories' of the json file." ) from e objs.append(obj) record["annotations"] = objs dataset_dicts.append(record)
if num_instances_without_valid_segmentation > 0: logger.warning( "Filtered out {} instances without valid segmentation. ".format( num_instances_without_valid_segmentation ) + "There might be issues in your dataset generation process. Please " "check https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html carefully" ) return dataset_dicts
def register_coco_instances(name, metadata, json_file, image_root): """ Register a dataset in COCO's json annotation format for instance detection, instance segmentation and keypoint detection. (i.e., Type 1 and 2 in http://cocodataset.org/#format-data. `instances*.json` and `person_keypoints*.json` in the dataset).
This is an example of how to register a new dataset. You can do something similar to this function, to register new datasets.
Args: name (str): the name that identifies a dataset, e.g. "coco_2014_train". metadata (dict): extra metadata associated with this dataset. You can leave it as an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ assert isinstance(name, str), name assert isinstance(json_file, (str, os.PathLike)), json_file assert isinstance(image_root, (str, os.PathLike)), image_root # 1. register a function which returns dicts DatasetCatalog.register(name, lambda: load_coco_json(json_file, image_root, name))
# 2. Optionally, add metadata about this dataset, # since they might be useful in evaluation, visualization or logging MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="coco", **metadata )
_PREDEFINED_SPLITS_ODINW = { "odinw_AerialMaritimeDrone_large": { "odinw_AerialMaritimeDrone_large_train": ( "odinw/AerialMaritimeDrone/large/train/", "odinw/AerialMaritimeDrone/large/train/annotations_without_background_converted.json", ), "odinw_AerialMaritimeDrone_large_val": ( "odinw/AerialMaritimeDrone/large/valid/", "odinw/AerialMaritimeDrone/large/valid/annotations_without_background_converted.json", ), "odinw_AerialMaritimeDrone_large_test": ( "odinw/AerialMaritimeDrone/large/test/", "odinw/AerialMaritimeDrone/large/test/annotations_without_background_converted.json", ), }, "odinw_AerialMaritimeDrone_tiled": { "odinw_AerialMaritimeDrone_tiled_train": ( "odinw/AerialMaritimeDrone/tiled/train/", "odinw/AerialMaritimeDrone/tiled/train/annotations_without_background_converted.json", ), "odinw_AerialMaritimeDrone_tiled_val": ( "odinw/AerialMaritimeDrone/tiled/valid/", "odinw/AerialMaritimeDrone/tiled/valid/annotations_without_background_converted.json", ), "odinw_AerialMaritimeDrone_tiled_test": ( "odinw/AerialMaritimeDrone/tiled/test/", "odinw/AerialMaritimeDrone/tiled/test/annotations_without_background_converted.json", ), }, "odinw_AmericanSignLanguageLetters_American_Sign_Language_Letters.v1-v1.coco": { "odinw_AmericanSignLanguageLetters_American_Sign_Language_Letters.v1-v1.coco_train": ( "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/train/", "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/train/annotations_without_background_converted.json", ), "odinw_AmericanSignLanguageLetters_American_Sign_Language_Letters.v1-v1.coco_val": ( "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/valid/", "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/valid/annotations_without_background_converted.json", ), "odinw_AmericanSignLanguageLetters_American_Sign_Language_Letters.v1-v1.coco_test": ( "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/test/", "odinw/AmericanSignLanguageLetters/American Sign Language Letters.v1-v1.coco/test/annotations_without_background_converted.json", ), }, "odinw_Aquarium_Aquarium_Combined.v2-raw-1024.coco": { "odinw_Aquarium_Aquarium_Combined.v2-raw-1024.coco_train": ( "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/train/", "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/train/annotations_without_background_converted.json", ), "odinw_Aquarium_Aquarium_Combined.v2-raw-1024.coco_val": ( "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/valid/", "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/valid/annotations_without_background_converted.json", ), "odinw_Aquarium_Aquarium_Combined.v2-raw-1024.coco_test": ( "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/test/", "odinw/Aquarium/Aquarium Combined.v2-raw-1024.coco/test/annotations_without_background_converted.json", ), }, "odinw_BCCD_BCCD.v3-raw.coco": { "odinw_BCCD_BCCD.v3-raw.coco_train": ( "odinw/BCCD/BCCD.v3-raw.coco/train/", "odinw/BCCD/BCCD.v3-raw.coco/train/annotations_without_background_converted.json", ), "odinw_BCCD_BCCD.v3-raw.coco_val": ( "odinw/BCCD/BCCD.v3-raw.coco/valid/", "odinw/BCCD/BCCD.v3-raw.coco/valid/annotations_without_background_converted.json", ), "odinw_BCCD_BCCD.v3-raw.coco_test": ( "odinw/BCCD/BCCD.v3-raw.coco/test/", "odinw/BCCD/BCCD.v3-raw.coco/test/annotations_without_background_converted.json", ), }, "odinw_boggleBoards_416x416AutoOrient_export_": { "odinw_boggleBoards_416x416AutoOrient_export_train": ( "odinw/boggleBoards/416x416AutoOrient/export/", "odinw/boggleBoards/416x416AutoOrient/export/train_annotations_without_background_converted.json", ), "odinw_boggleBoards_416x416AutoOrient_export_val": ( "odinw/boggleBoards/416x416AutoOrient/export/", "odinw/boggleBoards/416x416AutoOrient/export/val_annotations_without_background_converted.json", ), "odinw_boggleBoards_416x416AutoOrient_export_test": ( "odinw/boggleBoards/416x416AutoOrient/export/", "odinw/boggleBoards/416x416AutoOrient/export/test_annotations_without_background_converted.json", ), }, "odinw_brackishUnderwater_960x540": { "odinw_brackishUnderwater_960x540_train": ( "odinw/brackishUnderwater/960x540/train/", "odinw/brackishUnderwater/960x540/train/annotations_without_background_converted.json", ), "odinw_brackishUnderwater_960x540_val": ( "odinw/brackishUnderwater/960x540/valid/", "odinw/brackishUnderwater/960x540/valid/annotations_without_background_converted.json", ), "odinw_brackishUnderwater_960x540_minival": ( "odinw/brackishUnderwater/960x540/mini_val/", "odinw/brackishUnderwater/960x540/mini_val/annotations_without_background_converted.json", ), "odinw_brackishUnderwater_960x540_test": ( "odinw/brackishUnderwater/960x540/test/", "odinw/brackishUnderwater/960x540/test/annotations_without_background_converted.json", ), }, "odinw_ChessPieces_Chess_Pieces.v23-raw.coco": { "odinw_ChessPieces_Chess_Pieces.v23-raw.coco_train": ( "odinw/ChessPieces/Chess Pieces.v23-raw.coco/train/", "odinw/ChessPieces/Chess Pieces.v23-raw.coco/train/annotations_without_background_converted.json", ), "odinw_ChessPieces_Chess_Pieces.v23-raw.coco_val": ( "odinw/ChessPieces/Chess Pieces.v23-raw.coco/valid/", "odinw/ChessPieces/Chess Pieces.v23-raw.coco/valid/annotations_without_background_converted.json", ), "odinw_ChessPieces_Chess_Pieces.v23-raw.coco_test": ( "odinw/ChessPieces/Chess Pieces.v23-raw.coco/test/", "odinw/ChessPieces/Chess Pieces.v23-raw.coco/test/annotations_without_background_converted.json", ), }, "odinw_CottontailRabbits": { "odinw_CottontailRabbits_train": ( "odinw/CottontailRabbits/train/", "odinw/CottontailRabbits/train/annotations_without_background_converted.json", ), "odinw_CottontailRabbits_val": ( "odinw/CottontailRabbits/valid/", "odinw/CottontailRabbits/valid/annotations_without_background_converted.json", ), "odinw_CottontailRabbits_test": ( "odinw/CottontailRabbits/test/", "odinw/CottontailRabbits/test/annotations_without_background_converted.json", ), }, "odinw_dice_mediumColor_export": { "odinw_dice_mediumColor_export_train": ( "odinw/dice/mediumColor/export/", "odinw/dice/mediumColor/export/train_annotations_without_background_converted.json", ), "odinw_dice_mediumColor_export_val": ( "odinw/dice/mediumColor/export/", "odinw/dice/mediumColor/export/val_annotations_without_background_converted.json", ), "odinw_dice_mediumColor_export_test": ( "odinw/dice/mediumColor/export/", "odinw/dice/mediumColor/export/test_annotations_without_background_converted.json", ), }, "odinw_DroneControl_Drone_Control.v3-raw.coco": { "odinw_DroneControl_Drone_Control.v3-raw.coco_train": ( "odinw/DroneControl/Drone Control.v3-raw.coco/train/", "odinw/DroneControl/Drone Control.v3-raw.coco/train/annotations_without_background_converted.json", ), "odinw_DroneControl_Drone_Control.v3-raw.coco_val": ( "odinw/DroneControl/Drone Control.v3-raw.coco/valid/", "odinw/DroneControl/Drone Control.v3-raw.coco/valid/annotations_without_background_converted.json", ), "odinw_DroneControl_Drone_Control.v3-raw.coco_minival": ( "odinw/DroneControl/Drone Control.v3-raw.coco/mini_val/", "odinw/DroneControl/Drone Control.v3-raw.coco/mini_val/annotations_without_background_converted.json", ), "odinw_DroneControl_Drone_Control.v3-raw.coco_test": ( "odinw/DroneControl/Drone Control.v3-raw.coco/test/", "odinw/DroneControl/Drone Control.v3-raw.coco/test/annotations_without_background_converted.json", ), }, "odinw_EgoHands-generic": { "odinw_EgoHands_generic_train": ( "odinw/EgoHands/generic/train/", "odinw/EgoHands/generic/train/annotations_without_background_converted.json", ), "odinw_EgoHands_generic_val": ( "odinw/EgoHands/generic/valid/", "odinw/EgoHands/generic/valid/annotations_without_background_converted.json", ), "odinw_EgoHands_generic_minival": ( "odinw/EgoHands/generic/mini_val/", "odinw/EgoHands/generic/mini_val/annotations_without_background_converted.json", ), "odinw_EgoHands_generic_test": ( "odinw/EgoHands/generic/test/", "odinw/EgoHands/generic/test/annotations_without_background_converted.json", ), }, "odinw_EgoHands-specific": { "odinw_EgoHands_specific_train": ( "odinw/EgoHands/specific/train/", "odinw/EgoHands/specific/train/annotations_without_background_converted.json", ), "odinw_EgoHands_specific_val": ( "odinw/EgoHands/specific/valid/", "odinw/EgoHands/specific/valid/annotations_without_background_converted.json", ), "odinw_EgoHands_specific_minival": ( "odinw/EgoHands/specific/mini_val/", "odinw/EgoHands/specific/mini_val/annotations_without_background_converted.json", ), "odinw_EgoHands_specific_test": ( "odinw/EgoHands/specific/test/", "odinw/EgoHands/specific/test/annotations_without_background_converted.json", ), }, "odinw_HardHatWorkers_raw": { "odinw_HardHatWorkers_raw_train": ( "odinw/HardHatWorkers/raw/train/", "odinw/HardHatWorkers/raw/train/annotations_without_background_converted.json", ), "odinw_HardHatWorkers_raw_val": ( "odinw/HardHatWorkers/raw/valid/", "odinw/HardHatWorkers/raw/valid/annotations_without_background_converted.json", ), "odinw_HardHatWorkers_raw_test": ( "odinw/HardHatWorkers/raw/test/", "odinw/HardHatWorkers/raw/test/annotations_without_background_converted.json", ), }, "odinw_MaskWearing_raw": { "odinw_MaskWearing_raw_train": ( "odinw/MaskWearing/raw/train/", "odinw/MaskWearing/raw/train/annotations_without_background_converted.json", ), "odinw_MaskWearing_raw_val": ( "odinw/MaskWearing/raw/valid/", "odinw/MaskWearing/raw/valid/annotations_without_background_converted.json", ), "odinw_MaskWearing_raw_test": ( "odinw/MaskWearing/raw/test/", "odinw/MaskWearing/raw/test/annotations_without_background_converted.json", ), }, "odinw_MountainDewCommercial": { "odinw_MountainDewCommercial_train": ( "odinw/MountainDewCommercial/train/", "odinw/MountainDewCommercial/train/annotations_without_background_converted.json", ), "odinw_MountainDewCommercial_val": ( "odinw/MountainDewCommercial/valid/", "odinw/MountainDewCommercial/valid/annotations_without_background_converted.json", ), "odinw_MountainDewCommercial_test": ( "odinw/MountainDewCommercial/test/", "odinw/MountainDewCommercial/test/annotations_without_background_converted.json", ), }, "odinw_NorthAmericaMushrooms_North_American_Mushrooms.v1-416x416.coco": { "odinw_NorthAmericaMushrooms_North_American_Mushrooms.v1-416x416.coco_train": ( "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/train/", "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/train/annotations_without_background_converted.json", ), "odinw_NorthAmericaMushrooms_North_American_Mushrooms.v1-416x416.coco_val": ( "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/valid/", "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/valid/annotations_without_background_converted.json", ), "odinw_NorthAmericaMushrooms_North_American_Mushrooms.v1-416x416.coco_test": ( "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/test/", "odinw/NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/test/annotations_without_background_converted.json", ), }, "odinw_openPoetryVision_512x512": { "odinw_openPoetryVision_512x512_train": ( "odinw/openPoetryVision/512x512/train/", "odinw/openPoetryVision/512x512/train/annotations_without_background_converted.json", ), "odinw_openPoetryVision_512x512_val": ( "odinw/openPoetryVision/512x512/valid/", "odinw/openPoetryVision/512x512/valid/annotations_without_background_converted.json", ), "odinw_openPoetryVision_512x512_minival": ( "odinw/openPoetryVision/512x512/mini_val/", "odinw/openPoetryVision/512x512/mini_val/annotations_without_background_converted.json", ), "odinw_openPoetryVision_512x512_test": ( "odinw/openPoetryVision/512x512/test/", "odinw/openPoetryVision/512x512/test/annotations_without_background_converted.json", ), }, "odinw_OxfordPets-by-breed": { "odinw_OxfordPets_by-breed_train": ( "odinw/OxfordPets/by-breed/train/", "odinw/OxfordPets/by-breed/train/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-breed_val": ( "odinw/OxfordPets/by-breed/valid/", "odinw/OxfordPets/by-breed/valid/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-breed_minival": ( "odinw/OxfordPets/by-breed/mini_val/", "odinw/OxfordPets/by-breed/mini_val/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-breed_test": ( "odinw/OxfordPets/by-breed/test/", "odinw/OxfordPets/by-breed/test/annotations_without_background_converted.json", ), }, "odinw_OxfordPets-by-species": { "odinw_OxfordPets_by-species_train": ( "odinw/OxfordPets/by-species/train/", "odinw/OxfordPets/by-species/train/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-species_val": ( "odinw/OxfordPets/by-species/valid/", "odinw/OxfordPets/by-species/valid/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-species_minival": ( "odinw/OxfordPets/by-species/mini_val/", "odinw/OxfordPets/by-species/mini_val/annotations_without_background_converted.json", ), "odinw_OxfordPets_by-species_test": ( "odinw/OxfordPets/by-species/test/", "odinw/OxfordPets/by-species/test/annotations_without_background_converted.json", ), }, "odinw_Packages_Raw": { "odinw_Packages_Raw_train": ( "odinw/Packages/Raw/train/", "odinw/Packages/Raw/train/annotations_without_background_converted.json", ), "odinw_Packages_Raw_val": ( "odinw/Packages/Raw/valid/", "odinw/Packages/Raw/valid/annotations_without_background_converted.json", ), "odinw_Packages_Raw_test": ( "odinw/Packages/Raw/test/", "odinw/Packages/Raw/test/annotations_without_background_converted.json", # "odinw/Packages/Raw/test/_annotations.coco_converted.json", ), }, "odinw_PascalVOC": { "odinw_PascalVOC_train": ( "odinw/PascalVOC/train/", "odinw/PascalVOC/train/annotations_without_background_converted.json", ), "odinw_PascalVOC_val": ( "odinw/PascalVOC/valid/", "odinw/PascalVOC/valid/annotations_without_background_converted.json", ), }, "odinw_pistols_export": { "odinw_pistols_export_train": ( "odinw/pistols/export/", "odinw/pistols/export/train_annotations_without_background_converted.json", ), "odinw_pistols_export_val": ( "odinw/pistols/export/", "odinw/pistols/export/val_annotations_without_background_converted.json", ), "odinw_pistols_export_test": ( "odinw/pistols/export/", "odinw/pistols/export/test_annotations_without_background_converted.json", ), }, "odinw_PKLot_640": { "odinw_PKLot_640_train": ( "odinw/PKLot/640/train/", "odinw/PKLot/640/train/annotations_without_background_converted.json", ), "odinw_PKLot_640_val": ( "odinw/PKLot/640/valid/", "odinw/PKLot/640/valid/annotations_without_background_converted.json", ), "odinw_PKLot_640_minival": ( "odinw/PKLot/640/mini_val/", "odinw/PKLot/640/mini_val/annotations_without_background_converted.json", ), "odinw_PKLot_640_test": ( "odinw/PKLot/640/test/", "odinw/PKLot/640/test/annotations_without_background_converted.json", ), }, "odinw_plantdoc_100x100": { "odinw_plantdoc_100x100_train": ( "odinw/plantdoc/100x100/train/", "odinw/plantdoc/100x100/train/annotations_without_background_converted.json", ), "odinw_plantdoc_100x100_val": ( "odinw/plantdoc/100x100/valid/", "odinw/plantdoc/100x100/valid/annotations_without_background_converted.json", ), "odinw_plantdoc_100x100_test": ( "odinw/plantdoc/100x100/test/", "odinw/plantdoc/100x100/test/annotations_without_background_converted.json", ), }, "odinw_plantdoc_416x416": { "odinw_plantdoc_416x416_train": ( "odinw/plantdoc/416x416/train/", "odinw/plantdoc/416x416/train/annotations_without_background_converted.json", ), "odinw_plantdoc_416x416_val": ( "odinw/plantdoc/416x416/valid/", "odinw/plantdoc/416x416/valid/annotations_without_background_converted.json", ), "odinw_plantdoc_416x416_test": ( "odinw/plantdoc/416x416/test/", "odinw/plantdoc/416x416/test/annotations_without_background_converted.json", ), }, "odinw_pothole": { "odinw_pothole_train": ( "odinw/pothole/train/", "odinw/pothole/train/annotations_without_background_converted.json", ), "odinw_pothole_val": ( "odinw/pothole/valid/", "odinw/pothole/valid/annotations_without_background_converted.json", ), "odinw_pothole_test": ( "odinw/pothole/test/", "odinw/pothole/test/annotations_without_background_converted.json", ), }, "odinw_Raccoon_Raccoon.v2-raw.coco": { "odinw_Raccoon_Raccoon.v2-raw.coco_train": ( "odinw/Raccoon/Raccoon.v2-raw.coco/train/", "odinw/Raccoon/Raccoon.v2-raw.coco/train/annotations_without_background_converted.json", ), "odinw_Raccoon_Raccoon.v2-raw.coco_val": ( "odinw/Raccoon/Raccoon.v2-raw.coco/valid/", "odinw/Raccoon/Raccoon.v2-raw.coco/valid/annotations_without_background_converted.json", ), "odinw_Raccoon_Raccoon.v2-raw.coco_test": ( "odinw/Raccoon/Raccoon.v2-raw.coco/test/", "odinw/Raccoon/Raccoon.v2-raw.coco/test/annotations_without_background_converted.json", ), }, "odinw_selfdrivingCar_fixedLarge_export": { "odinw_selfdrivingCar_fixedLarge_export_train": ( "odinw/selfdrivingCar/fixedLarge/export/", "odinw/selfdrivingCar/fixedLarge/export/train_annotations_without_background_converted.json", ), "odinw_selfdrivingCar_fixedLarge_export_val": ( "odinw/selfdrivingCar/fixedLarge/export/", "odinw/selfdrivingCar/fixedLarge/export/val_annotations_without_background_converted.json", ), "odinw_selfdrivingCar_fixedLarge_export_test": ( "odinw/selfdrivingCar/fixedLarge/export/", "odinw/selfdrivingCar/fixedLarge/export/test_annotations_without_background_converted.json", ), }, "odinw_ShellfishOpenImages_raw": { "odinw_ShellfishOpenImages_raw_train": ( "odinw/ShellfishOpenImages/raw/train/", "odinw/ShellfishOpenImages/raw/train/annotations_without_background_converted.json", ), "odinw_ShellfishOpenImages_raw_val": ( "odinw/ShellfishOpenImages/raw/valid/", "odinw/ShellfishOpenImages/raw/valid/annotations_without_background_converted.json", ), "odinw_ShellfishOpenImages_raw_test": ( "odinw/ShellfishOpenImages/raw/test/", "odinw/ShellfishOpenImages/raw/test/annotations_without_background_converted.json", ), }, "odinw_ThermalCheetah": { "odinw_ThermalCheetah_train": ( "odinw/ThermalCheetah/train/", "odinw/ThermalCheetah/train/annotations_without_background_converted.json", ), "odinw_ThermalCheetah_val": ( "odinw/ThermalCheetah/valid/", "odinw/ThermalCheetah/valid/annotations_without_background_converted.json", ), "odinw_ThermalCheetah_test": ( "odinw/ThermalCheetah/test/", "odinw/ThermalCheetah/test/annotations_without_background_converted.json", ), }, "odinw_thermalDogsAndPeople": { "odinw_thermalDogsAndPeople_train": ( "odinw/thermalDogsAndPeople/train/", "odinw/thermalDogsAndPeople/train/annotations_without_background_converted.json", ), "odinw_thermalDogsAndPeople_val": ( "odinw/thermalDogsAndPeople/valid/", "odinw/thermalDogsAndPeople/valid/annotations_without_background_converted.json", ), "odinw_thermalDogsAndPeople_test": ( "odinw/thermalDogsAndPeople/test/", "odinw/thermalDogsAndPeople/test/annotations_without_background_converted.json", ), }, "odinw_UnoCards_raw": { "odinw_UnoCards_raw_train": ( "odinw/UnoCards/raw/train/", "odinw/UnoCards/raw/train/annotations_without_background_converted.json", ), "odinw_UnoCards_raw_val": ( "odinw/UnoCards/raw/valid/", "odinw/UnoCards/raw/valid/annotations_without_background_converted.json", ), "odinw_UnoCards_raw_minival": ( "odinw/UnoCards/raw/mini_val/", "odinw/UnoCards/raw/mini_val/annotations_without_background_converted.json", ), "odinw_UnoCards_raw_test": ( "odinw/UnoCards/raw/test/", "odinw/UnoCards/raw/test/annotations_without_background_converted.json", ), }, "odinw_VehiclesOpenImages_416x416": { "odinw_VehiclesOpenImages_416x416_train": ( "odinw/VehiclesOpenImages/416x416/train/", "odinw/VehiclesOpenImages/416x416/train/annotations_without_background_converted.json", ), "odinw_VehiclesOpenImages_416x416_val": ( "odinw/VehiclesOpenImages/416x416/valid/", "odinw/VehiclesOpenImages/416x416/valid/annotations_without_background_converted.json", ), "odinw_VehiclesOpenImages_416x416_minival": ( "odinw/VehiclesOpenImages/416x416/mini_val/", "odinw/VehiclesOpenImages/416x416/mini_val/annotations_without_background_converted.json", ), "odinw_VehiclesOpenImages_416x416_test": ( "odinw/VehiclesOpenImages/416x416/test/", "odinw/VehiclesOpenImages/416x416/test/annotations_without_background_converted.json", ), }, "odinw_websiteScreenshots": { "odinw_websiteScreenshots_train": ( "odinw/websiteScreenshots/train/", "odinw/websiteScreenshots/train/annotations_without_background_converted.json", ), "odinw_websiteScreenshots_val": ( "odinw/websiteScreenshots/valid/", "odinw/websiteScreenshots/valid/annotations_without_background_converted.json", ), "odinw_websiteScreenshots_minival": ( "odinw/websiteScreenshots/mini_val/", "odinw/websiteScreenshots/mini_val/annotations_without_background_converted.json", ), "odinw_websiteScreenshots_test": ( "odinw/websiteScreenshots/test/", "odinw/websiteScreenshots/test/annotations_without_background_converted.json", ), }, "odinw_WildfireSmoke": { "odinw_WildfireSmoke_train": ( "odinw/WildfireSmoke/train/", "odinw/WildfireSmoke/train/annotations_without_background_converted.json", ), "odinw_WildfireSmoke_val": ( "odinw/WildfireSmoke/valid/", "odinw/WildfireSmoke/valid/annotations_without_background_converted.json", ), "odinw_WildfireSmoke_test": ( "odinw/WildfireSmoke/test/", "odinw/WildfireSmoke/test/annotations_without_background_converted.json", ), },}
def _get_builtin_metadata(name): meta = {} if name.split("_")[1] in ODINW_PROMPTS: meta["thing_classes"] = [ ODINW_PROMPTS[name.split("_")[1]](m["name"]) for m in ODINW_CATEGORIES[name.split("_")[1]] ] else: meta["thing_classes"] = [m["name"] for m in ODINW_CATEGORIES[name.split("_")[1]]] return meta
def register_all_odinw(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_ODINW.items(): for key, (image_root, json_file) in splits_per_dataset.items(): register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".odinw_instance"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DATASET", "datasets") register_all_odinw(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475ODINW_PROMPTS = { "AerialMaritimeDrone": lambda name: "a ship" if name == "boat" else name, "AmericanSignLanguageLetters": lambda name: "hand gesture '{}'".format(name), "BCCD": lambda name: "Red-Blood-Cell-(RBC)" if name == "RBC" else "White-Blood-Cell-(WBC)" if name == "WBC" else "Blood-Platelet-Cell-(BPC)" if name == "Platelets" else name, "boggleBoards": lambda name: "letter '{}'".format(name.upper()), "brackishUnderwater": lambda name: "big_fish" if name == "fish" else name, "ChessPieces": lambda name: "chess piece {}".format(name), "dice": lambda name: "dice {}".format(name), "DroneControl": lambda name: "body gesture '{}'".format(name), "EgoHands-specific": lambda name: "{} hand".format(name), # "EgoHands-specific": lambda name: "my left hand" # if name == "myleft" # else "my right hand" # if name == "myright" # else "your right hand" # if name == "yourright" # else "your left hand" # if name == "yourleft" # else name, "HardHatWorkers": lambda name: "human head wearing a helmet" if name == "helmet" else "human head" if name == "head" else name, "MaskWearing": lambda name: "human head wearing a mask" if name == "mask" else "human head" if name == "no-mask" else name, "MountainDewCommercial": lambda name: "small {}".format(name), "NorthAmericaMushrooms": lambda name: "mushroom {}".format(name), "openPoetryVision": lambda name: "some text with font {}".format(name), "OxfordPets-by-breed": lambda name: "head of {}".format(name), "OxfordPets-by-species": lambda name: "head of {}".format(name), "PKLot": lambda name: "{} parking slot".format(name), "pothole": lambda name: "broken {}".format(name), "ThermalCheetah": lambda name: "person" if name == "human" else name, "UnoCards": lambda name: "Arabic numerals 0" if name == "0" else "Arabic numerals 1" if name == "1" else "Arabic numerals +4" if name == "2" else "Arabic numerals +2" if name == "3" else "two arrows" if name == "4" else "cross cycle" if name == "5" else "colorful cycle" if name == "6" else "Arabic numerals 2" if name == "7" else "Arabic numerals 3" if name == "8" else "Arabic numerals 4" if name == "9" else "Arabic numerals 5" if name == "10" else "Arabic numerals 6" if name == "11" else "Arabic numerals 7" if name == "12" else "Arabic numerals 8" if name == "13" else "Arabic numerals 9" if name == "14" else name,}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573import contextlibimport ioimport loggingimport os
from detectron2.data import DatasetCatalog, MetadataCatalog
from .coco import custom_load_coco_jsonfrom .openimages_v6_category_image_count import OPENIMAGES_v6_CATEGORY_IMAGE_COUNT
def register_oid_instances(name, metadata, json_file, image_root): """ Register a dataset in COCO's json annotation format for instance detection, instance segmentation and keypoint detection. (i.e., Type 1 and 2 in http://cocodataset.org/#format-data. `instances*.json` and `person_keypoints*.json` in the dataset).
This is an example of how to register a new dataset. You can do something similar to this function, to register new datasets.
Args: name (str): the name that identifies a dataset, e.g. "coco_2014_train". metadata (dict): extra metadata associated with this dataset. You can leave it as an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ assert isinstance(name, str), name assert isinstance(json_file, (str, os.PathLike)), json_file assert isinstance(image_root, (str, os.PathLike)), image_root # 1. register a function which returns dicts DatasetCatalog.register(name, lambda: custom_load_coco_json(json_file, image_root, name))
# 2. Optionally, add metadata about this dataset, # since they might be useful in evaluation, visualization or logging MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="oid", **metadata )
OPENIMAGES_2019_CATEGORIES = [ {"id": 1, "name": "Infant bed", "freebase_id": "/m/061hd_"}, {"id": 2, "name": "Rose", "freebase_id": "/m/06m11"}, {"id": 3, "name": "Flag", "freebase_id": "/m/03120"}, {"id": 4, "name": "Flashlight", "freebase_id": "/m/01kb5b"}, {"id": 5, "name": "Sea turtle", "freebase_id": "/m/0120dh"}, {"id": 6, "name": "Camera", "freebase_id": "/m/0dv5r"}, {"id": 7, "name": "Animal", "freebase_id": "/m/0jbk"}, {"id": 8, "name": "Glove", "freebase_id": "/m/0174n1"}, {"id": 9, "name": "Crocodile", "freebase_id": "/m/09f_2"}, {"id": 10, "name": "Cattle", "freebase_id": "/m/01xq0k1"}, {"id": 11, "name": "House", "freebase_id": "/m/03jm5"}, {"id": 12, "name": "Guacamole", "freebase_id": "/m/02g30s"}, {"id": 13, "name": "Penguin", "freebase_id": "/m/05z6w"}, {"id": 14, "name": "Vehicle registration plate", "freebase_id": "/m/01jfm_"}, {"id": 15, "name": "Bench", "freebase_id": "/m/076lb9"}, {"id": 16, "name": "Ladybug", "freebase_id": "/m/0gj37"}, {"id": 17, "name": "Human nose", "freebase_id": "/m/0k0pj"}, {"id": 18, "name": "Watermelon", "freebase_id": "/m/0kpqd"}, {"id": 19, "name": "Flute", "freebase_id": "/m/0l14j_"}, {"id": 20, "name": "Butterfly", "freebase_id": "/m/0cyf8"}, {"id": 21, "name": "Washing machine", "freebase_id": "/m/0174k2"}, {"id": 22, "name": "Raccoon", "freebase_id": "/m/0dq75"}, {"id": 23, "name": "Segway", "freebase_id": "/m/076bq"}, {"id": 24, "name": "Taco", "freebase_id": "/m/07crc"}, {"id": 25, "name": "Jellyfish", "freebase_id": "/m/0d8zb"}, {"id": 26, "name": "Cake", "freebase_id": "/m/0fszt"}, {"id": 27, "name": "Pen", "freebase_id": "/m/0k1tl"}, {"id": 28, "name": "Cannon", "freebase_id": "/m/020kz"}, {"id": 29, "name": "Bread", "freebase_id": "/m/09728"}, {"id": 30, "name": "Tree", "freebase_id": "/m/07j7r"}, {"id": 31, "name": "Shellfish", "freebase_id": "/m/0fbdv"}, {"id": 32, "name": "Bed", "freebase_id": "/m/03ssj5"}, {"id": 33, "name": "Hamster", "freebase_id": "/m/03qrc"}, {"id": 34, "name": "Hat", "freebase_id": "/m/02dl1y"}, {"id": 35, "name": "Toaster", "freebase_id": "/m/01k6s3"}, {"id": 36, "name": "Sombrero", "freebase_id": "/m/02jfl0"}, {"id": 37, "name": "Tiara", "freebase_id": "/m/01krhy"}, {"id": 38, "name": "Bowl", "freebase_id": "/m/04kkgm"}, {"id": 39, "name": "Dragonfly", "freebase_id": "/m/0ft9s"}, {"id": 40, "name": "Moths and butterflies", "freebase_id": "/m/0d_2m"}, {"id": 41, "name": "Antelope", "freebase_id": "/m/0czz2"}, {"id": 42, "name": "Vegetable", "freebase_id": "/m/0f4s2w"}, {"id": 43, "name": "Torch", "freebase_id": "/m/07dd4"}, {"id": 44, "name": "Building", "freebase_id": "/m/0cgh4"}, {"id": 45, "name": "Power plugs and sockets", "freebase_id": "/m/03bbps"}, {"id": 46, "name": "Blender", "freebase_id": "/m/02pjr4"}, {"id": 47, "name": "Billiard table", "freebase_id": "/m/04p0qw"}, {"id": 48, "name": "Cutting board", "freebase_id": "/m/02pdsw"}, {"id": 49, "name": "Bronze sculpture", "freebase_id": "/m/01yx86"}, {"id": 50, "name": "Turtle", "freebase_id": "/m/09dzg"}, {"id": 51, "name": "Broccoli", "freebase_id": "/m/0hkxq"}, {"id": 52, "name": "Tiger", "freebase_id": "/m/07dm6"}, {"id": 53, "name": "Mirror", "freebase_id": "/m/054_l"}, {"id": 54, "name": "Bear", "freebase_id": "/m/01dws"}, {"id": 55, "name": "Zucchini", "freebase_id": "/m/027pcv"}, {"id": 56, "name": "Dress", "freebase_id": "/m/01d40f"}, {"id": 57, "name": "Volleyball", "freebase_id": "/m/02rgn06"}, {"id": 58, "name": "Guitar", "freebase_id": "/m/0342h"}, {"id": 59, "name": "Reptile", "freebase_id": "/m/06bt6"}, {"id": 60, "name": "Golf cart", "freebase_id": "/m/0323sq"}, {"id": 61, "name": "Tart", "freebase_id": "/m/02zvsm"}, {"id": 62, "name": "Fedora", "freebase_id": "/m/02fq_6"}, {"id": 63, "name": "Carnivore", "freebase_id": "/m/01lrl"}, {"id": 64, "name": "Car", "freebase_id": "/m/0k4j"}, {"id": 65, "name": "Lighthouse", "freebase_id": "/m/04h7h"}, {"id": 66, "name": "Coffeemaker", "freebase_id": "/m/07xyvk"}, {"id": 67, "name": "Food processor", "freebase_id": "/m/03y6mg"}, {"id": 68, "name": "Truck", "freebase_id": "/m/07r04"}, {"id": 69, "name": "Bookcase", "freebase_id": "/m/03__z0"}, {"id": 70, "name": "Surfboard", "freebase_id": "/m/019w40"}, {"id": 71, "name": "Footwear", "freebase_id": "/m/09j5n"}, {"id": 72, "name": "Bench", "freebase_id": "/m/0cvnqh"}, {"id": 73, "name": "Necklace", "freebase_id": "/m/01llwg"}, {"id": 74, "name": "Flower", "freebase_id": "/m/0c9ph5"}, {"id": 75, "name": "Radish", "freebase_id": "/m/015x5n"}, {"id": 76, "name": "Marine mammal", "freebase_id": "/m/0gd2v"}, {"id": 77, "name": "Frying pan", "freebase_id": "/m/04v6l4"}, {"id": 78, "name": "Tap", "freebase_id": "/m/02jz0l"}, {"id": 79, "name": "Peach", "freebase_id": "/m/0dj6p"}, {"id": 80, "name": "Knife", "freebase_id": "/m/04ctx"}, {"id": 81, "name": "Handbag", "freebase_id": "/m/080hkjn"}, {"id": 82, "name": "Laptop", "freebase_id": "/m/01c648"}, {"id": 83, "name": "Tent", "freebase_id": "/m/01j61q"}, {"id": 84, "name": "Ambulance", "freebase_id": "/m/012n7d"}, {"id": 85, "name": "Christmas tree", "freebase_id": "/m/025nd"}, {"id": 86, "name": "Eagle", "freebase_id": "/m/09csl"}, {"id": 87, "name": "Limousine", "freebase_id": "/m/01lcw4"}, {"id": 88, "name": "Kitchen & dining room table", "freebase_id": "/m/0h8n5zk"}, {"id": 89, "name": "Polar bear", "freebase_id": "/m/0633h"}, {"id": 90, "name": "Tower", "freebase_id": "/m/01fdzj"}, {"id": 91, "name": "Football", "freebase_id": "/m/01226z"}, {"id": 92, "name": "Willow", "freebase_id": "/m/0mw_6"}, {"id": 93, "name": "Human head", "freebase_id": "/m/04hgtk"}, {"id": 94, "name": "Stop sign", "freebase_id": "/m/02pv19"}, {"id": 95, "name": "Banana", "freebase_id": "/m/09qck"}, {"id": 96, "name": "Mixer", "freebase_id": "/m/063rgb"}, {"id": 97, "name": "Binoculars", "freebase_id": "/m/0lt4_"}, {"id": 98, "name": "Dessert", "freebase_id": "/m/0270h"}, {"id": 99, "name": "Bee", "freebase_id": "/m/01h3n"}, {"id": 100, "name": "Chair", "freebase_id": "/m/01mzpv"}, {"id": 101, "name": "Wood-burning stove", "freebase_id": "/m/04169hn"}, {"id": 102, "name": "Flowerpot", "freebase_id": "/m/0fm3zh"}, {"id": 103, "name": "Beaker", "freebase_id": "/m/0d20w4"}, {"id": 104, "name": "Oyster", "freebase_id": "/m/0_cp5"}, {"id": 105, "name": "Woodpecker", "freebase_id": "/m/01dy8n"}, {"id": 106, "name": "Harp", "freebase_id": "/m/03m5k"}, {"id": 107, "name": "Bathtub", "freebase_id": "/m/03dnzn"}, {"id": 108, "name": "Wall clock", "freebase_id": "/m/0h8mzrc"}, {"id": 109, "name": "Sports uniform", "freebase_id": "/m/0h8mhzd"}, {"id": 110, "name": "Rhinoceros", "freebase_id": "/m/03d443"}, {"id": 111, "name": "Beehive", "freebase_id": "/m/01gllr"}, {"id": 112, "name": "Cupboard", "freebase_id": "/m/0642b4"}, {"id": 113, "name": "Chicken", "freebase_id": "/m/09b5t"}, {"id": 114, "name": "Man", "freebase_id": "/m/04yx4"}, {"id": 115, "name": "Blue jay", "freebase_id": "/m/01f8m5"}, {"id": 116, "name": "Cucumber", "freebase_id": "/m/015x4r"}, {"id": 117, "name": "Balloon", "freebase_id": "/m/01j51"}, {"id": 118, "name": "Kite", "freebase_id": "/m/02zt3"}, {"id": 119, "name": "Fireplace", "freebase_id": "/m/03tw93"}, {"id": 120, "name": "Lantern", "freebase_id": "/m/01jfsr"}, {"id": 121, "name": "Missile", "freebase_id": "/m/04ylt"}, {"id": 122, "name": "Book", "freebase_id": "/m/0bt_c3"}, {"id": 123, "name": "Spoon", "freebase_id": "/m/0cmx8"}, {"id": 124, "name": "Grapefruit", "freebase_id": "/m/0hqkz"}, {"id": 125, "name": "Squirrel", "freebase_id": "/m/071qp"}, {"id": 126, "name": "Orange", "freebase_id": "/m/0cyhj_"}, {"id": 127, "name": "Coat", "freebase_id": "/m/01xygc"}, {"id": 128, "name": "Punching bag", "freebase_id": "/m/0420v5"}, {"id": 129, "name": "Zebra", "freebase_id": "/m/0898b"}, {"id": 130, "name": "Billboard", "freebase_id": "/m/01knjb"}, {"id": 131, "name": "Bicycle", "freebase_id": "/m/0199g"}, {"id": 132, "name": "Door handle", "freebase_id": "/m/03c7gz"}, {"id": 133, "name": "Mechanical fan", "freebase_id": "/m/02x984l"}, {"id": 134, "name": "Ring binder", "freebase_id": "/m/04zwwv"}, {"id": 135, "name": "Table", "freebase_id": "/m/04bcr3"}, {"id": 136, "name": "Parrot", "freebase_id": "/m/0gv1x"}, {"id": 137, "name": "Sock", "freebase_id": "/m/01nq26"}, {"id": 138, "name": "Vase", "freebase_id": "/m/02s195"}, {"id": 139, "name": "Weapon", "freebase_id": "/m/083kb"}, {"id": 140, "name": "Shotgun", "freebase_id": "/m/06nrc"}, {"id": 141, "name": "Glasses", "freebase_id": "/m/0jyfg"}, {"id": 142, "name": "Seahorse", "freebase_id": "/m/0nybt"}, {"id": 143, "name": "Belt", "freebase_id": "/m/0176mf"}, {"id": 144, "name": "Watercraft", "freebase_id": "/m/01rzcn"}, {"id": 145, "name": "Window", "freebase_id": "/m/0d4v4"}, {"id": 146, "name": "Giraffe", "freebase_id": "/m/03bk1"}, {"id": 147, "name": "Lion", "freebase_id": "/m/096mb"}, {"id": 148, "name": "Tire", "freebase_id": "/m/0h9mv"}, {"id": 149, "name": "Vehicle", "freebase_id": "/m/07yv9"}, {"id": 150, "name": "Canoe", "freebase_id": "/m/0ph39"}, {"id": 151, "name": "Tie", "freebase_id": "/m/01rkbr"}, {"id": 152, "name": "Shelf", "freebase_id": "/m/0gjbg72"}, {"id": 153, "name": "Picture frame", "freebase_id": "/m/06z37_"}, {"id": 154, "name": "Printer", "freebase_id": "/m/01m4t"}, {"id": 155, "name": "Human leg", "freebase_id": "/m/035r7c"}, {"id": 156, "name": "Boat", "freebase_id": "/m/019jd"}, {"id": 157, "name": "Slow cooker", "freebase_id": "/m/02tsc9"}, {"id": 158, "name": "Croissant", "freebase_id": "/m/015wgc"}, {"id": 159, "name": "Candle", "freebase_id": "/m/0c06p"}, {"id": 160, "name": "Pancake", "freebase_id": "/m/01dwwc"}, {"id": 161, "name": "Pillow", "freebase_id": "/m/034c16"}, {"id": 162, "name": "Coin", "freebase_id": "/m/0242l"}, {"id": 163, "name": "Stretcher", "freebase_id": "/m/02lbcq"}, {"id": 164, "name": "Sandal", "freebase_id": "/m/03nfch"}, {"id": 165, "name": "Woman", "freebase_id": "/m/03bt1vf"}, {"id": 166, "name": "Stairs", "freebase_id": "/m/01lynh"}, {"id": 167, "name": "Harpsichord", "freebase_id": "/m/03q5t"}, {"id": 168, "name": "Stool", "freebase_id": "/m/0fqt361"}, {"id": 169, "name": "Bus", "freebase_id": "/m/01bjv"}, {"id": 170, "name": "Suitcase", "freebase_id": "/m/01s55n"}, {"id": 171, "name": "Human mouth", "freebase_id": "/m/0283dt1"}, {"id": 172, "name": "Juice", "freebase_id": "/m/01z1kdw"}, {"id": 173, "name": "Skull", "freebase_id": "/m/016m2d"}, {"id": 174, "name": "Door", "freebase_id": "/m/02dgv"}, {"id": 175, "name": "Violin", "freebase_id": "/m/07y_7"}, {"id": 176, "name": "Chopsticks", "freebase_id": "/m/01_5g"}, {"id": 177, "name": "Digital clock", "freebase_id": "/m/06_72j"}, {"id": 178, "name": "Sunflower", "freebase_id": "/m/0ftb8"}, {"id": 179, "name": "Leopard", "freebase_id": "/m/0c29q"}, {"id": 180, "name": "Bell pepper", "freebase_id": "/m/0jg57"}, {"id": 181, "name": "Harbor seal", "freebase_id": "/m/02l8p9"}, {"id": 182, "name": "Snake", "freebase_id": "/m/078jl"}, {"id": 183, "name": "Sewing machine", "freebase_id": "/m/0llzx"}, {"id": 184, "name": "Goose", "freebase_id": "/m/0dbvp"}, {"id": 185, "name": "Helicopter", "freebase_id": "/m/09ct_"}, {"id": 186, "name": "Seat belt", "freebase_id": "/m/0dkzw"}, {"id": 187, "name": "Coffee cup", "freebase_id": "/m/02p5f1q"}, {"id": 188, "name": "Microwave oven", "freebase_id": "/m/0fx9l"}, {"id": 189, "name": "Hot dog", "freebase_id": "/m/01b9xk"}, {"id": 190, "name": "Countertop", "freebase_id": "/m/0b3fp9"}, {"id": 191, "name": "Serving tray", "freebase_id": "/m/0h8n27j"}, {"id": 192, "name": "Dog bed", "freebase_id": "/m/0h8n6f9"}, {"id": 193, "name": "Beer", "freebase_id": "/m/01599"}, {"id": 194, "name": "Sunglasses", "freebase_id": "/m/017ftj"}, {"id": 195, "name": "Golf ball", "freebase_id": "/m/044r5d"}, {"id": 196, "name": "Waffle", "freebase_id": "/m/01dwsz"}, {"id": 197, "name": "Palm tree", "freebase_id": "/m/0cdl1"}, {"id": 198, "name": "Trumpet", "freebase_id": "/m/07gql"}, {"id": 199, "name": "Ruler", "freebase_id": "/m/0hdln"}, {"id": 200, "name": "Helmet", "freebase_id": "/m/0zvk5"}, {"id": 201, "name": "Ladder", "freebase_id": "/m/012w5l"}, {"id": 202, "name": "Office building", "freebase_id": "/m/021sj1"}, {"id": 203, "name": "Tablet computer", "freebase_id": "/m/0bh9flk"}, {"id": 204, "name": "Toilet paper", "freebase_id": "/m/09gtd"}, {"id": 205, "name": "Pomegranate", "freebase_id": "/m/0jwn_"}, {"id": 206, "name": "Skirt", "freebase_id": "/m/02wv6h6"}, {"id": 207, "name": "Gas stove", "freebase_id": "/m/02wv84t"}, {"id": 208, "name": "Cookie", "freebase_id": "/m/021mn"}, {"id": 209, "name": "Cart", "freebase_id": "/m/018p4k"}, {"id": 210, "name": "Raven", "freebase_id": "/m/06j2d"}, {"id": 211, "name": "Egg", "freebase_id": "/m/033cnk"}, {"id": 212, "name": "Burrito", "freebase_id": "/m/01j3zr"}, {"id": 213, "name": "Goat", "freebase_id": "/m/03fwl"}, {"id": 214, "name": "Kitchen knife", "freebase_id": "/m/058qzx"}, {"id": 215, "name": "Skateboard", "freebase_id": "/m/06_fw"}, {"id": 216, "name": "Salt and pepper shakers", "freebase_id": "/m/02x8cch"}, {"id": 217, "name": "Lynx", "freebase_id": "/m/04g2r"}, {"id": 218, "name": "Boot", "freebase_id": "/m/01b638"}, {"id": 219, "name": "Platter", "freebase_id": "/m/099ssp"}, {"id": 220, "name": "Ski", "freebase_id": "/m/071p9"}, {"id": 221, "name": "Swimwear", "freebase_id": "/m/01gkx_"}, {"id": 222, "name": "Swimming pool", "freebase_id": "/m/0b_rs"}, {"id": 223, "name": "Drinking straw", "freebase_id": "/m/03v5tg"}, {"id": 224, "name": "Wrench", "freebase_id": "/m/01j5ks"}, {"id": 225, "name": "Drum", "freebase_id": "/m/026t6"}, {"id": 226, "name": "Ant", "freebase_id": "/m/0_k2"}, {"id": 227, "name": "Human ear", "freebase_id": "/m/039xj_"}, {"id": 228, "name": "Headphones", "freebase_id": "/m/01b7fy"}, {"id": 229, "name": "Fountain", "freebase_id": "/m/0220r2"}, {"id": 230, "name": "Bird", "freebase_id": "/m/015p6"}, {"id": 231, "name": "Jeans", "freebase_id": "/m/0fly7"}, {"id": 232, "name": "Television", "freebase_id": "/m/07c52"}, {"id": 233, "name": "Crab", "freebase_id": "/m/0n28_"}, {"id": 234, "name": "Microphone", "freebase_id": "/m/0hg7b"}, {"id": 235, "name": "Home appliance", "freebase_id": "/m/019dx1"}, {"id": 236, "name": "Snowplow", "freebase_id": "/m/04vv5k"}, {"id": 237, "name": "Beetle", "freebase_id": "/m/020jm"}, {"id": 238, "name": "Artichoke", "freebase_id": "/m/047v4b"}, {"id": 239, "name": "Jet ski", "freebase_id": "/m/01xs3r"}, {"id": 240, "name": "Stationary bicycle", "freebase_id": "/m/03kt2w"}, {"id": 241, "name": "Human hair", "freebase_id": "/m/03q69"}, {"id": 242, "name": "Brown bear", "freebase_id": "/m/01dxs"}, {"id": 243, "name": "Starfish", "freebase_id": "/m/01h8tj"}, {"id": 244, "name": "Fork", "freebase_id": "/m/0dt3t"}, {"id": 245, "name": "Lobster", "freebase_id": "/m/0cjq5"}, {"id": 246, "name": "Corded phone", "freebase_id": "/m/0h8lkj8"}, {"id": 247, "name": "Drink", "freebase_id": "/m/0271t"}, {"id": 248, "name": "Saucer", "freebase_id": "/m/03q5c7"}, {"id": 249, "name": "Carrot", "freebase_id": "/m/0fj52s"}, {"id": 250, "name": "Insect", "freebase_id": "/m/03vt0"}, {"id": 251, "name": "Clock", "freebase_id": "/m/01x3z"}, {"id": 252, "name": "Castle", "freebase_id": "/m/0d5gx"}, {"id": 253, "name": "Tennis racket", "freebase_id": "/m/0h8my_4"}, {"id": 254, "name": "Ceiling fan", "freebase_id": "/m/03ldnb"}, {"id": 255, "name": "Asparagus", "freebase_id": "/m/0cjs7"}, {"id": 256, "name": "Jaguar", "freebase_id": "/m/0449p"}, {"id": 257, "name": "Musical instrument", "freebase_id": "/m/04szw"}, {"id": 258, "name": "Train", "freebase_id": "/m/07jdr"}, {"id": 259, "name": "Cat", "freebase_id": "/m/01yrx"}, {"id": 260, "name": "Rifle", "freebase_id": "/m/06c54"}, {"id": 261, "name": "Dumbbell", "freebase_id": "/m/04h8sr"}, {"id": 262, "name": "Mobile phone", "freebase_id": "/m/050k8"}, {"id": 263, "name": "Taxi", "freebase_id": "/m/0pg52"}, {"id": 264, "name": "Shower", "freebase_id": "/m/02f9f_"}, {"id": 265, "name": "Pitcher", "freebase_id": "/m/054fyh"}, {"id": 266, "name": "Lemon", "freebase_id": "/m/09k_b"}, {"id": 267, "name": "Invertebrate", "freebase_id": "/m/03xxp"}, {"id": 268, "name": "Turkey", "freebase_id": "/m/0jly1"}, {"id": 269, "name": "High heels", "freebase_id": "/m/06k2mb"}, {"id": 270, "name": "Bust", "freebase_id": "/m/04yqq2"}, {"id": 271, "name": "Elephant", "freebase_id": "/m/0bwd_0j"}, {"id": 272, "name": "Scarf", "freebase_id": "/m/02h19r"}, {"id": 273, "name": "Barrel", "freebase_id": "/m/02zn6n"}, {"id": 274, "name": "Trombone", "freebase_id": "/m/07c6l"}, {"id": 275, "name": "Pumpkin", "freebase_id": "/m/05zsy"}, {"id": 276, "name": "Box", "freebase_id": "/m/025dyy"}, {"id": 277, "name": "Tomato", "freebase_id": "/m/07j87"}, {"id": 278, "name": "Frog", "freebase_id": "/m/09ld4"}, {"id": 279, "name": "Bidet", "freebase_id": "/m/01vbnl"}, {"id": 280, "name": "Human face", "freebase_id": "/m/0dzct"}, {"id": 281, "name": "Houseplant", "freebase_id": "/m/03fp41"}, {"id": 282, "name": "Van", "freebase_id": "/m/0h2r6"}, {"id": 283, "name": "Shark", "freebase_id": "/m/0by6g"}, {"id": 284, "name": "Ice cream", "freebase_id": "/m/0cxn2"}, {"id": 285, "name": "Swim cap", "freebase_id": "/m/04tn4x"}, {"id": 286, "name": "Falcon", "freebase_id": "/m/0f6wt"}, {"id": 287, "name": "Ostrich", "freebase_id": "/m/05n4y"}, {"id": 288, "name": "Handgun", "freebase_id": "/m/0gxl3"}, {"id": 289, "name": "Whiteboard", "freebase_id": "/m/02d9qx"}, {"id": 290, "name": "Lizard", "freebase_id": "/m/04m9y"}, {"id": 291, "name": "Pasta", "freebase_id": "/m/05z55"}, {"id": 292, "name": "Snowmobile", "freebase_id": "/m/01x3jk"}, {"id": 293, "name": "Light bulb", "freebase_id": "/m/0h8l4fh"}, {"id": 294, "name": "Window blind", "freebase_id": "/m/031b6r"}, {"id": 295, "name": "Muffin", "freebase_id": "/m/01tcjp"}, {"id": 296, "name": "Pretzel", "freebase_id": "/m/01f91_"}, {"id": 297, "name": "Computer monitor", "freebase_id": "/m/02522"}, {"id": 298, "name": "Horn", "freebase_id": "/m/0319l"}, {"id": 299, "name": "Furniture", "freebase_id": "/m/0c_jw"}, {"id": 300, "name": "Sandwich", "freebase_id": "/m/0l515"}, {"id": 301, "name": "Fox", "freebase_id": "/m/0306r"}, {"id": 302, "name": "Convenience store", "freebase_id": "/m/0crjs"}, {"id": 303, "name": "Fish", "freebase_id": "/m/0ch_cf"}, {"id": 304, "name": "Fruit", "freebase_id": "/m/02xwb"}, {"id": 305, "name": "Earrings", "freebase_id": "/m/01r546"}, {"id": 306, "name": "Curtain", "freebase_id": "/m/03rszm"}, {"id": 307, "name": "Grape", "freebase_id": "/m/0388q"}, {"id": 308, "name": "Sofa bed", "freebase_id": "/m/03m3pdh"}, {"id": 309, "name": "Horse", "freebase_id": "/m/03k3r"}, {"id": 310, "name": "Luggage and bags", "freebase_id": "/m/0hf58v5"}, {"id": 311, "name": "Desk", "freebase_id": "/m/01y9k5"}, {"id": 312, "name": "Crutch", "freebase_id": "/m/05441v"}, {"id": 313, "name": "Bicycle helmet", "freebase_id": "/m/03p3bw"}, {"id": 314, "name": "Tick", "freebase_id": "/m/0175cv"}, {"id": 315, "name": "Airplane", "freebase_id": "/m/0cmf2"}, {"id": 316, "name": "Canary", "freebase_id": "/m/0ccs93"}, {"id": 317, "name": "Spatula", "freebase_id": "/m/02d1br"}, {"id": 318, "name": "Watch", "freebase_id": "/m/0gjkl"}, {"id": 319, "name": "Lily", "freebase_id": "/m/0jqgx"}, {"id": 320, "name": "Kitchen appliance", "freebase_id": "/m/0h99cwc"}, {"id": 321, "name": "Filing cabinet", "freebase_id": "/m/047j0r"}, {"id": 322, "name": "Aircraft", "freebase_id": "/m/0k5j"}, {"id": 323, "name": "Cake stand", "freebase_id": "/m/0h8n6ft"}, {"id": 324, "name": "Candy", "freebase_id": "/m/0gm28"}, {"id": 325, "name": "Sink", "freebase_id": "/m/0130jx"}, {"id": 326, "name": "Mouse", "freebase_id": "/m/04rmv"}, {"id": 327, "name": "Wine", "freebase_id": "/m/081qc"}, {"id": 328, "name": "Wheelchair", "freebase_id": "/m/0qmmr"}, {"id": 329, "name": "Goldfish", "freebase_id": "/m/03fj2"}, {"id": 330, "name": "Refrigerator", "freebase_id": "/m/040b_t"}, {"id": 331, "name": "French fries", "freebase_id": "/m/02y6n"}, {"id": 332, "name": "Drawer", "freebase_id": "/m/0fqfqc"}, {"id": 333, "name": "Treadmill", "freebase_id": "/m/030610"}, {"id": 334, "name": "Picnic basket", "freebase_id": "/m/07kng9"}, {"id": 335, "name": "Dice", "freebase_id": "/m/029b3"}, {"id": 336, "name": "Cabbage", "freebase_id": "/m/0fbw6"}, {"id": 337, "name": "Football helmet", "freebase_id": "/m/07qxg_"}, {"id": 338, "name": "Pig", "freebase_id": "/m/068zj"}, {"id": 339, "name": "Person", "freebase_id": "/m/01g317"}, {"id": 340, "name": "Shorts", "freebase_id": "/m/01bfm9"}, {"id": 341, "name": "Gondola", "freebase_id": "/m/02068x"}, {"id": 342, "name": "Honeycomb", "freebase_id": "/m/0fz0h"}, {"id": 343, "name": "Doughnut", "freebase_id": "/m/0jy4k"}, {"id": 344, "name": "Chest of drawers", "freebase_id": "/m/05kyg_"}, {"id": 345, "name": "Land vehicle", "freebase_id": "/m/01prls"}, {"id": 346, "name": "Bat", "freebase_id": "/m/01h44"}, {"id": 347, "name": "Monkey", "freebase_id": "/m/08pbxl"}, {"id": 348, "name": "Dagger", "freebase_id": "/m/02gzp"}, {"id": 349, "name": "Tableware", "freebase_id": "/m/04brg2"}, {"id": 350, "name": "Human foot", "freebase_id": "/m/031n1"}, {"id": 351, "name": "Mug", "freebase_id": "/m/02jvh9"}, {"id": 352, "name": "Alarm clock", "freebase_id": "/m/046dlr"}, {"id": 353, "name": "Pressure cooker", "freebase_id": "/m/0h8ntjv"}, {"id": 354, "name": "Human hand", "freebase_id": "/m/0k65p"}, {"id": 355, "name": "Tortoise", "freebase_id": "/m/011k07"}, {"id": 356, "name": "Baseball glove", "freebase_id": "/m/03grzl"}, {"id": 357, "name": "Sword", "freebase_id": "/m/06y5r"}, {"id": 358, "name": "Pear", "freebase_id": "/m/061_f"}, {"id": 359, "name": "Miniskirt", "freebase_id": "/m/01cmb2"}, {"id": 360, "name": "Traffic sign", "freebase_id": "/m/01mqdt"}, {"id": 361, "name": "Girl", "freebase_id": "/m/05r655"}, {"id": 362, "name": "Roller skates", "freebase_id": "/m/02p3w7d"}, {"id": 363, "name": "Dinosaur", "freebase_id": "/m/029tx"}, {"id": 364, "name": "Porch", "freebase_id": "/m/04m6gz"}, {"id": 365, "name": "Human beard", "freebase_id": "/m/015h_t"}, {"id": 366, "name": "Submarine sandwich", "freebase_id": "/m/06pcq"}, {"id": 367, "name": "Screwdriver", "freebase_id": "/m/01bms0"}, {"id": 368, "name": "Strawberry", "freebase_id": "/m/07fbm7"}, {"id": 369, "name": "Wine glass", "freebase_id": "/m/09tvcd"}, {"id": 370, "name": "Seafood", "freebase_id": "/m/06nwz"}, {"id": 371, "name": "Racket", "freebase_id": "/m/0dv9c"}, {"id": 372, "name": "Wheel", "freebase_id": "/m/083wq"}, {"id": 373, "name": "Sea lion", "freebase_id": "/m/0gd36"}, {"id": 374, "name": "Toy", "freebase_id": "/m/0138tl"}, {"id": 375, "name": "Tea", "freebase_id": "/m/07clx"}, {"id": 376, "name": "Tennis ball", "freebase_id": "/m/05ctyq"}, {"id": 377, "name": "Waste container", "freebase_id": "/m/0bjyj5"}, {"id": 378, "name": "Mule", "freebase_id": "/m/0dbzx"}, {"id": 379, "name": "Cricket ball", "freebase_id": "/m/02ctlc"}, {"id": 380, "name": "Pineapple", "freebase_id": "/m/0fp6w"}, {"id": 381, "name": "Coconut", "freebase_id": "/m/0djtd"}, {"id": 382, "name": "Doll", "freebase_id": "/m/0167gd"}, {"id": 383, "name": "Coffee table", "freebase_id": "/m/078n6m"}, {"id": 384, "name": "Snowman", "freebase_id": "/m/0152hh"}, {"id": 385, "name": "Lavender", "freebase_id": "/m/04gth"}, {"id": 386, "name": "Shrimp", "freebase_id": "/m/0ll1f78"}, {"id": 387, "name": "Maple", "freebase_id": "/m/0cffdh"}, {"id": 388, "name": "Cowboy hat", "freebase_id": "/m/025rp__"}, {"id": 389, "name": "Goggles", "freebase_id": "/m/02_n6y"}, {"id": 390, "name": "Rugby ball", "freebase_id": "/m/0wdt60w"}, {"id": 391, "name": "Caterpillar", "freebase_id": "/m/0cydv"}, {"id": 392, "name": "Poster", "freebase_id": "/m/01n5jq"}, {"id": 393, "name": "Rocket", "freebase_id": "/m/09rvcxw"}, {"id": 394, "name": "Organ", "freebase_id": "/m/013y1f"}, {"id": 395, "name": "Saxophone", "freebase_id": "/m/06ncr"}, {"id": 396, "name": "Traffic light", "freebase_id": "/m/015qff"}, {"id": 397, "name": "Cocktail", "freebase_id": "/m/024g6"}, {"id": 398, "name": "Plastic bag", "freebase_id": "/m/05gqfk"}, {"id": 399, "name": "Squash", "freebase_id": "/m/0dv77"}, {"id": 400, "name": "Mushroom", "freebase_id": "/m/052sf"}, {"id": 401, "name": "Hamburger", "freebase_id": "/m/0cdn1"}, {"id": 402, "name": "Light switch", "freebase_id": "/m/03jbxj"}, {"id": 403, "name": "Parachute", "freebase_id": "/m/0cyfs"}, {"id": 404, "name": "Teddy bear", "freebase_id": "/m/0kmg4"}, {"id": 405, "name": "Winter melon", "freebase_id": "/m/02cvgx"}, {"id": 406, "name": "Deer", "freebase_id": "/m/09kx5"}, {"id": 407, "name": "Musical keyboard", "freebase_id": "/m/057cc"}, {"id": 408, "name": "Plumbing fixture", "freebase_id": "/m/02pkr5"}, {"id": 409, "name": "Scoreboard", "freebase_id": "/m/057p5t"}, {"id": 410, "name": "Baseball bat", "freebase_id": "/m/03g8mr"}, {"id": 411, "name": "Envelope", "freebase_id": "/m/0frqm"}, {"id": 412, "name": "Adhesive tape", "freebase_id": "/m/03m3vtv"}, {"id": 413, "name": "Briefcase", "freebase_id": "/m/0584n8"}, {"id": 414, "name": "Paddle", "freebase_id": "/m/014y4n"}, {"id": 415, "name": "Bow and arrow", "freebase_id": "/m/01g3x7"}, {"id": 416, "name": "Telephone", "freebase_id": "/m/07cx4"}, {"id": 417, "name": "Sheep", "freebase_id": "/m/07bgp"}, {"id": 418, "name": "Jacket", "freebase_id": "/m/032b3c"}, {"id": 419, "name": "Boy", "freebase_id": "/m/01bl7v"}, {"id": 420, "name": "Pizza", "freebase_id": "/m/0663v"}, {"id": 421, "name": "Otter", "freebase_id": "/m/0cn6p"}, {"id": 422, "name": "Office supplies", "freebase_id": "/m/02rdsp"}, {"id": 423, "name": "Couch", "freebase_id": "/m/02crq1"}, {"id": 424, "name": "Cello", "freebase_id": "/m/01xqw"}, {"id": 425, "name": "Bull", "freebase_id": "/m/0cnyhnx"}, {"id": 426, "name": "Camel", "freebase_id": "/m/01x_v"}, {"id": 427, "name": "Ball", "freebase_id": "/m/018xm"}, {"id": 428, "name": "Duck", "freebase_id": "/m/09ddx"}, {"id": 429, "name": "Whale", "freebase_id": "/m/084zz"}, {"id": 430, "name": "Shirt", "freebase_id": "/m/01n4qj"}, {"id": 431, "name": "Tank", "freebase_id": "/m/07cmd"}, {"id": 432, "name": "Motorcycle", "freebase_id": "/m/04_sv"}, {"id": 433, "name": "Accordion", "freebase_id": "/m/0mkg"}, {"id": 434, "name": "Owl", "freebase_id": "/m/09d5_"}, {"id": 435, "name": "Porcupine", "freebase_id": "/m/0c568"}, {"id": 436, "name": "Sun hat", "freebase_id": "/m/02wbtzl"}, {"id": 437, "name": "Nail", "freebase_id": "/m/05bm6"}, {"id": 438, "name": "Scissors", "freebase_id": "/m/01lsmm"}, {"id": 439, "name": "Swan", "freebase_id": "/m/0dftk"}, {"id": 440, "name": "Lamp", "freebase_id": "/m/0dtln"}, {"id": 441, "name": "Crown", "freebase_id": "/m/0nl46"}, {"id": 442, "name": "Piano", "freebase_id": "/m/05r5c"}, {"id": 443, "name": "Sculpture", "freebase_id": "/m/06msq"}, {"id": 444, "name": "Cheetah", "freebase_id": "/m/0cd4d"}, {"id": 445, "name": "Oboe", "freebase_id": "/m/05kms"}, {"id": 446, "name": "Tin can", "freebase_id": "/m/02jnhm"}, {"id": 447, "name": "Mango", "freebase_id": "/m/0fldg"}, {"id": 448, "name": "Tripod", "freebase_id": "/m/073bxn"}, {"id": 449, "name": "Oven", "freebase_id": "/m/029bxz"}, {"id": 450, "name": "Mouse", "freebase_id": "/m/020lf"}, {"id": 451, "name": "Barge", "freebase_id": "/m/01btn"}, {"id": 452, "name": "Coffee", "freebase_id": "/m/02vqfm"}, {"id": 453, "name": "Snowboard", "freebase_id": "/m/06__v"}, {"id": 454, "name": "Common fig", "freebase_id": "/m/043nyj"}, {"id": 455, "name": "Salad", "freebase_id": "/m/0grw1"}, {"id": 456, "name": "Marine invertebrates", "freebase_id": "/m/03hl4l9"}, {"id": 457, "name": "Umbrella", "freebase_id": "/m/0hnnb"}, {"id": 458, "name": "Kangaroo", "freebase_id": "/m/04c0y"}, {"id": 459, "name": "Human arm", "freebase_id": "/m/0dzf4"}, {"id": 460, "name": "Measuring cup", "freebase_id": "/m/07v9_z"}, {"id": 461, "name": "Snail", "freebase_id": "/m/0f9_l"}, {"id": 462, "name": "Loveseat", "freebase_id": "/m/0703r8"}, {"id": 463, "name": "Suit", "freebase_id": "/m/01xyhv"}, {"id": 464, "name": "Teapot", "freebase_id": "/m/01fh4r"}, {"id": 465, "name": "Bottle", "freebase_id": "/m/04dr76w"}, {"id": 466, "name": "Alpaca", "freebase_id": "/m/0pcr"}, {"id": 467, "name": "Kettle", "freebase_id": "/m/03s_tn"}, {"id": 468, "name": "Trousers", "freebase_id": "/m/07mhn"}, {"id": 469, "name": "Popcorn", "freebase_id": "/m/01hrv5"}, {"id": 470, "name": "Centipede", "freebase_id": "/m/019h78"}, {"id": 471, "name": "Spider", "freebase_id": "/m/09kmb"}, {"id": 472, "name": "Sparrow", "freebase_id": "/m/0h23m"}, {"id": 473, "name": "Plate", "freebase_id": "/m/050gv4"}, {"id": 474, "name": "Bagel", "freebase_id": "/m/01fb_0"}, {"id": 475, "name": "Personal care", "freebase_id": "/m/02w3_ws"}, {"id": 476, "name": "Apple", "freebase_id": "/m/014j1m"}, {"id": 477, "name": "Brassiere", "freebase_id": "/m/01gmv2"}, {"id": 478, "name": "Bathroom cabinet", "freebase_id": "/m/04y4h8h"}, {"id": 479, "name": "studio couch", "freebase_id": "/m/026qbn5"}, {"id": 480, "name": "Computer keyboard", "freebase_id": "/m/01m2v"}, {"id": 481, "name": "Table tennis racket", "freebase_id": "/m/05_5p_0"}, {"id": 482, "name": "Sushi", "freebase_id": "/m/07030"}, {"id": 483, "name": "Cabinetry", "freebase_id": "/m/01s105"}, {"id": 484, "name": "Street light", "freebase_id": "/m/033rq4"}, {"id": 485, "name": "Towel", "freebase_id": "/m/0162_1"}, {"id": 486, "name": "Nightstand", "freebase_id": "/m/02z51p"}, {"id": 487, "name": "Rabbit", "freebase_id": "/m/06mf6"}, {"id": 488, "name": "Dolphin", "freebase_id": "/m/02hj4"}, {"id": 489, "name": "Dog", "freebase_id": "/m/0bt9lr"}, {"id": 490, "name": "Jug", "freebase_id": "/m/08hvt4"}, {"id": 491, "name": "Wok", "freebase_id": "/m/084rd"}, {"id": 492, "name": "Fire hydrant", "freebase_id": "/m/01pns0"}, {"id": 493, "name": "Human eye", "freebase_id": "/m/014sv8"}, {"id": 494, "name": "Skyscraper", "freebase_id": "/m/079cl"}, {"id": 495, "name": "Backpack", "freebase_id": "/m/01940j"}, {"id": 496, "name": "Potato", "freebase_id": "/m/05vtc"}, {"id": 497, "name": "Paper towel", "freebase_id": "/m/02w3r3"}, {"id": 498, "name": "Lifejacket", "freebase_id": "/m/054xkw"}, {"id": 499, "name": "Bicycle wheel", "freebase_id": "/m/01bqk0"}, {"id": 500, "name": "Toilet", "freebase_id": "/m/09g1w"},]
OPENIMAGES_V6_CATEGORIES = [ {"id": 1, "name": "Tortoise", "freebase_id": "/m/011k07"}, {"id": 2, "name": "Container", "freebase_id": "/m/011q46kg"}, {"id": 3, "name": "Magpie", "freebase_id": "/m/012074"}, {"id": 4, "name": "Sea turtle", "freebase_id": "/m/0120dh"}, {"id": 5, "name": "Football", "freebase_id": "/m/01226z"}, {"id": 6, "name": "Ambulance", "freebase_id": "/m/012n7d"}, {"id": 7, "name": "Ladder", "freebase_id": "/m/012w5l"}, {"id": 8, "name": "Toothbrush", "freebase_id": "/m/012xff"}, {"id": 9, "name": "Syringe", "freebase_id": "/m/012ysf"}, {"id": 10, "name": "Sink", "freebase_id": "/m/0130jx"}, {"id": 11, "name": "Toy", "freebase_id": "/m/0138tl"}, {"id": 12, "name": "Organ (Musical Instrument)", "freebase_id": "/m/013y1f"}, {"id": 13, "name": "Cassette deck", "freebase_id": "/m/01432t"}, {"id": 14, "name": "Apple", "freebase_id": "/m/014j1m"}, {"id": 15, "name": "Human eye", "freebase_id": "/m/014sv8"}, {"id": 16, "name": "Cosmetics", "freebase_id": "/m/014trl"}, {"id": 17, "name": "Paddle", "freebase_id": "/m/014y4n"}, {"id": 18, "name": "Snowman", "freebase_id": "/m/0152hh"}, {"id": 19, "name": "Beer", "freebase_id": "/m/01599"}, {"id": 20, "name": "Chopsticks", "freebase_id": "/m/01_5g"}, {"id": 21, "name": "Human beard", "freebase_id": "/m/015h_t"}, {"id": 22, "name": "Bird", "freebase_id": "/m/015p6"}, {"id": 23, "name": "Parking meter", "freebase_id": "/m/015qbp"}, {"id": 24, "name": "Traffic light", "freebase_id": "/m/015qff"}, {"id": 25, "name": "Croissant", "freebase_id": "/m/015wgc"}, {"id": 26, "name": "Cucumber", "freebase_id": "/m/015x4r"}, {"id": 27, "name": "Radish", "freebase_id": "/m/015x5n"}, {"id": 28, "name": "Towel", "freebase_id": "/m/0162_1"}, {"id": 29, "name": "Doll", "freebase_id": "/m/0167gd"}, {"id": 30, "name": "Skull", "freebase_id": "/m/016m2d"}, {"id": 31, "name": "Washing machine", "freebase_id": "/m/0174k2"}, {"id": 32, "name": "Glove", "freebase_id": "/m/0174n1"}, {"id": 33, "name": "Tick", "freebase_id": "/m/0175cv"}, {"id": 34, "name": "Belt", "freebase_id": "/m/0176mf"}, {"id": 35, "name": "Sunglasses", "freebase_id": "/m/017ftj"}, {"id": 36, "name": "Banjo", "freebase_id": "/m/018j2"}, {"id": 37, "name": "Cart", "freebase_id": "/m/018p4k"}, {"id": 38, "name": "Ball", "freebase_id": "/m/018xm"}, {"id": 39, "name": "Backpack", "freebase_id": "/m/01940j"}, {"id": 40, "name": "Bicycle", "freebase_id": "/m/0199g"}, {"id": 41, "name": "Home appliance", "freebase_id": "/m/019dx1"}, {"id": 42, "name": "Centipede", "freebase_id": "/m/019h78"}, {"id": 43, "name": "Boat", "freebase_id": "/m/019jd"}, {"id": 44, "name": "Surfboard", "freebase_id": "/m/019w40"}, {"id": 45, "name": "Boot", "freebase_id": "/m/01b638"}, {"id": 46, "name": "Headphones", "freebase_id": "/m/01b7fy"}, {"id": 47, "name": "Hot dog", "freebase_id": "/m/01b9xk"}, {"id": 48, "name": "Shorts", "freebase_id": "/m/01bfm9"}, {"id": 49, "name": "Fast food", "freebase_id": "/m/01_bhs"}, {"id": 50, "name": "Bus", "freebase_id": "/m/01bjv"}, {"id": 51, "name": "Boy", "freebase_id": "/m/01bl7v"}, {"id": 52, "name": "Screwdriver", "freebase_id": "/m/01bms0"}, {"id": 53, "name": "Bicycle wheel", "freebase_id": "/m/01bqk0"}, {"id": 54, "name": "Barge", "freebase_id": "/m/01btn"}, {"id": 55, "name": "Laptop", "freebase_id": "/m/01c648"}, {"id": 56, "name": "Miniskirt", "freebase_id": "/m/01cmb2"}, {"id": 57, "name": "Drill (Tool)", "freebase_id": "/m/01d380"}, {"id": 58, "name": "Dress", "freebase_id": "/m/01d40f"}, {"id": 59, "name": "Bear", "freebase_id": "/m/01dws"}, {"id": 60, "name": "Waffle", "freebase_id": "/m/01dwsz"}, {"id": 61, "name": "Pancake", "freebase_id": "/m/01dwwc"}, {"id": 62, "name": "Brown bear", "freebase_id": "/m/01dxs"}, {"id": 63, "name": "Woodpecker", "freebase_id": "/m/01dy8n"}, {"id": 64, "name": "Blue jay", "freebase_id": "/m/01f8m5"}, {"id": 65, "name": "Pretzel", "freebase_id": "/m/01f91_"}, {"id": 66, "name": "Bagel", "freebase_id": "/m/01fb_0"}, {"id": 67, "name": "Tower", "freebase_id": "/m/01fdzj"}, {"id": 68, "name": "Teapot", "freebase_id": "/m/01fh4r"}, {"id": 69, "name": "Person", "freebase_id": "/m/01g317"}, {"id": 70, "name": "Bow and arrow", "freebase_id": "/m/01g3x7"}, {"id": 71, "name": "Swimwear", "freebase_id": "/m/01gkx_"}, {"id": 72, "name": "Beehive", "freebase_id": "/m/01gllr"}, {"id": 73, "name": "Brassiere", "freebase_id": "/m/01gmv2"}, {"id": 74, "name": "Bee", "freebase_id": "/m/01h3n"}, {"id": 75, "name": "Bat (Animal)", "freebase_id": "/m/01h44"}, {"id": 76, "name": "Starfish", "freebase_id": "/m/01h8tj"}, {"id": 77, "name": "Popcorn", "freebase_id": "/m/01hrv5"}, {"id": 78, "name": "Burrito", "freebase_id": "/m/01j3zr"}, {"id": 79, "name": "Chainsaw", "freebase_id": "/m/01j4z9"}, {"id": 80, "name": "Balloon", "freebase_id": "/m/01j51"}, {"id": 81, "name": "Wrench", "freebase_id": "/m/01j5ks"}, {"id": 82, "name": "Tent", "freebase_id": "/m/01j61q"}, {"id": 83, "name": "Vehicle registration plate", "freebase_id": "/m/01jfm_"}, {"id": 84, "name": "Lantern", "freebase_id": "/m/01jfsr"}, {"id": 85, "name": "Toaster", "freebase_id": "/m/01k6s3"}, {"id": 86, "name": "Flashlight", "freebase_id": "/m/01kb5b"}, {"id": 87, "name": "Billboard", "freebase_id": "/m/01knjb"}, {"id": 88, "name": "Tiara", "freebase_id": "/m/01krhy"}, {"id": 89, "name": "Limousine", "freebase_id": "/m/01lcw4"}, {"id": 90, "name": "Necklace", "freebase_id": "/m/01llwg"}, {"id": 91, "name": "Carnivore", "freebase_id": "/m/01lrl"}, {"id": 92, "name": "Scissors", "freebase_id": "/m/01lsmm"}, {"id": 93, "name": "Stairs", "freebase_id": "/m/01lynh"}, {"id": 94, "name": "Computer keyboard", "freebase_id": "/m/01m2v"}, {"id": 95, "name": "Printer", "freebase_id": "/m/01m4t"}, {"id": 96, "name": "Traffic sign", "freebase_id": "/m/01mqdt"}, {"id": 97, "name": "Chair", "freebase_id": "/m/01mzpv"}, {"id": 98, "name": "Shirt", "freebase_id": "/m/01n4qj"}, {"id": 99, "name": "Poster", "freebase_id": "/m/01n5jq"}, {"id": 100, "name": "Cheese", "freebase_id": "/m/01nkt"}, {"id": 101, "name": "Sock", "freebase_id": "/m/01nq26"}, {"id": 102, "name": "Fire hydrant", "freebase_id": "/m/01pns0"}, {"id": 103, "name": "Land vehicle", "freebase_id": "/m/01prls"}, {"id": 104, "name": "Earrings", "freebase_id": "/m/01r546"}, {"id": 105, "name": "Tie", "freebase_id": "/m/01rkbr"}, {"id": 106, "name": "Watercraft", "freebase_id": "/m/01rzcn"}, {"id": 107, "name": "Cabinetry", "freebase_id": "/m/01s105"}, {"id": 108, "name": "Suitcase", "freebase_id": "/m/01s55n"}, {"id": 109, "name": "Muffin", "freebase_id": "/m/01tcjp"}, {"id": 110, "name": "Bidet", "freebase_id": "/m/01vbnl"}, {"id": 111, "name": "Snack", "freebase_id": "/m/01ww8y"}, {"id": 112, "name": "Snowmobile", "freebase_id": "/m/01x3jk"}, {"id": 113, "name": "Clock", "freebase_id": "/m/01x3z"}, {"id": 114, "name": "Medical equipment", "freebase_id": "/m/01xgg_"}, {"id": 115, "name": "Cattle", "freebase_id": "/m/01xq0k1"}, {"id": 116, "name": "Cello", "freebase_id": "/m/01xqw"}, {"id": 117, "name": "Jet ski", "freebase_id": "/m/01xs3r"}, {"id": 118, "name": "Camel", "freebase_id": "/m/01x_v"}, {"id": 119, "name": "Coat", "freebase_id": "/m/01xygc"}, {"id": 120, "name": "Suit", "freebase_id": "/m/01xyhv"}, {"id": 121, "name": "Desk", "freebase_id": "/m/01y9k5"}, {"id": 122, "name": "Cat", "freebase_id": "/m/01yrx"}, {"id": 123, "name": "Bronze sculpture", "freebase_id": "/m/01yx86"}, {"id": 124, "name": "Juice", "freebase_id": "/m/01z1kdw"}, {"id": 125, "name": "Gondola", "freebase_id": "/m/02068x"}, {"id": 126, "name": "Beetle", "freebase_id": "/m/020jm"}, {"id": 127, "name": "Cannon", "freebase_id": "/m/020kz"}, {"id": 128, "name": "Computer mouse", "freebase_id": "/m/020lf"}, {"id": 129, "name": "Cookie", "freebase_id": "/m/021mn"}, {"id": 130, "name": "Office building", "freebase_id": "/m/021sj1"}, {"id": 131, "name": "Fountain", "freebase_id": "/m/0220r2"}, {"id": 132, "name": "Coin", "freebase_id": "/m/0242l"}, {"id": 133, "name": "Calculator", "freebase_id": "/m/024d2"}, {"id": 134, "name": "Cocktail", "freebase_id": "/m/024g6"}, {"id": 135, "name": "Computer monitor", "freebase_id": "/m/02522"}, {"id": 136, "name": "Box", "freebase_id": "/m/025dyy"}, {"id": 137, "name": "Stapler", "freebase_id": "/m/025fsf"}, {"id": 138, "name": "Christmas tree", "freebase_id": "/m/025nd"}, {"id": 139, "name": "Cowboy hat", "freebase_id": "/m/025rp__"}, {"id": 140, "name": "Hiking equipment", "freebase_id": "/m/0268lbt"}, {"id": 141, "name": "Studio couch", "freebase_id": "/m/026qbn5"}, {"id": 142, "name": "Drum", "freebase_id": "/m/026t6"}, {"id": 143, "name": "Dessert", "freebase_id": "/m/0270h"}, {"id": 144, "name": "Wine rack", "freebase_id": "/m/0271qf7"}, {"id": 145, "name": "Drink", "freebase_id": "/m/0271t"}, {"id": 146, "name": "Zucchini", "freebase_id": "/m/027pcv"}, {"id": 147, "name": "Ladle", "freebase_id": "/m/027rl48"}, {"id": 148, "name": "Human mouth", "freebase_id": "/m/0283dt1"}, {"id": 149, "name": "Dairy Product", "freebase_id": "/m/0284d"}, {"id": 150, "name": "Dice", "freebase_id": "/m/029b3"}, {"id": 151, "name": "Oven", "freebase_id": "/m/029bxz"}, {"id": 152, "name": "Dinosaur", "freebase_id": "/m/029tx"}, {"id": 153, "name": "Ratchet (Device)", "freebase_id": "/m/02bm9n"}, {"id": 154, "name": "Couch", "freebase_id": "/m/02crq1"}, {"id": 155, "name": "Cricket ball", "freebase_id": "/m/02ctlc"}, {"id": 156, "name": "Winter melon", "freebase_id": "/m/02cvgx"}, {"id": 157, "name": "Spatula", "freebase_id": "/m/02d1br"}, {"id": 158, "name": "Whiteboard", "freebase_id": "/m/02d9qx"}, {"id": 159, "name": "Pencil sharpener", "freebase_id": "/m/02ddwp"}, {"id": 160, "name": "Door", "freebase_id": "/m/02dgv"}, {"id": 161, "name": "Hat", "freebase_id": "/m/02dl1y"}, {"id": 162, "name": "Shower", "freebase_id": "/m/02f9f_"}, {"id": 163, "name": "Eraser", "freebase_id": "/m/02fh7f"}, {"id": 164, "name": "Fedora", "freebase_id": "/m/02fq_6"}, {"id": 165, "name": "Guacamole", "freebase_id": "/m/02g30s"}, {"id": 166, "name": "Dagger", "freebase_id": "/m/02gzp"}, {"id": 167, "name": "Scarf", "freebase_id": "/m/02h19r"}, {"id": 168, "name": "Dolphin", "freebase_id": "/m/02hj4"}, {"id": 169, "name": "Sombrero", "freebase_id": "/m/02jfl0"}, {"id": 170, "name": "Tin can", "freebase_id": "/m/02jnhm"}, {"id": 171, "name": "Mug", "freebase_id": "/m/02jvh9"}, {"id": 172, "name": "Tap", "freebase_id": "/m/02jz0l"}, {"id": 173, "name": "Harbor seal", "freebase_id": "/m/02l8p9"}, {"id": 174, "name": "Stretcher", "freebase_id": "/m/02lbcq"}, {"id": 175, "name": "Can opener", "freebase_id": "/m/02mqfb"}, {"id": 176, "name": "Goggles", "freebase_id": "/m/02_n6y"}, {"id": 177, "name": "Human body", "freebase_id": "/m/02p0tk3"}, {"id": 178, "name": "Roller skates", "freebase_id": "/m/02p3w7d"}, {"id": 179, "name": "Coffee cup", "freebase_id": "/m/02p5f1q"}, {"id": 180, "name": "Cutting board", "freebase_id": "/m/02pdsw"}, {"id": 181, "name": "Blender", "freebase_id": "/m/02pjr4"}, {"id": 182, "name": "Plumbing fixture", "freebase_id": "/m/02pkr5"}, {"id": 183, "name": "Stop sign", "freebase_id": "/m/02pv19"}, {"id": 184, "name": "Office supplies", "freebase_id": "/m/02rdsp"}, {"id": 185, "name": "Volleyball (Ball)", "freebase_id": "/m/02rgn06"}, {"id": 186, "name": "Vase", "freebase_id": "/m/02s195"}, {"id": 187, "name": "Slow cooker", "freebase_id": "/m/02tsc9"}, {"id": 188, "name": "Wardrobe", "freebase_id": "/m/02vkqh8"}, {"id": 189, "name": "Coffee", "freebase_id": "/m/02vqfm"}, {"id": 190, "name": "Whisk", "freebase_id": "/m/02vwcm"}, {"id": 191, "name": "Paper towel", "freebase_id": "/m/02w3r3"}, {"id": 192, "name": "Personal care", "freebase_id": "/m/02w3_ws"}, {"id": 193, "name": "Food", "freebase_id": "/m/02wbm"}, {"id": 194, "name": "Sun hat", "freebase_id": "/m/02wbtzl"}, {"id": 195, "name": "Tree house", "freebase_id": "/m/02wg_p"}, {"id": 196, "name": "Flying disc", "freebase_id": "/m/02wmf"}, {"id": 197, "name": "Skirt", "freebase_id": "/m/02wv6h6"}, {"id": 198, "name": "Gas stove", "freebase_id": "/m/02wv84t"}, {"id": 199, "name": "Salt and pepper shakers", "freebase_id": "/m/02x8cch"}, {"id": 200, "name": "Mechanical fan", "freebase_id": "/m/02x984l"}, {"id": 201, "name": "Face powder", "freebase_id": "/m/02xb7qb"}, {"id": 202, "name": "Fax", "freebase_id": "/m/02xqq"}, {"id": 203, "name": "Fruit", "freebase_id": "/m/02xwb"}, {"id": 204, "name": "French fries", "freebase_id": "/m/02y6n"}, {"id": 205, "name": "Nightstand", "freebase_id": "/m/02z51p"}, {"id": 206, "name": "Barrel", "freebase_id": "/m/02zn6n"}, {"id": 207, "name": "Kite", "freebase_id": "/m/02zt3"}, {"id": 208, "name": "Tart", "freebase_id": "/m/02zvsm"}, {"id": 209, "name": "Treadmill", "freebase_id": "/m/030610"}, {"id": 210, "name": "Fox", "freebase_id": "/m/0306r"}, {"id": 211, "name": "Flag", "freebase_id": "/m/03120"}, {"id": 212, "name": "French horn", "freebase_id": "/m/0319l"}, {"id": 213, "name": "Window blind", "freebase_id": "/m/031b6r"}, {"id": 214, "name": "Human foot", "freebase_id": "/m/031n1"}, {"id": 215, "name": "Golf cart", "freebase_id": "/m/0323sq"}, {"id": 216, "name": "Jacket", "freebase_id": "/m/032b3c"}, {"id": 217, "name": "Egg (Food)", "freebase_id": "/m/033cnk"}, {"id": 218, "name": "Street light", "freebase_id": "/m/033rq4"}, {"id": 219, "name": "Guitar", "freebase_id": "/m/0342h"}, {"id": 220, "name": "Pillow", "freebase_id": "/m/034c16"}, {"id": 221, "name": "Human leg", "freebase_id": "/m/035r7c"}, {"id": 222, "name": "Isopod", "freebase_id": "/m/035vxb"}, {"id": 223, "name": "Grape", "freebase_id": "/m/0388q"}, {"id": 224, "name": "Human ear", "freebase_id": "/m/039xj_"}, {"id": 225, "name": "Power plugs and sockets", "freebase_id": "/m/03bbps"}, {"id": 226, "name": "Panda", "freebase_id": "/m/03bj1"}, {"id": 227, "name": "Giraffe", "freebase_id": "/m/03bk1"}, {"id": 228, "name": "Woman", "freebase_id": "/m/03bt1vf"}, {"id": 229, "name": "Door handle", "freebase_id": "/m/03c7gz"}, {"id": 230, "name": "Rhinoceros", "freebase_id": "/m/03d443"}, {"id": 231, "name": "Bathtub", "freebase_id": "/m/03dnzn"}, {"id": 232, "name": "Goldfish", "freebase_id": "/m/03fj2"}, {"id": 233, "name": "Houseplant", "freebase_id": "/m/03fp41"}, {"id": 234, "name": "Goat", "freebase_id": "/m/03fwl"}, {"id": 235, "name": "Baseball bat", "freebase_id": "/m/03g8mr"}, {"id": 236, "name": "Baseball glove", "freebase_id": "/m/03grzl"}, {"id": 237, "name": "Mixing bowl", "freebase_id": "/m/03hj559"}, {"id": 238, "name": "Marine invertebrates", "freebase_id": "/m/03hl4l9"}, {"id": 239, "name": "Kitchen utensil", "freebase_id": "/m/03hlz0c"}, {"id": 240, "name": "Light switch", "freebase_id": "/m/03jbxj"}, {"id": 241, "name": "House", "freebase_id": "/m/03jm5"}, {"id": 242, "name": "Horse", "freebase_id": "/m/03k3r"}, {"id": 243, "name": "Stationary bicycle", "freebase_id": "/m/03kt2w"}, {"id": 244, "name": "Hammer", "freebase_id": "/m/03l9g"}, {"id": 245, "name": "Ceiling fan", "freebase_id": "/m/03ldnb"}, {"id": 246, "name": "Sofa bed", "freebase_id": "/m/03m3pdh"}, {"id": 247, "name": "Adhesive tape", "freebase_id": "/m/03m3vtv"}, {"id": 248, "name": "Harp", "freebase_id": "/m/03m5k"}, {"id": 249, "name": "Sandal", "freebase_id": "/m/03nfch"}, {"id": 250, "name": "Bicycle helmet", "freebase_id": "/m/03p3bw"}, {"id": 251, "name": "Saucer", "freebase_id": "/m/03q5c7"}, {"id": 252, "name": "Harpsichord", "freebase_id": "/m/03q5t"}, {"id": 253, "name": "Human hair", "freebase_id": "/m/03q69"}, {"id": 254, "name": "Heater", "freebase_id": "/m/03qhv5"}, {"id": 255, "name": "Harmonica", "freebase_id": "/m/03qjg"}, {"id": 256, "name": "Hamster", "freebase_id": "/m/03qrc"}, {"id": 257, "name": "Curtain", "freebase_id": "/m/03rszm"}, {"id": 258, "name": "Bed", "freebase_id": "/m/03ssj5"}, {"id": 259, "name": "Kettle", "freebase_id": "/m/03s_tn"}, {"id": 260, "name": "Fireplace", "freebase_id": "/m/03tw93"}, {"id": 261, "name": "Scale", "freebase_id": "/m/03txqz"}, {"id": 262, "name": "Drinking straw", "freebase_id": "/m/03v5tg"}, {"id": 263, "name": "Insect", "freebase_id": "/m/03vt0"}, {"id": 264, "name": "Hair dryer", "freebase_id": "/m/03wvsk"}, {"id": 265, "name": "Kitchenware", "freebase_id": "/m/03_wxk"}, {"id": 266, "name": "Indoor rower", "freebase_id": "/m/03wym"}, {"id": 267, "name": "Invertebrate", "freebase_id": "/m/03xxp"}, {"id": 268, "name": "Food processor", "freebase_id": "/m/03y6mg"}, {"id": 269, "name": "Bookcase", "freebase_id": "/m/03__z0"}, {"id": 270, "name": "Refrigerator", "freebase_id": "/m/040b_t"}, {"id": 271, "name": "Wood-burning stove", "freebase_id": "/m/04169hn"}, {"id": 272, "name": "Punching bag", "freebase_id": "/m/0420v5"}, {"id": 273, "name": "Common fig", "freebase_id": "/m/043nyj"}, {"id": 274, "name": "Cocktail shaker", "freebase_id": "/m/0440zs"}, {"id": 275, "name": "Jaguar (Animal)", "freebase_id": "/m/0449p"}, {"id": 276, "name": "Golf ball", "freebase_id": "/m/044r5d"}, {"id": 277, "name": "Fashion accessory", "freebase_id": "/m/0463sg"}, {"id": 278, "name": "Alarm clock", "freebase_id": "/m/046dlr"}, {"id": 279, "name": "Filing cabinet", "freebase_id": "/m/047j0r"}, {"id": 280, "name": "Artichoke", "freebase_id": "/m/047v4b"}, {"id": 281, "name": "Table", "freebase_id": "/m/04bcr3"}, {"id": 282, "name": "Tableware", "freebase_id": "/m/04brg2"}, {"id": 283, "name": "Kangaroo", "freebase_id": "/m/04c0y"}, {"id": 284, "name": "Koala", "freebase_id": "/m/04cp_"}, {"id": 285, "name": "Knife", "freebase_id": "/m/04ctx"}, {"id": 286, "name": "Bottle", "freebase_id": "/m/04dr76w"}, {"id": 287, "name": "Bottle opener", "freebase_id": "/m/04f5ws"}, {"id": 288, "name": "Lynx", "freebase_id": "/m/04g2r"}, {"id": 289, "name": "Lavender (Plant)", "freebase_id": "/m/04gth"}, {"id": 290, "name": "Lighthouse", "freebase_id": "/m/04h7h"}, {"id": 291, "name": "Dumbbell", "freebase_id": "/m/04h8sr"}, {"id": 292, "name": "Human head", "freebase_id": "/m/04hgtk"}, {"id": 293, "name": "Bowl", "freebase_id": "/m/04kkgm"}, {"id": 294, "name": "Humidifier", "freebase_id": "/m/04lvq_"}, {"id": 295, "name": "Porch", "freebase_id": "/m/04m6gz"}, {"id": 296, "name": "Lizard", "freebase_id": "/m/04m9y"}, {"id": 297, "name": "Billiard table", "freebase_id": "/m/04p0qw"}, {"id": 298, "name": "Mammal", "freebase_id": "/m/04rky"}, {"id": 299, "name": "Mouse", "freebase_id": "/m/04rmv"}, {"id": 300, "name": "Motorcycle", "freebase_id": "/m/04_sv"}, {"id": 301, "name": "Musical instrument", "freebase_id": "/m/04szw"}, {"id": 302, "name": "Swim cap", "freebase_id": "/m/04tn4x"}, {"id": 303, "name": "Frying pan", "freebase_id": "/m/04v6l4"}, {"id": 304, "name": "Snowplow", "freebase_id": "/m/04vv5k"}, {"id": 305, "name": "Bathroom cabinet", "freebase_id": "/m/04y4h8h"}, {"id": 306, "name": "Missile", "freebase_id": "/m/04ylt"}, {"id": 307, "name": "Bust", "freebase_id": "/m/04yqq2"}, {"id": 308, "name": "Man", "freebase_id": "/m/04yx4"}, {"id": 309, "name": "Waffle iron", "freebase_id": "/m/04z4wx"}, {"id": 310, "name": "Milk", "freebase_id": "/m/04zpv"}, {"id": 311, "name": "Ring binder", "freebase_id": "/m/04zwwv"}, {"id": 312, "name": "Plate", "freebase_id": "/m/050gv4"}, {"id": 313, "name": "Mobile phone", "freebase_id": "/m/050k8"}, {"id": 314, "name": "Baked goods", "freebase_id": "/m/052lwg6"}, {"id": 315, "name": "Mushroom", "freebase_id": "/m/052sf"}, {"id": 316, "name": "Crutch", "freebase_id": "/m/05441v"}, {"id": 317, "name": "Pitcher (Container)", "freebase_id": "/m/054fyh"}, {"id": 318, "name": "Mirror", "freebase_id": "/m/054_l"}, {"id": 319, "name": "Personal flotation device", "freebase_id": "/m/054xkw"}, {"id": 320, "name": "Table tennis racket", "freebase_id": "/m/05_5p_0"}, {"id": 321, "name": "Pencil case", "freebase_id": "/m/05676x"}, {"id": 322, "name": "Musical keyboard", "freebase_id": "/m/057cc"}, {"id": 323, "name": "Scoreboard", "freebase_id": "/m/057p5t"}, {"id": 324, "name": "Briefcase", "freebase_id": "/m/0584n8"}, {"id": 325, "name": "Kitchen knife", "freebase_id": "/m/058qzx"}, {"id": 326, "name": "Nail (Construction)", "freebase_id": "/m/05bm6"}, {"id": 327, "name": "Tennis ball", "freebase_id": "/m/05ctyq"}, {"id": 328, "name": "Plastic bag", "freebase_id": "/m/05gqfk"}, {"id": 329, "name": "Oboe", "freebase_id": "/m/05kms"}, {"id": 330, "name": "Chest of drawers", "freebase_id": "/m/05kyg_"}, {"id": 331, "name": "Ostrich", "freebase_id": "/m/05n4y"}, {"id": 332, "name": "Piano", "freebase_id": "/m/05r5c"}, {"id": 333, "name": "Girl", "freebase_id": "/m/05r655"}, {"id": 334, "name": "Plant", "freebase_id": "/m/05s2s"}, {"id": 335, "name": "Potato", "freebase_id": "/m/05vtc"}, {"id": 336, "name": "Hair spray", "freebase_id": "/m/05w9t9"}, {"id": 337, "name": "Sports equipment", "freebase_id": "/m/05y5lj"}, {"id": 338, "name": "Pasta", "freebase_id": "/m/05z55"}, {"id": 339, "name": "Penguin", "freebase_id": "/m/05z6w"}, {"id": 340, "name": "Pumpkin", "freebase_id": "/m/05zsy"}, {"id": 341, "name": "Pear", "freebase_id": "/m/061_f"}, {"id": 342, "name": "Infant bed", "freebase_id": "/m/061hd_"}, {"id": 343, "name": "Polar bear", "freebase_id": "/m/0633h"}, {"id": 344, "name": "Mixer", "freebase_id": "/m/063rgb"}, {"id": 345, "name": "Cupboard", "freebase_id": "/m/0642b4"}, {"id": 346, "name": "Jacuzzi", "freebase_id": "/m/065h6l"}, {"id": 347, "name": "Pizza", "freebase_id": "/m/0663v"}, {"id": 348, "name": "Digital clock", "freebase_id": "/m/06_72j"}, {"id": 349, "name": "Pig", "freebase_id": "/m/068zj"}, {"id": 350, "name": "Reptile", "freebase_id": "/m/06bt6"}, {"id": 351, "name": "Rifle", "freebase_id": "/m/06c54"}, {"id": 352, "name": "Lipstick", "freebase_id": "/m/06c7f7"}, {"id": 353, "name": "Skateboard", "freebase_id": "/m/06_fw"}, {"id": 354, "name": "Raven", "freebase_id": "/m/06j2d"}, {"id": 355, "name": "High heels", "freebase_id": "/m/06k2mb"}, {"id": 356, "name": "Red panda", "freebase_id": "/m/06l9r"}, {"id": 357, "name": "Rose", "freebase_id": "/m/06m11"}, {"id": 358, "name": "Rabbit", "freebase_id": "/m/06mf6"}, {"id": 359, "name": "Sculpture", "freebase_id": "/m/06msq"}, {"id": 360, "name": "Saxophone", "freebase_id": "/m/06ncr"}, {"id": 361, "name": "Shotgun", "freebase_id": "/m/06nrc"}, {"id": 362, "name": "Seafood", "freebase_id": "/m/06nwz"}, {"id": 363, "name": "Submarine sandwich", "freebase_id": "/m/06pcq"}, {"id": 364, "name": "Snowboard", "freebase_id": "/m/06__v"}, {"id": 365, "name": "Sword", "freebase_id": "/m/06y5r"}, {"id": 366, "name": "Picture frame", "freebase_id": "/m/06z37_"}, {"id": 367, "name": "Sushi", "freebase_id": "/m/07030"}, {"id": 368, "name": "Loveseat", "freebase_id": "/m/0703r8"}, {"id": 369, "name": "Ski", "freebase_id": "/m/071p9"}, {"id": 370, "name": "Squirrel", "freebase_id": "/m/071qp"}, {"id": 371, "name": "Tripod", "freebase_id": "/m/073bxn"}, {"id": 372, "name": "Stethoscope", "freebase_id": "/m/073g6"}, {"id": 373, "name": "Submarine", "freebase_id": "/m/074d1"}, {"id": 374, "name": "Scorpion", "freebase_id": "/m/0755b"}, {"id": 375, "name": "Segway", "freebase_id": "/m/076bq"}, {"id": 376, "name": "Training bench", "freebase_id": "/m/076lb9"}, {"id": 377, "name": "Snake", "freebase_id": "/m/078jl"}, {"id": 378, "name": "Coffee table", "freebase_id": "/m/078n6m"}, {"id": 379, "name": "Skyscraper", "freebase_id": "/m/079cl"}, {"id": 380, "name": "Sheep", "freebase_id": "/m/07bgp"}, {"id": 381, "name": "Television", "freebase_id": "/m/07c52"}, {"id": 382, "name": "Trombone", "freebase_id": "/m/07c6l"}, {"id": 383, "name": "Tea", "freebase_id": "/m/07clx"}, {"id": 384, "name": "Tank", "freebase_id": "/m/07cmd"}, {"id": 385, "name": "Taco", "freebase_id": "/m/07crc"}, {"id": 386, "name": "Telephone", "freebase_id": "/m/07cx4"}, {"id": 387, "name": "Torch", "freebase_id": "/m/07dd4"}, {"id": 388, "name": "Tiger", "freebase_id": "/m/07dm6"}, {"id": 389, "name": "Strawberry", "freebase_id": "/m/07fbm7"}, {"id": 390, "name": "Trumpet", "freebase_id": "/m/07gql"}, {"id": 391, "name": "Tree", "freebase_id": "/m/07j7r"}, {"id": 392, "name": "Tomato", "freebase_id": "/m/07j87"}, {"id": 393, "name": "Train", "freebase_id": "/m/07jdr"}, {"id": 394, "name": "Tool", "freebase_id": "/m/07k1x"}, {"id": 395, "name": "Picnic basket", "freebase_id": "/m/07kng9"}, {"id": 396, "name": "Cooking spray", "freebase_id": "/m/07mcwg"}, {"id": 397, "name": "Trousers", "freebase_id": "/m/07mhn"}, {"id": 398, "name": "Bowling equipment", "freebase_id": "/m/07pj7bq"}, {"id": 399, "name": "Football helmet", "freebase_id": "/m/07qxg_"}, {"id": 400, "name": "Truck", "freebase_id": "/m/07r04"}, {"id": 401, "name": "Measuring cup", "freebase_id": "/m/07v9_z"}, {"id": 402, "name": "Coffeemaker", "freebase_id": "/m/07xyvk"}, {"id": 403, "name": "Violin", "freebase_id": "/m/07y_7"}, {"id": 404, "name": "Vehicle", "freebase_id": "/m/07yv9"}, {"id": 405, "name": "Handbag", "freebase_id": "/m/080hkjn"}, {"id": 406, "name": "Paper cutter", "freebase_id": "/m/080n7g"}, {"id": 407, "name": "Wine", "freebase_id": "/m/081qc"}, {"id": 408, "name": "Weapon", "freebase_id": "/m/083kb"}, {"id": 409, "name": "Wheel", "freebase_id": "/m/083wq"}, {"id": 410, "name": "Worm", "freebase_id": "/m/084hf"}, {"id": 411, "name": "Wok", "freebase_id": "/m/084rd"}, {"id": 412, "name": "Whale", "freebase_id": "/m/084zz"}, {"id": 413, "name": "Zebra", "freebase_id": "/m/0898b"}, {"id": 414, "name": "Auto part", "freebase_id": "/m/08dz3q"}, {"id": 415, "name": "Jug", "freebase_id": "/m/08hvt4"}, {"id": 416, "name": "Pizza cutter", "freebase_id": "/m/08ks85"}, {"id": 417, "name": "Cream", "freebase_id": "/m/08p92x"}, {"id": 418, "name": "Monkey", "freebase_id": "/m/08pbxl"}, {"id": 419, "name": "Lion", "freebase_id": "/m/096mb"}, {"id": 420, "name": "Bread", "freebase_id": "/m/09728"}, {"id": 421, "name": "Platter", "freebase_id": "/m/099ssp"}, {"id": 422, "name": "Chicken", "freebase_id": "/m/09b5t"}, {"id": 423, "name": "Eagle", "freebase_id": "/m/09csl"}, {"id": 424, "name": "Helicopter", "freebase_id": "/m/09ct_"}, {"id": 425, "name": "Owl", "freebase_id": "/m/09d5_"}, {"id": 426, "name": "Duck", "freebase_id": "/m/09ddx"}, {"id": 427, "name": "Turtle", "freebase_id": "/m/09dzg"}, {"id": 428, "name": "Hippopotamus", "freebase_id": "/m/09f20"}, {"id": 429, "name": "Crocodile", "freebase_id": "/m/09f_2"}, {"id": 430, "name": "Toilet", "freebase_id": "/m/09g1w"}, {"id": 431, "name": "Toilet paper", "freebase_id": "/m/09gtd"}, {"id": 432, "name": "Squid", "freebase_id": "/m/09gys"}, {"id": 433, "name": "Clothing", "freebase_id": "/m/09j2d"}, {"id": 434, "name": "Footwear", "freebase_id": "/m/09j5n"}, {"id": 435, "name": "Lemon", "freebase_id": "/m/09k_b"}, {"id": 436, "name": "Spider", "freebase_id": "/m/09kmb"}, {"id": 437, "name": "Deer", "freebase_id": "/m/09kx5"}, {"id": 438, "name": "Frog", "freebase_id": "/m/09ld4"}, {"id": 439, "name": "Banana", "freebase_id": "/m/09qck"}, {"id": 440, "name": "Rocket", "freebase_id": "/m/09rvcxw"}, {"id": 441, "name": "Wine glass", "freebase_id": "/m/09tvcd"}, {"id": 442, "name": "Countertop", "freebase_id": "/m/0b3fp9"}, {"id": 443, "name": "Tablet computer", "freebase_id": "/m/0bh9flk"}, {"id": 444, "name": "Waste container", "freebase_id": "/m/0bjyj5"}, {"id": 445, "name": "Swimming pool", "freebase_id": "/m/0b_rs"}, {"id": 446, "name": "Dog", "freebase_id": "/m/0bt9lr"}, {"id": 447, "name": "Book", "freebase_id": "/m/0bt_c3"}, {"id": 448, "name": "Elephant", "freebase_id": "/m/0bwd_0j"}, {"id": 449, "name": "Shark", "freebase_id": "/m/0by6g"}, {"id": 450, "name": "Candle", "freebase_id": "/m/0c06p"}, {"id": 451, "name": "Leopard", "freebase_id": "/m/0c29q"}, {"id": 452, "name": "Axe", "freebase_id": "/m/0c2jj"}, {"id": 453, "name": "Hand dryer", "freebase_id": "/m/0c3m8g"}, {"id": 454, "name": "Soap dispenser", "freebase_id": "/m/0c3mkw"}, {"id": 455, "name": "Porcupine", "freebase_id": "/m/0c568"}, {"id": 456, "name": "Flower", "freebase_id": "/m/0c9ph5"}, {"id": 457, "name": "Canary", "freebase_id": "/m/0ccs93"}, {"id": 458, "name": "Cheetah", "freebase_id": "/m/0cd4d"}, {"id": 459, "name": "Palm tree", "freebase_id": "/m/0cdl1"}, {"id": 460, "name": "Hamburger", "freebase_id": "/m/0cdn1"}, {"id": 461, "name": "Maple", "freebase_id": "/m/0cffdh"}, {"id": 462, "name": "Building", "freebase_id": "/m/0cgh4"}, {"id": 463, "name": "Fish", "freebase_id": "/m/0ch_cf"}, {"id": 464, "name": "Lobster", "freebase_id": "/m/0cjq5"}, {"id": 465, "name": "Garden Asparagus", "freebase_id": "/m/0cjs7"}, {"id": 466, "name": "Furniture", "freebase_id": "/m/0c_jw"}, {"id": 467, "name": "Hedgehog", "freebase_id": "/m/0cl4p"}, {"id": 468, "name": "Airplane", "freebase_id": "/m/0cmf2"}, {"id": 469, "name": "Spoon", "freebase_id": "/m/0cmx8"}, {"id": 470, "name": "Otter", "freebase_id": "/m/0cn6p"}, {"id": 471, "name": "Bull", "freebase_id": "/m/0cnyhnx"}, {"id": 472, "name": "Oyster", "freebase_id": "/m/0_cp5"}, {"id": 473, "name": "Horizontal bar", "freebase_id": "/m/0cqn2"}, {"id": 474, "name": "Convenience store", "freebase_id": "/m/0crjs"}, {"id": 475, "name": "Bomb", "freebase_id": "/m/0ct4f"}, {"id": 476, "name": "Bench", "freebase_id": "/m/0cvnqh"}, {"id": 477, "name": "Ice cream", "freebase_id": "/m/0cxn2"}, {"id": 478, "name": "Caterpillar", "freebase_id": "/m/0cydv"}, {"id": 479, "name": "Butterfly", "freebase_id": "/m/0cyf8"}, {"id": 480, "name": "Parachute", "freebase_id": "/m/0cyfs"}, {"id": 481, "name": "Orange", "freebase_id": "/m/0cyhj_"}, {"id": 482, "name": "Antelope", "freebase_id": "/m/0czz2"}, {"id": 483, "name": "Beaker", "freebase_id": "/m/0d20w4"}, {"id": 484, "name": "Moths and butterflies", "freebase_id": "/m/0d_2m"}, {"id": 485, "name": "Window", "freebase_id": "/m/0d4v4"}, {"id": 486, "name": "Closet", "freebase_id": "/m/0d4w1"}, {"id": 487, "name": "Castle", "freebase_id": "/m/0d5gx"}, {"id": 488, "name": "Jellyfish", "freebase_id": "/m/0d8zb"}, {"id": 489, "name": "Goose", "freebase_id": "/m/0dbvp"}, {"id": 490, "name": "Mule", "freebase_id": "/m/0dbzx"}, {"id": 491, "name": "Swan", "freebase_id": "/m/0dftk"}, {"id": 492, "name": "Peach", "freebase_id": "/m/0dj6p"}, {"id": 493, "name": "Coconut", "freebase_id": "/m/0djtd"}, {"id": 494, "name": "Seat belt", "freebase_id": "/m/0dkzw"}, {"id": 495, "name": "Raccoon", "freebase_id": "/m/0dq75"}, {"id": 496, "name": "Chisel", "freebase_id": "/m/0_dqb"}, {"id": 497, "name": "Fork", "freebase_id": "/m/0dt3t"}, {"id": 498, "name": "Lamp", "freebase_id": "/m/0dtln"}, {"id": 499, "name": "Camera", "freebase_id": "/m/0dv5r"}, {"id": 500, "name": "Squash (Plant)", "freebase_id": "/m/0dv77"}, {"id": 501, "name": "Racket", "freebase_id": "/m/0dv9c"}, {"id": 502, "name": "Human face", "freebase_id": "/m/0dzct"}, {"id": 503, "name": "Human arm", "freebase_id": "/m/0dzf4"}, {"id": 504, "name": "Vegetable", "freebase_id": "/m/0f4s2w"}, {"id": 505, "name": "Diaper", "freebase_id": "/m/0f571"}, {"id": 506, "name": "Unicycle", "freebase_id": "/m/0f6nr"}, {"id": 507, "name": "Falcon", "freebase_id": "/m/0f6wt"}, {"id": 508, "name": "Chime", "freebase_id": "/m/0f8s22"}, {"id": 509, "name": "Snail", "freebase_id": "/m/0f9_l"}, {"id": 510, "name": "Shellfish", "freebase_id": "/m/0fbdv"}, {"id": 511, "name": "Cabbage", "freebase_id": "/m/0fbw6"}, {"id": 512, "name": "Carrot", "freebase_id": "/m/0fj52s"}, {"id": 513, "name": "Mango", "freebase_id": "/m/0fldg"}, {"id": 514, "name": "Jeans", "freebase_id": "/m/0fly7"}, {"id": 515, "name": "Flowerpot", "freebase_id": "/m/0fm3zh"}, {"id": 516, "name": "Pineapple", "freebase_id": "/m/0fp6w"}, {"id": 517, "name": "Drawer", "freebase_id": "/m/0fqfqc"}, {"id": 518, "name": "Stool", "freebase_id": "/m/0fqt361"}, {"id": 519, "name": "Envelope", "freebase_id": "/m/0frqm"}, {"id": 520, "name": "Cake", "freebase_id": "/m/0fszt"}, {"id": 521, "name": "Dragonfly", "freebase_id": "/m/0ft9s"}, {"id": 522, "name": "Common sunflower", "freebase_id": "/m/0ftb8"}, {"id": 523, "name": "Microwave oven", "freebase_id": "/m/0fx9l"}, {"id": 524, "name": "Honeycomb", "freebase_id": "/m/0fz0h"}, {"id": 525, "name": "Marine mammal", "freebase_id": "/m/0gd2v"}, {"id": 526, "name": "Sea lion", "freebase_id": "/m/0gd36"}, {"id": 527, "name": "Ladybug", "freebase_id": "/m/0gj37"}, {"id": 528, "name": "Shelf", "freebase_id": "/m/0gjbg72"}, {"id": 529, "name": "Watch", "freebase_id": "/m/0gjkl"}, {"id": 530, "name": "Candy", "freebase_id": "/m/0gm28"}, {"id": 531, "name": "Salad", "freebase_id": "/m/0grw1"}, {"id": 532, "name": "Parrot", "freebase_id": "/m/0gv1x"}, {"id": 533, "name": "Handgun", "freebase_id": "/m/0gxl3"}, {"id": 534, "name": "Sparrow", "freebase_id": "/m/0h23m"}, {"id": 535, "name": "Van", "freebase_id": "/m/0h2r6"}, {"id": 536, "name": "Grinder", "freebase_id": "/m/0h8jyh6"}, {"id": 537, "name": "Spice rack", "freebase_id": "/m/0h8kx63"}, {"id": 538, "name": "Light bulb", "freebase_id": "/m/0h8l4fh"}, {"id": 539, "name": "Corded phone", "freebase_id": "/m/0h8lkj8"}, {"id": 540, "name": "Sports uniform", "freebase_id": "/m/0h8mhzd"}, {"id": 541, "name": "Tennis racket", "freebase_id": "/m/0h8my_4"}, {"id": 542, "name": "Wall clock", "freebase_id": "/m/0h8mzrc"}, {"id": 543, "name": "Serving tray", "freebase_id": "/m/0h8n27j"}, {"id": 544, "name": "Kitchen & dining room table", "freebase_id": "/m/0h8n5zk"}, {"id": 545, "name": "Dog bed", "freebase_id": "/m/0h8n6f9"}, {"id": 546, "name": "Cake stand", "freebase_id": "/m/0h8n6ft"}, {"id": 547, "name": "Cat furniture", "freebase_id": "/m/0h8nm9j"}, {"id": 548, "name": "Bathroom accessory", "freebase_id": "/m/0h8nr_l"}, {"id": 549, "name": "Facial tissue holder", "freebase_id": "/m/0h8nsvg"}, {"id": 550, "name": "Pressure cooker", "freebase_id": "/m/0h8ntjv"}, {"id": 551, "name": "Kitchen appliance", "freebase_id": "/m/0h99cwc"}, {"id": 552, "name": "Tire", "freebase_id": "/m/0h9mv"}, {"id": 553, "name": "Ruler", "freebase_id": "/m/0hdln"}, {"id": 554, "name": "Luggage and bags", "freebase_id": "/m/0hf58v5"}, {"id": 555, "name": "Microphone", "freebase_id": "/m/0hg7b"}, {"id": 556, "name": "Broccoli", "freebase_id": "/m/0hkxq"}, {"id": 557, "name": "Umbrella", "freebase_id": "/m/0hnnb"}, {"id": 558, "name": "Pastry", "freebase_id": "/m/0hnyx"}, {"id": 559, "name": "Grapefruit", "freebase_id": "/m/0hqkz"}, {"id": 560, "name": "Band-aid", "freebase_id": "/m/0j496"}, {"id": 561, "name": "Animal", "freebase_id": "/m/0jbk"}, {"id": 562, "name": "Bell pepper", "freebase_id": "/m/0jg57"}, {"id": 563, "name": "Turkey", "freebase_id": "/m/0jly1"}, {"id": 564, "name": "Lily", "freebase_id": "/m/0jqgx"}, {"id": 565, "name": "Pomegranate", "freebase_id": "/m/0jwn_"}, {"id": 566, "name": "Doughnut", "freebase_id": "/m/0jy4k"}, {"id": 567, "name": "Glasses", "freebase_id": "/m/0jyfg"}, {"id": 568, "name": "Human nose", "freebase_id": "/m/0k0pj"}, {"id": 569, "name": "Pen", "freebase_id": "/m/0k1tl"}, {"id": 570, "name": "Ant", "freebase_id": "/m/0_k2"}, {"id": 571, "name": "Car", "freebase_id": "/m/0k4j"}, {"id": 572, "name": "Aircraft", "freebase_id": "/m/0k5j"}, {"id": 573, "name": "Human hand", "freebase_id": "/m/0k65p"}, {"id": 574, "name": "Skunk", "freebase_id": "/m/0km7z"}, {"id": 575, "name": "Teddy bear", "freebase_id": "/m/0kmg4"}, {"id": 576, "name": "Watermelon", "freebase_id": "/m/0kpqd"}, {"id": 577, "name": "Cantaloupe", "freebase_id": "/m/0kpt_"}, {"id": 578, "name": "Dishwasher", "freebase_id": "/m/0ky7b"}, {"id": 579, "name": "Flute", "freebase_id": "/m/0l14j_"}, {"id": 580, "name": "Balance beam", "freebase_id": "/m/0l3ms"}, {"id": 581, "name": "Sandwich", "freebase_id": "/m/0l515"}, {"id": 582, "name": "Shrimp", "freebase_id": "/m/0ll1f78"}, {"id": 583, "name": "Sewing machine", "freebase_id": "/m/0llzx"}, {"id": 584, "name": "Binoculars", "freebase_id": "/m/0lt4_"}, {"id": 585, "name": "Rays and skates", "freebase_id": "/m/0m53l"}, {"id": 586, "name": "Ipod", "freebase_id": "/m/0mcx2"}, {"id": 587, "name": "Accordion", "freebase_id": "/m/0mkg"}, {"id": 588, "name": "Willow", "freebase_id": "/m/0mw_6"}, {"id": 589, "name": "Crab", "freebase_id": "/m/0n28_"}, {"id": 590, "name": "Crown", "freebase_id": "/m/0nl46"}, {"id": 591, "name": "Seahorse", "freebase_id": "/m/0nybt"}, {"id": 592, "name": "Perfume", "freebase_id": "/m/0p833"}, {"id": 593, "name": "Alpaca", "freebase_id": "/m/0pcr"}, {"id": 594, "name": "Taxi", "freebase_id": "/m/0pg52"}, {"id": 595, "name": "Canoe", "freebase_id": "/m/0ph39"}, {"id": 596, "name": "Remote control", "freebase_id": "/m/0qjjc"}, {"id": 597, "name": "Wheelchair", "freebase_id": "/m/0qmmr"}, {"id": 598, "name": "Rugby ball", "freebase_id": "/m/0wdt60w"}, {"id": 599, "name": "Armadillo", "freebase_id": "/m/0xfy"}, {"id": 600, "name": "Maracas", "freebase_id": "/m/0xzly"}, {"id": 601, "name": "Helmet", "freebase_id": "/m/0zvk5"},]
categories_seg = [ {"id": 1, "name": "Screwdriver", "freebase_id": "/m/01bms0"}, {"id": 2, "name": "Light switch", "freebase_id": "/m/03jbxj"}, {"id": 3, "name": "Doughnut", "freebase_id": "/m/0jy4k"}, {"id": 4, "name": "Toilet paper", "freebase_id": "/m/09gtd"}, {"id": 5, "name": "Wrench", "freebase_id": "/m/01j5ks"}, {"id": 6, "name": "Toaster", "freebase_id": "/m/01k6s3"}, {"id": 7, "name": "Tennis ball", "freebase_id": "/m/05ctyq"}, {"id": 8, "name": "Radish", "freebase_id": "/m/015x5n"}, {"id": 9, "name": "Pomegranate", "freebase_id": "/m/0jwn_"}, {"id": 10, "name": "Kite", "freebase_id": "/m/02zt3"}, {"id": 11, "name": "Table tennis racket", "freebase_id": "/m/05_5p_0"}, {"id": 12, "name": "Hamster", "freebase_id": "/m/03qrc"}, {"id": 13, "name": "Barge", "freebase_id": "/m/01btn"}, {"id": 14, "name": "Shower", "freebase_id": "/m/02f9f_"}, {"id": 15, "name": "Printer", "freebase_id": "/m/01m4t"}, {"id": 16, "name": "Snowmobile", "freebase_id": "/m/01x3jk"}, {"id": 17, "name": "Fire hydrant", "freebase_id": "/m/01pns0"}, {"id": 18, "name": "Limousine", "freebase_id": "/m/01lcw4"}, {"id": 19, "name": "Whale", "freebase_id": "/m/084zz"}, {"id": 20, "name": "Microwave oven", "freebase_id": "/m/0fx9l"}, {"id": 21, "name": "Asparagus", "freebase_id": "/m/0cjs7"}, {"id": 22, "name": "Lion", "freebase_id": "/m/096mb"}, {"id": 23, "name": "Spatula", "freebase_id": "/m/02d1br"}, {"id": 24, "name": "Torch", "freebase_id": "/m/07dd4"}, {"id": 25, "name": "Volleyball", "freebase_id": "/m/02rgn06"}, {"id": 26, "name": "Ambulance", "freebase_id": "/m/012n7d"}, {"id": 27, "name": "Chopsticks", "freebase_id": "/m/01_5g"}, {"id": 28, "name": "Raccoon", "freebase_id": "/m/0dq75"}, {"id": 29, "name": "Blue jay", "freebase_id": "/m/01f8m5"}, {"id": 30, "name": "Lynx", "freebase_id": "/m/04g2r"}, {"id": 31, "name": "Dice", "freebase_id": "/m/029b3"}, {"id": 32, "name": "Filing cabinet", "freebase_id": "/m/047j0r"}, {"id": 33, "name": "Ruler", "freebase_id": "/m/0hdln"}, {"id": 34, "name": "Power plugs and sockets", "freebase_id": "/m/03bbps"}, {"id": 35, "name": "Bell pepper", "freebase_id": "/m/0jg57"}, {"id": 36, "name": "Binoculars", "freebase_id": "/m/0lt4_"}, {"id": 37, "name": "Pretzel", "freebase_id": "/m/01f91_"}, {"id": 38, "name": "Hot dog", "freebase_id": "/m/01b9xk"}, {"id": 39, "name": "Missile", "freebase_id": "/m/04ylt"}, {"id": 40, "name": "Common fig", "freebase_id": "/m/043nyj"}, {"id": 41, "name": "Croissant", "freebase_id": "/m/015wgc"}, {"id": 42, "name": "Adhesive tape", "freebase_id": "/m/03m3vtv"}, {"id": 43, "name": "Slow cooker", "freebase_id": "/m/02tsc9"}, {"id": 44, "name": "Dog bed", "freebase_id": "/m/0h8n6f9"}, {"id": 45, "name": "Harpsichord", "freebase_id": "/m/03q5t"}, {"id": 46, "name": "Billiard table", "freebase_id": "/m/04p0qw"}, {"id": 47, "name": "Alpaca", "freebase_id": "/m/0pcr"}, {"id": 48, "name": "Harbor seal", "freebase_id": "/m/02l8p9"}, {"id": 49, "name": "Grape", "freebase_id": "/m/0388q"}, {"id": 50, "name": "Nail", "freebase_id": "/m/05bm6"}, {"id": 51, "name": "Paper towel", "freebase_id": "/m/02w3r3"}, {"id": 52, "name": "Alarm clock", "freebase_id": "/m/046dlr"}, {"id": 53, "name": "Guacamole", "freebase_id": "/m/02g30s"}, {"id": 54, "name": "Starfish", "freebase_id": "/m/01h8tj"}, {"id": 55, "name": "Zebra", "freebase_id": "/m/0898b"}, {"id": 56, "name": "Segway", "freebase_id": "/m/076bq"}, {"id": 57, "name": "Sea turtle", "freebase_id": "/m/0120dh"}, {"id": 58, "name": "Scissors", "freebase_id": "/m/01lsmm"}, {"id": 59, "name": "Rhinoceros", "freebase_id": "/m/03d443"}, {"id": 60, "name": "Kangaroo", "freebase_id": "/m/04c0y"}, {"id": 61, "name": "Jaguar", "freebase_id": "/m/0449p"}, {"id": 62, "name": "Leopard", "freebase_id": "/m/0c29q"}, {"id": 63, "name": "Dumbbell", "freebase_id": "/m/04h8sr"}, {"id": 64, "name": "Envelope", "freebase_id": "/m/0frqm"}, {"id": 65, "name": "Winter melon", "freebase_id": "/m/02cvgx"}, {"id": 66, "name": "Teapot", "freebase_id": "/m/01fh4r"}, {"id": 67, "name": "Camel", "freebase_id": "/m/01x_v"}, {"id": 68, "name": "Beaker", "freebase_id": "/m/0d20w4"}, {"id": 69, "name": "Brown bear", "freebase_id": "/m/01dxs"}, {"id": 70, "name": "Toilet", "freebase_id": "/m/09g1w"}, {"id": 71, "name": "Teddy bear", "freebase_id": "/m/0kmg4"}, {"id": 72, "name": "Briefcase", "freebase_id": "/m/0584n8"}, {"id": 73, "name": "Stop sign", "freebase_id": "/m/02pv19"}, {"id": 74, "name": "Tiger", "freebase_id": "/m/07dm6"}, {"id": 75, "name": "Cabbage", "freebase_id": "/m/0fbw6"}, {"id": 76, "name": "Giraffe", "freebase_id": "/m/03bk1"}, {"id": 77, "name": "Polar bear", "freebase_id": "/m/0633h"}, {"id": 78, "name": "Shark", "freebase_id": "/m/0by6g"}, {"id": 79, "name": "Rabbit", "freebase_id": "/m/06mf6"}, {"id": 80, "name": "Swim cap", "freebase_id": "/m/04tn4x"}, {"id": 81, "name": "Pressure cooker", "freebase_id": "/m/0h8ntjv"}, {"id": 82, "name": "Kitchen knife", "freebase_id": "/m/058qzx"}, {"id": 83, "name": "Submarine sandwich", "freebase_id": "/m/06pcq"}, {"id": 84, "name": "Flashlight", "freebase_id": "/m/01kb5b"}, {"id": 85, "name": "Penguin", "freebase_id": "/m/05z6w"}, {"id": 86, "name": "Snake", "freebase_id": "/m/078jl"}, {"id": 87, "name": "Zucchini", "freebase_id": "/m/027pcv"}, {"id": 88, "name": "Bat", "freebase_id": "/m/01h44"}, {"id": 89, "name": "Food processor", "freebase_id": "/m/03y6mg"}, {"id": 90, "name": "Ostrich", "freebase_id": "/m/05n4y"}, {"id": 91, "name": "Sea lion", "freebase_id": "/m/0gd36"}, {"id": 92, "name": "Goldfish", "freebase_id": "/m/03fj2"}, {"id": 93, "name": "Elephant", "freebase_id": "/m/0bwd_0j"}, {"id": 94, "name": "Rocket", "freebase_id": "/m/09rvcxw"}, {"id": 95, "name": "Mouse", "freebase_id": "/m/04rmv"}, {"id": 96, "name": "Oyster", "freebase_id": "/m/0_cp5"}, {"id": 97, "name": "Digital clock", "freebase_id": "/m/06_72j"}, {"id": 98, "name": "Otter", "freebase_id": "/m/0cn6p"}, {"id": 99, "name": "Dolphin", "freebase_id": "/m/02hj4"}, {"id": 100, "name": "Punching bag", "freebase_id": "/m/0420v5"}, {"id": 101, "name": "Corded phone", "freebase_id": "/m/0h8lkj8"}, {"id": 102, "name": "Tennis racket", "freebase_id": "/m/0h8my_4"}, {"id": 103, "name": "Pancake", "freebase_id": "/m/01dwwc"}, {"id": 104, "name": "Mango", "freebase_id": "/m/0fldg"}, {"id": 105, "name": "Crocodile", "freebase_id": "/m/09f_2"}, {"id": 106, "name": "Waffle", "freebase_id": "/m/01dwsz"}, {"id": 107, "name": "Computer mouse", "freebase_id": "/m/020lf"}, {"id": 108, "name": "Kettle", "freebase_id": "/m/03s_tn"}, {"id": 109, "name": "Tart", "freebase_id": "/m/02zvsm"}, {"id": 110, "name": "Oven", "freebase_id": "/m/029bxz"}, {"id": 111, "name": "Banana", "freebase_id": "/m/09qck"}, {"id": 112, "name": "Cheetah", "freebase_id": "/m/0cd4d"}, {"id": 113, "name": "Raven", "freebase_id": "/m/06j2d"}, {"id": 114, "name": "Frying pan", "freebase_id": "/m/04v6l4"}, {"id": 115, "name": "Pear", "freebase_id": "/m/061_f"}, {"id": 116, "name": "Fox", "freebase_id": "/m/0306r"}, {"id": 117, "name": "Skateboard", "freebase_id": "/m/06_fw"}, {"id": 118, "name": "Rugby ball", "freebase_id": "/m/0wdt60w"}, {"id": 119, "name": "Watermelon", "freebase_id": "/m/0kpqd"}, {"id": 120, "name": "Flute", "freebase_id": "/m/0l14j_"}, {"id": 121, "name": "Canary", "freebase_id": "/m/0ccs93"}, {"id": 122, "name": "Door handle", "freebase_id": "/m/03c7gz"}, {"id": 123, "name": "Saxophone", "freebase_id": "/m/06ncr"}, {"id": 124, "name": "Burrito", "freebase_id": "/m/01j3zr"}, {"id": 125, "name": "Suitcase", "freebase_id": "/m/01s55n"}, {"id": 126, "name": "Roller skates", "freebase_id": "/m/02p3w7d"}, {"id": 127, "name": "Dagger", "freebase_id": "/m/02gzp"}, {"id": 128, "name": "Seat belt", "freebase_id": "/m/0dkzw"}, {"id": 129, "name": "Washing machine", "freebase_id": "/m/0174k2"}, {"id": 130, "name": "Jet ski", "freebase_id": "/m/01xs3r"}, {"id": 131, "name": "Sombrero", "freebase_id": "/m/02jfl0"}, {"id": 132, "name": "Pig", "freebase_id": "/m/068zj"}, {"id": 133, "name": "Drinking straw", "freebase_id": "/m/03v5tg"}, {"id": 134, "name": "Peach", "freebase_id": "/m/0dj6p"}, {"id": 135, "name": "Tortoise", "freebase_id": "/m/011k07"}, {"id": 136, "name": "Towel", "freebase_id": "/m/0162_1"}, {"id": 137, "name": "Tablet computer", "freebase_id": "/m/0bh9flk"}, {"id": 138, "name": "Cucumber", "freebase_id": "/m/015x4r"}, {"id": 139, "name": "Mule", "freebase_id": "/m/0dbzx"}, {"id": 140, "name": "Potato", "freebase_id": "/m/05vtc"}, {"id": 141, "name": "Frog", "freebase_id": "/m/09ld4"}, {"id": 142, "name": "Bear", "freebase_id": "/m/01dws"}, {"id": 143, "name": "Lighthouse", "freebase_id": "/m/04h7h"}, {"id": 144, "name": "Belt", "freebase_id": "/m/0176mf"}, {"id": 145, "name": "Baseball bat", "freebase_id": "/m/03g8mr"}, {"id": 146, "name": "Racket", "freebase_id": "/m/0dv9c"}, {"id": 147, "name": "Sword", "freebase_id": "/m/06y5r"}, {"id": 148, "name": "Bagel", "freebase_id": "/m/01fb_0"}, {"id": 149, "name": "Goat", "freebase_id": "/m/03fwl"}, {"id": 150, "name": "Lizard", "freebase_id": "/m/04m9y"}, {"id": 151, "name": "Parrot", "freebase_id": "/m/0gv1x"}, {"id": 152, "name": "Owl", "freebase_id": "/m/09d5_"}, {"id": 153, "name": "Turkey", "freebase_id": "/m/0jly1"}, {"id": 154, "name": "Cello", "freebase_id": "/m/01xqw"}, {"id": 155, "name": "Knife", "freebase_id": "/m/04ctx"}, {"id": 156, "name": "Handgun", "freebase_id": "/m/0gxl3"}, {"id": 157, "name": "Carrot", "freebase_id": "/m/0fj52s"}, {"id": 158, "name": "Hamburger", "freebase_id": "/m/0cdn1"}, {"id": 159, "name": "Grapefruit", "freebase_id": "/m/0hqkz"}, {"id": 160, "name": "Tap", "freebase_id": "/m/02jz0l"}, {"id": 161, "name": "Tea", "freebase_id": "/m/07clx"}, {"id": 162, "name": "Bull", "freebase_id": "/m/0cnyhnx"}, {"id": 163, "name": "Turtle", "freebase_id": "/m/09dzg"}, {"id": 164, "name": "Bust", "freebase_id": "/m/04yqq2"}, {"id": 165, "name": "Monkey", "freebase_id": "/m/08pbxl"}, {"id": 166, "name": "Wok", "freebase_id": "/m/084rd"}, {"id": 167, "name": "Broccoli", "freebase_id": "/m/0hkxq"}, {"id": 168, "name": "Pitcher", "freebase_id": "/m/054fyh"}, {"id": 169, "name": "Whiteboard", "freebase_id": "/m/02d9qx"}, {"id": 170, "name": "Squirrel", "freebase_id": "/m/071qp"}, {"id": 171, "name": "Jug", "freebase_id": "/m/08hvt4"}, {"id": 172, "name": "Woodpecker", "freebase_id": "/m/01dy8n"}, {"id": 173, "name": "Pizza", "freebase_id": "/m/0663v"}, {"id": 174, "name": "Surfboard", "freebase_id": "/m/019w40"}, {"id": 175, "name": "Sofa bed", "freebase_id": "/m/03m3pdh"}, {"id": 176, "name": "Sheep", "freebase_id": "/m/07bgp"}, {"id": 177, "name": "Candle", "freebase_id": "/m/0c06p"}, {"id": 178, "name": "Muffin", "freebase_id": "/m/01tcjp"}, {"id": 179, "name": "Cookie", "freebase_id": "/m/021mn"}, {"id": 180, "name": "Apple", "freebase_id": "/m/014j1m"}, {"id": 181, "name": "Chest of drawers", "freebase_id": "/m/05kyg_"}, {"id": 182, "name": "Skull", "freebase_id": "/m/016m2d"}, {"id": 183, "name": "Chicken", "freebase_id": "/m/09b5t"}, {"id": 184, "name": "Loveseat", "freebase_id": "/m/0703r8"}, {"id": 185, "name": "Baseball glove", "freebase_id": "/m/03grzl"}, {"id": 186, "name": "Piano", "freebase_id": "/m/05r5c"}, {"id": 187, "name": "Waste container", "freebase_id": "/m/0bjyj5"}, {"id": 188, "name": "Barrel", "freebase_id": "/m/02zn6n"}, {"id": 189, "name": "Swan", "freebase_id": "/m/0dftk"}, {"id": 190, "name": "Taxi", "freebase_id": "/m/0pg52"}, {"id": 191, "name": "Lemon", "freebase_id": "/m/09k_b"}, {"id": 192, "name": "Pumpkin", "freebase_id": "/m/05zsy"}, {"id": 193, "name": "Sparrow", "freebase_id": "/m/0h23m"}, {"id": 194, "name": "Orange", "freebase_id": "/m/0cyhj_"}, {"id": 195, "name": "Tank", "freebase_id": "/m/07cmd"}, {"id": 196, "name": "Sandwich", "freebase_id": "/m/0l515"}, {"id": 197, "name": "Coffee", "freebase_id": "/m/02vqfm"}, {"id": 198, "name": "Juice", "freebase_id": "/m/01z1kdw"}, {"id": 199, "name": "Coin", "freebase_id": "/m/0242l"}, {"id": 200, "name": "Pen", "freebase_id": "/m/0k1tl"}, {"id": 201, "name": "Watch", "freebase_id": "/m/0gjkl"}, {"id": 202, "name": "Eagle", "freebase_id": "/m/09csl"}, {"id": 203, "name": "Goose", "freebase_id": "/m/0dbvp"}, {"id": 204, "name": "Falcon", "freebase_id": "/m/0f6wt"}, {"id": 205, "name": "Christmas tree", "freebase_id": "/m/025nd"}, {"id": 206, "name": "Sunflower", "freebase_id": "/m/0ftb8"}, {"id": 207, "name": "Vase", "freebase_id": "/m/02s195"}, {"id": 208, "name": "Football", "freebase_id": "/m/01226z"}, {"id": 209, "name": "Canoe", "freebase_id": "/m/0ph39"}, {"id": 210, "name": "High heels", "freebase_id": "/m/06k2mb"}, {"id": 211, "name": "Spoon", "freebase_id": "/m/0cmx8"}, {"id": 212, "name": "Mug", "freebase_id": "/m/02jvh9"}, {"id": 213, "name": "Swimwear", "freebase_id": "/m/01gkx_"}, {"id": 214, "name": "Duck", "freebase_id": "/m/09ddx"}, {"id": 215, "name": "Cat", "freebase_id": "/m/01yrx"}, {"id": 216, "name": "Tomato", "freebase_id": "/m/07j87"}, {"id": 217, "name": "Cocktail", "freebase_id": "/m/024g6"}, {"id": 218, "name": "Clock", "freebase_id": "/m/01x3z"}, {"id": 219, "name": "Cowboy hat", "freebase_id": "/m/025rp__"}, {"id": 220, "name": "Miniskirt", "freebase_id": "/m/01cmb2"}, {"id": 221, "name": "Cattle", "freebase_id": "/m/01xq0k1"}, {"id": 222, "name": "Strawberry", "freebase_id": "/m/07fbm7"}, {"id": 223, "name": "Bronze sculpture", "freebase_id": "/m/01yx86"}, {"id": 224, "name": "Pillow", "freebase_id": "/m/034c16"}, {"id": 225, "name": "Squash", "freebase_id": "/m/0dv77"}, {"id": 226, "name": "Traffic light", "freebase_id": "/m/015qff"}, {"id": 227, "name": "Saucer", "freebase_id": "/m/03q5c7"}, {"id": 228, "name": "Reptile", "freebase_id": "/m/06bt6"}, {"id": 229, "name": "Cake", "freebase_id": "/m/0fszt"}, {"id": 230, "name": "Plastic bag", "freebase_id": "/m/05gqfk"}, {"id": 231, "name": "Studio couch", "freebase_id": "/m/026qbn5"}, {"id": 232, "name": "Beer", "freebase_id": "/m/01599"}, {"id": 233, "name": "Scarf", "freebase_id": "/m/02h19r"}, {"id": 234, "name": "Coffee cup", "freebase_id": "/m/02p5f1q"}, {"id": 235, "name": "Wine", "freebase_id": "/m/081qc"}, {"id": 236, "name": "Mushroom", "freebase_id": "/m/052sf"}, {"id": 237, "name": "Traffic sign", "freebase_id": "/m/01mqdt"}, {"id": 238, "name": "Camera", "freebase_id": "/m/0dv5r"}, {"id": 239, "name": "Rose", "freebase_id": "/m/06m11"}, {"id": 240, "name": "Couch", "freebase_id": "/m/02crq1"}, {"id": 241, "name": "Handbag", "freebase_id": "/m/080hkjn"}, {"id": 242, "name": "Fedora", "freebase_id": "/m/02fq_6"}, {"id": 243, "name": "Sock", "freebase_id": "/m/01nq26"}, {"id": 244, "name": "Computer keyboard", "freebase_id": "/m/01m2v"}, {"id": 245, "name": "Mobile phone", "freebase_id": "/m/050k8"}, {"id": 246, "name": "Ball", "freebase_id": "/m/018xm"}, {"id": 247, "name": "Balloon", "freebase_id": "/m/01j51"}, {"id": 248, "name": "Horse", "freebase_id": "/m/03k3r"}, {"id": 249, "name": "Boot", "freebase_id": "/m/01b638"}, {"id": 250, "name": "Fish", "freebase_id": "/m/0ch_cf"}, {"id": 251, "name": "Backpack", "freebase_id": "/m/01940j"}, {"id": 252, "name": "Skirt", "freebase_id": "/m/02wv6h6"}, {"id": 253, "name": "Van", "freebase_id": "/m/0h2r6"}, {"id": 254, "name": "Bread", "freebase_id": "/m/09728"}, {"id": 255, "name": "Glove", "freebase_id": "/m/0174n1"}, {"id": 256, "name": "Dog", "freebase_id": "/m/0bt9lr"}, {"id": 257, "name": "Airplane", "freebase_id": "/m/0cmf2"}, {"id": 258, "name": "Motorcycle", "freebase_id": "/m/04_sv"}, {"id": 259, "name": "Drink", "freebase_id": "/m/0271t"}, {"id": 260, "name": "Book", "freebase_id": "/m/0bt_c3"}, {"id": 261, "name": "Train", "freebase_id": "/m/07jdr"}, {"id": 262, "name": "Flower", "freebase_id": "/m/0c9ph5"}, {"id": 263, "name": "Carnivore", "freebase_id": "/m/01lrl"}, {"id": 264, "name": "Human ear", "freebase_id": "/m/039xj_"}, {"id": 265, "name": "Toy", "freebase_id": "/m/0138tl"}, {"id": 266, "name": "Box", "freebase_id": "/m/025dyy"}, {"id": 267, "name": "Truck", "freebase_id": "/m/07r04"}, {"id": 268, "name": "Wheel", "freebase_id": "/m/083wq"}, {"id": 269, "name": "Aircraft", "freebase_id": "/m/0k5j"}, {"id": 270, "name": "Bus", "freebase_id": "/m/01bjv"}, {"id": 271, "name": "Human mouth", "freebase_id": "/m/0283dt1"}, {"id": 272, "name": "Sculpture", "freebase_id": "/m/06msq"}, {"id": 273, "name": "Shirt", "freebase_id": "/m/01n4qj"}, {"id": 274, "name": "Hat", "freebase_id": "/m/02dl1y"}, {"id": 275, "name": "Vehicle registration plate", "freebase_id": "/m/01jfm_"}, {"id": 276, "name": "Guitar", "freebase_id": "/m/0342h"}, {"id": 277, "name": "Sun hat", "freebase_id": "/m/02wbtzl"}, {"id": 278, "name": "Bottle", "freebase_id": "/m/04dr76w"}, {"id": 279, "name": "Luggage and bags", "freebase_id": "/m/0hf58v5"}, {"id": 280, "name": "Trousers", "freebase_id": "/m/07mhn"}, {"id": 281, "name": "Bicycle wheel", "freebase_id": "/m/01bqk0"}, {"id": 282, "name": "Suit", "freebase_id": "/m/01xyhv"}, {"id": 283, "name": "Bowl", "freebase_id": "/m/04kkgm"}, {"id": 284, "name": "Man", "freebase_id": "/m/04yx4"}, {"id": 285, "name": "Flowerpot", "freebase_id": "/m/0fm3zh"}, {"id": 286, "name": "Laptop", "freebase_id": "/m/01c648"}, {"id": 287, "name": "Boy", "freebase_id": "/m/01bl7v"}, {"id": 288, "name": "Picture frame", "freebase_id": "/m/06z37_"}, {"id": 289, "name": "Bird", "freebase_id": "/m/015p6"}, {"id": 290, "name": "Car", "freebase_id": "/m/0k4j"}, {"id": 291, "name": "Shorts", "freebase_id": "/m/01bfm9"}, {"id": 292, "name": "Woman", "freebase_id": "/m/03bt1vf"}, {"id": 293, "name": "Platter", "freebase_id": "/m/099ssp"}, {"id": 294, "name": "Tie", "freebase_id": "/m/01rkbr"}, {"id": 295, "name": "Girl", "freebase_id": "/m/05r655"}, {"id": 296, "name": "Skyscraper", "freebase_id": "/m/079cl"}, {"id": 297, "name": "Person", "freebase_id": "/m/01g317"}, {"id": 298, "name": "Flag", "freebase_id": "/m/03120"}, {"id": 299, "name": "Jeans", "freebase_id": "/m/0fly7"}, {"id": 300, "name": "Dress", "freebase_id": "/m/01d40f"},]
def _get_builtin_metadata(cats, class_image_count=None): id_to_name = {x["id"]: x["name"] for x in cats} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(cats))} thing_classes = [x["name"] for x in sorted(cats, key=lambda x: x["id"])] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, "class_image_count": class_image_count, }
_PREDEFINED_SPLITS_OID = { "oid_train": ("oid/images/train/", "oid/annotations/oid_challenge_2019_train_bbox.json"), "oid_val": ("oid/images/validation/", "oid/annotations/oid_challenge_2019_val.json"), "oid_val_expanded": ( "oid/images/validation/", "oid/annotations/oid_challenge_2019_val_expanded.json", ), "oid_kaggle_test": ("oid/images/test/", "oid/annotations/oid_kaggle_test_image_info.json"),}
for key, (image_root, json_file) in _PREDEFINED_SPLITS_OID.items(): register_oid_instances( key, _get_builtin_metadata(OPENIMAGES_2019_CATEGORIES), os.path.join("datasets", json_file) if "://" not in json_file else json_file, os.path.join("datasets", image_root), )
_PREDEFINED_SPLITS_OID_SEG = { "oid_seg_train": ("oid/images/train/", "oid/annotations/openimages_instances_train.json"), "oid_seg_val": ("oid/images/validation/", "oid/annotations/openimages_instances_val.json"), "oid_seg_kaggle_test": ( "oid/images/test/", "oid/annotations/openimages_instances_kaggle_test_image_info.json", ),}
for key, (image_root, json_file) in _PREDEFINED_SPLITS_OID_SEG.items(): register_oid_instances( key, _get_builtin_metadata(categories_seg), os.path.join("datasets", json_file) if "://" not in json_file else json_file, os.path.join("datasets", image_root), )
_PREDEFINED_SPLITS_OPENIMAGES_DETECTION = { "openimages_challenge_2019_train": ( "openimages/train/", "openimages/annotations/openimages_challenge_2019_train_bbox.json", ), "openimages_challenge_2019_val": ( "openimages/validation/", "openimages/annotations/openimages_challenge_2019_val_bbox.json", ),}
for key, (image_root, json_file) in _PREDEFINED_SPLITS_OPENIMAGES_DETECTION.items(): register_oid_instances( key, _get_builtin_metadata(OPENIMAGES_2019_CATEGORIES), os.path.join("datasets", json_file) if "://" not in json_file else json_file, os.path.join("datasets", image_root), )
_PREDEFINED_SPLITS_OPENIMAGES_V6_DETECTION = { "openimages_v6_train_bbox": ( "openimages/train/", "openimages/annotations/openimages_v6_train_bbox.json", ), "openimages_v6_train_bbox_nogroup": ( "openimages/train/", "openimages/annotations/openimages_v6_train_bbox_nogroup.json", ), "openimages_v6_val_bbox": ( "openimages/validation/", "openimages/annotations/openimages_v6_val_bbox.json", ), "openimages_v6_val_bbox_nogroup": ( "openimages/validation/", "openimages/annotations/openimages_v6_val_bbox_nogroup.json", ), "openimages_v6_train_instance": ( "openimages/train/", "openimages/annotations/openimages_v6_train_instance.json", ), "openimages_v6_val_instance": ( "openimages/validation/", "openimages/annotations/openimages_v6_val_instance.json", ), "openimages_v6_train_bbox_instance": ( "openimages/train/", "openimages/annotations/openimages_v6_train_bbox_instance.json", ), "openimages_v6_val_bbox_instance": ( "openimages/validation/", "openimages/annotations/openimages_v6_val_bbox_instance.json", ),}
def register_all_oid(root): for key, (image_root, json_file) in _PREDEFINED_SPLITS_OPENIMAGES_V6_DETECTION.items(): register_oid_instances( key, _get_builtin_metadata(OPENIMAGES_V6_CATEGORIES, OPENIMAGES_v6_CATEGORY_IMAGE_COUNT), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".oid"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_oid(_root)12OPENIMAGES_v6_CATEGORY_IMAGE_COUNT = [{"id": 1, "name": "Tortoise", "freebase_id": "/m/011k07", "image_count": 1151, "instance_count": 1678}, {"id": 2, "name": "Container", "freebase_id": "/m/011q46kg", "image_count": 0, "instance_count": 0}, {"id": 3, "name": "Magpie", "freebase_id": "/m/012074", "image_count": 100, "instance_count": 117}, {"id": 4, "name": "Sea turtle", "freebase_id": "/m/0120dh", "image_count": 664, "instance_count": 999}, {"id": 5, "name": "Football", "freebase_id": "/m/01226z", "image_count": 2727, "instance_count": 3150}, {"id": 6, "name": "Ambulance", "freebase_id": "/m/012n7d", "image_count": 305, "instance_count": 391}, {"id": 7, "name": "Ladder", "freebase_id": "/m/012w5l", "image_count": 679, "instance_count": 895}, {"id": 8, "name": "Toothbrush", "freebase_id": "/m/012xff", "image_count": 106, "instance_count": 202}, {"id": 9, "name": "Syringe", "freebase_id": "/m/012ysf", "image_count": 92, "instance_count": 124}, {"id": 10, "name": "Sink", "freebase_id": "/m/0130jx", "image_count": 1165, "instance_count": 1327}, {"id": 11, "name": "Toy", "freebase_id": "/m/0138tl", "image_count": 13584, "instance_count": 43916}, {"id": 12, "name": "Organ (Musical Instrument)", "freebase_id": "/m/013y1f", "image_count": 366, "instance_count": 386}, {"id": 13, "name": "Cassette deck", "freebase_id": "/m/01432t", "image_count": 49, "instance_count": 66}, {"id": 14, "name": "Apple", "freebase_id": "/m/014j1m", "image_count": 630, "instance_count": 1624}, {"id": 15, "name": "Human eye", "freebase_id": "/m/014sv8", "image_count": 20295, "instance_count": 58440}, {"id": 16, "name": "Cosmetics", "freebase_id": "/m/014trl", "image_count": 790, "instance_count": 2090}, {"id": 17, "name": "Paddle", "freebase_id": "/m/014y4n", "image_count": 1705, "instance_count": 4598}, {"id": 18, "name": "Snowman", "freebase_id": "/m/0152hh", "image_count": 497, "instance_count": 696}, {"id": 19, "name": "Beer", "freebase_id": "/m/01599", "image_count": 4063, "instance_count": 7841}, {"id": 20, "name": "Chopsticks", "freebase_id": "/m/01_5g", "image_count": 353, "instance_count": 448}, {"id": 21, "name": "Human beard", "freebase_id": "/m/015h_t", "image_count": 2530, "instance_count": 2845}, {"id": 22, "name": "Bird", "freebase_id": "/m/015p6", "image_count": 15042, "instance_count": 32316}, {"id": 23, "name": "Parking meter", "freebase_id": "/m/015qbp", "image_count": 176, "instance_count": 208}, {"id": 24, "name": "Traffic light", "freebase_id": "/m/015qff", "image_count": 1188, "instance_count": 4663}, {"id": 25, "name": "Croissant", "freebase_id": "/m/015wgc", "image_count": 167, "instance_count": 307}, {"id": 26, "name": "Cucumber", "freebase_id": "/m/015x4r", "image_count": 200, "instance_count": 477}, {"id": 27, "name": "Radish", "freebase_id": "/m/015x5n", "image_count": 80, "instance_count": 325}, {"id": 28, "name": "Towel", "freebase_id": "/m/0162_1", "image_count": 118, "instance_count": 202}, {"id": 29, "name": "Doll", "freebase_id": "/m/0167gd", "image_count": 3049, "instance_count": 5446}, {"id": 30, "name": "Skull", "freebase_id": "/m/016m2d", "image_count": 1407, "instance_count": 2340}, {"id": 31, "name": "Washing machine", "freebase_id": "/m/0174k2", "image_count": 299, "instance_count": 593}, {"id": 32, "name": "Glove", "freebase_id": "/m/0174n1", "image_count": 656, "instance_count": 1071}, {"id": 33, "name": "Tick", "freebase_id": "/m/0175cv", "image_count": 95, "instance_count": 127}, {"id": 34, "name": "Belt", "freebase_id": "/m/0176mf", "image_count": 341, "instance_count": 411}, {"id": 35, "name": "Sunglasses", "freebase_id": "/m/017ftj", "image_count": 12875, "instance_count": 19324}, {"id": 36, "name": "Banjo", "freebase_id": "/m/018j2", "image_count": 235, "instance_count": 253}, {"id": 37, "name": "Cart", "freebase_id": "/m/018p4k", "image_count": 1376, "instance_count": 1910}, {"id": 38, "name": "Ball", "freebase_id": "/m/018xm", "image_count": 2479, "instance_count": 4943}, {"id": 39, "name": "Backpack", "freebase_id": "/m/01940j", "image_count": 598, "instance_count": 966}, {"id": 40, "name": "Bicycle", "freebase_id": "/m/0199g", "image_count": 11536, "instance_count": 21840}, {"id": 41, "name": "Home appliance", "freebase_id": "/m/019dx1", "image_count": 893, "instance_count": 1732}, {"id": 42, "name": "Centipede", "freebase_id": "/m/019h78", "image_count": 231, "instance_count": 275}, {"id": 43, "name": "Boat", "freebase_id": "/m/019jd", "image_count": 19756, "instance_count": 54017}, {"id": 44, "name": "Surfboard", "freebase_id": "/m/019w40", "image_count": 1641, "instance_count": 2427}, {"id": 45, "name": "Boot", "freebase_id": "/m/01b638", "image_count": 1311, "instance_count": 2812}, {"id": 46, "name": "Headphones", "freebase_id": "/m/01b7fy", "image_count": 1028, "instance_count": 1193}, {"id": 47, "name": "Hot dog", "freebase_id": "/m/01b9xk", "image_count": 311, "instance_count": 405}, {"id": 48, "name": "Shorts", "freebase_id": "/m/01bfm9", "image_count": 5427, "instance_count": 12674}, {"id": 49, "name": "Fast food", "freebase_id": "/m/01_bhs", "image_count": 4621, "instance_count": 11599}, {"id": 50, "name": "Bus", "freebase_id": "/m/01bjv", "image_count": 5811, "instance_count": 9584}, {"id": 51, "name": "Boy", "freebase_id": "/m/01bl7v", "image_count": 36079, "instance_count": 61661}, {"id": 52, "name": "Screwdriver", "freebase_id": "/m/01bms0", "image_count": 46, "instance_count": 85}, {"id": 53, "name": "Bicycle wheel", "freebase_id": "/m/01bqk0", "image_count": 10655, "instance_count": 31513}, {"id": 54, "name": "Barge", "freebase_id": "/m/01btn", "image_count": 295, "instance_count": 690}, {"id": 55, "name": "Laptop", "freebase_id": "/m/01c648", "image_count": 5171, "instance_count": 8213}, {"id": 56, "name": "Miniskirt", "freebase_id": "/m/01cmb2", "image_count": 674, "instance_count": 851}, {"id": 57, "name": "Drill (Tool)", "freebase_id": "/m/01d380", "image_count": 169, "instance_count": 201}, {"id": 58, "name": "Dress", "freebase_id": "/m/01d40f", "image_count": 25529, "instance_count": 41137}, {"id": 59, "name": "Bear", "freebase_id": "/m/01dws", "image_count": 270, "instance_count": 326}, {"id": 60, "name": "Waffle", "freebase_id": "/m/01dwsz", "image_count": 327, "instance_count": 581}, {"id": 61, "name": "Pancake", "freebase_id": "/m/01dwwc", "image_count": 181, "instance_count": 437}, {"id": 62, "name": "Brown bear", "freebase_id": "/m/01dxs", "image_count": 403, "instance_count": 532}, {"id": 63, "name": "Woodpecker", "freebase_id": "/m/01dy8n", "image_count": 391, "instance_count": 480}, {"id": 64, "name": "Blue jay", "freebase_id": "/m/01f8m5", "image_count": 210, "instance_count": 233}, {"id": 65, "name": "Pretzel", "freebase_id": "/m/01f91_", "image_count": 123, "instance_count": 220}, {"id": 66, "name": "Bagel", "freebase_id": "/m/01fb_0", "image_count": 173, "instance_count": 374}, {"id": 67, "name": "Tower", "freebase_id": "/m/01fdzj", "image_count": 16337, "instance_count": 44982}, {"id": 68, "name": "Teapot", "freebase_id": "/m/01fh4r", "image_count": 448, "instance_count": 564}, {"id": 69, "name": "Person", "freebase_id": "/m/01g317", "image_count": 177356, "instance_count": 595849}, {"id": 70, "name": "Bow and arrow", "freebase_id": "/m/01g3x7", "image_count": 235, "instance_count": 459}, {"id": 71, "name": "Swimwear", "freebase_id": "/m/01gkx_", "image_count": 3084, "instance_count": 8645}, {"id": 72, "name": "Beehive", "freebase_id": "/m/01gllr", "image_count": 283, "instance_count": 327}, {"id": 73, "name": "Brassiere", "freebase_id": "/m/01gmv2", "image_count": 1146, "instance_count": 1567}, {"id": 74, "name": "Bee", "freebase_id": "/m/01h3n", "image_count": 2113, "instance_count": 4484}, {"id": 75, "name": "Bat (Animal)", "freebase_id": "/m/01h44", "image_count": 331, "instance_count": 490}, {"id": 76, "name": "Starfish", "freebase_id": "/m/01h8tj", "image_count": 409, "instance_count": 577}, {"id": 77, "name": "Popcorn", "freebase_id": "/m/01hrv5", "image_count": 179, "instance_count": 245}, {"id": 78, "name": "Burrito", "freebase_id": "/m/01j3zr", "image_count": 160, "instance_count": 251}, {"id": 79, "name": "Chainsaw", "freebase_id": "/m/01j4z9", "image_count": 100, "instance_count": 106}, {"id": 80, "name": "Balloon", "freebase_id": "/m/01j51", "image_count": 1691, "instance_count": 8440}, {"id": 81, "name": "Wrench", "freebase_id": "/m/01j5ks", "image_count": 54, "instance_count": 134}, {"id": 82, "name": "Tent", "freebase_id": "/m/01j61q", "image_count": 1588, "instance_count": 2929}, {"id": 83, "name": "Vehicle registration plate", "freebase_id": "/m/01jfm_", "image_count": 3956, "instance_count": 5420}, {"id": 84, "name": "Lantern", "freebase_id": "/m/01jfsr", "image_count": 555, "instance_count": 2221}, {"id": 85, "name": "Toaster", "freebase_id": "/m/01k6s3", "image_count": 56, "instance_count": 68}, {"id": 86, "name": "Flashlight", "freebase_id": "/m/01kb5b", "image_count": 60, "instance_count": 85}, {"id": 87, "name": "Billboard", "freebase_id": "/m/01knjb", "image_count": 2628, "instance_count": 6604}, {"id": 88, "name": "Tiara", "freebase_id": "/m/01krhy", "image_count": 330, "instance_count": 360}, {"id": 89, "name": "Limousine", "freebase_id": "/m/01lcw4", "image_count": 315, "instance_count": 346}, {"id": 90, "name": "Necklace", "freebase_id": "/m/01llwg", "image_count": 2122, "instance_count": 2537}, {"id": 91, "name": "Carnivore", "freebase_id": "/m/01lrl", "image_count": 1909, "instance_count": 2859}, {"id": 92, "name": "Scissors", "freebase_id": "/m/01lsmm", "image_count": 283, "instance_count": 388}, {"id": 93, "name": "Stairs", "freebase_id": "/m/01lynh", "image_count": 2057, "instance_count": 2501}, {"id": 94, "name": "Computer keyboard", "freebase_id": "/m/01m2v", "image_count": 3226, "instance_count": 4338}, {"id": 95, "name": "Printer", "freebase_id": "/m/01m4t", "image_count": 199, "instance_count": 252}, {"id": 96, "name": "Traffic sign", "freebase_id": "/m/01mqdt", "image_count": 1923, "instance_count": 4030}, {"id": 97, "name": "Chair", "freebase_id": "/m/01mzpv", "image_count": 19112, "instance_count": 87999}, {"id": 98, "name": "Shirt", "freebase_id": "/m/01n4qj", "image_count": 4971, "instance_count": 7016}, {"id": 99, "name": "Poster", "freebase_id": "/m/01n5jq", "image_count": 14231, "instance_count": 19811}, {"id": 100, "name": "Cheese", "freebase_id": "/m/01nkt", "image_count": 330, "instance_count": 1039}, {"id": 101, "name": "Sock", "freebase_id": "/m/01nq26", "image_count": 643, "instance_count": 1330}, {"id": 102, "name": "Fire hydrant", "freebase_id": "/m/01pns0", "image_count": 388, "instance_count": 412}, {"id": 103, "name": "Land vehicle", "freebase_id": "/m/01prls", "image_count": 20402, "instance_count": 45498}, {"id": 104, "name": "Earrings", "freebase_id": "/m/01r546", "image_count": 661, "instance_count": 1426}, {"id": 105, "name": "Tie", "freebase_id": "/m/01rkbr", "image_count": 7470, "instance_count": 10074}, {"id": 106, "name": "Watercraft", "freebase_id": "/m/01rzcn", "image_count": 2164, "instance_count": 4456}, {"id": 107, "name": "Cabinetry", "freebase_id": "/m/01s105", "image_count": 2011, "instance_count": 5908}, {"id": 108, "name": "Suitcase", "freebase_id": "/m/01s55n", "image_count": 367, "instance_count": 573}, {"id": 109, "name": "Muffin", "freebase_id": "/m/01tcjp", "image_count": 795, "instance_count": 2926}, {"id": 110, "name": "Bidet", "freebase_id": "/m/01vbnl", "image_count": 346, "instance_count": 406}, {"id": 111, "name": "Snack", "freebase_id": "/m/01ww8y", "image_count": 5792, "instance_count": 15326}, {"id": 112, "name": "Snowmobile", "freebase_id": "/m/01x3jk", "image_count": 161, "instance_count": 290}, {"id": 113, "name": "Clock", "freebase_id": "/m/01x3z", "image_count": 846, "instance_count": 1099}, {"id": 114, "name": "Medical equipment", "freebase_id": "/m/01xgg_", "image_count": 588, "instance_count": 1747}, {"id": 115, "name": "Cattle", "freebase_id": "/m/01xq0k1", "image_count": 1786, "instance_count": 6183}, {"id": 116, "name": "Cello", "freebase_id": "/m/01xqw", "image_count": 1230, "instance_count": 1802}, {"id": 117, "name": "Jet ski", "freebase_id": "/m/01xs3r", "image_count": 445, "instance_count": 518}, {"id": 118, "name": "Camel", "freebase_id": "/m/01x_v", "image_count": 632, "instance_count": 1136}, {"id": 119, "name": "Coat", "freebase_id": "/m/01xygc", "image_count": 3005, "instance_count": 5370}, {"id": 120, "name": "Suit", "freebase_id": "/m/01xyhv", "image_count": 39016, "instance_count": 91879}, {"id": 121, "name": "Desk", "freebase_id": "/m/01y9k5", "image_count": 8004, "instance_count": 9623}, {"id": 122, "name": "Cat", "freebase_id": "/m/01yrx", "image_count": 11569, "instance_count": 13979}, {"id": 123, "name": "Bronze sculpture", "freebase_id": "/m/01yx86", "image_count": 1928, "instance_count": 2312}, {"id": 124, "name": "Juice", "freebase_id": "/m/01z1kdw", "image_count": 1500, "instance_count": 2262}, {"id": 125, "name": "Gondola", "freebase_id": "/m/02068x", "image_count": 430, "instance_count": 1375}, {"id": 126, "name": "Beetle", "freebase_id": "/m/020jm", "image_count": 1763, "instance_count": 3256}, {"id": 127, "name": "Cannon", "freebase_id": "/m/020kz", "image_count": 612, "instance_count": 840}, {"id": 128, "name": "Computer mouse", "freebase_id": "/m/020lf", "image_count": 614, "instance_count": 724}, {"id": 129, "name": "Cookie", "freebase_id": "/m/021mn", "image_count": 552, "instance_count": 3012}, {"id": 130, "name": "Office building", "freebase_id": "/m/021sj1", "image_count": 4298, "instance_count": 4331}, {"id": 131, "name": "Fountain", "freebase_id": "/m/0220r2", "image_count": 1888, "instance_count": 2201}, {"id": 132, "name": "Coin", "freebase_id": "/m/0242l", "image_count": 1031, "instance_count": 2533}, {"id": 133, "name": "Calculator", "freebase_id": "/m/024d2", "image_count": 166, "instance_count": 202}, {"id": 134, "name": "Cocktail", "freebase_id": "/m/024g6", "image_count": 2320, "instance_count": 3886}, {"id": 135, "name": "Computer monitor", "freebase_id": "/m/02522", "image_count": 3117, "instance_count": 5551}, {"id": 136, "name": "Box", "freebase_id": "/m/025dyy", "image_count": 1897, "instance_count": 3928}, {"id": 137, "name": "Stapler", "freebase_id": "/m/025fsf", "image_count": 48, "instance_count": 58}, {"id": 138, "name": "Christmas tree", "freebase_id": "/m/025nd", "image_count": 2860, "instance_count": 3816}, {"id": 139, "name": "Cowboy hat", "freebase_id": "/m/025rp__", "image_count": 1727, "instance_count": 2430}, {"id": 140, "name": "Hiking equipment", "freebase_id": "/m/0268lbt", "image_count": 1522, "instance_count": 5428}, {"id": 141, "name": "Studio couch", "freebase_id": "/m/026qbn5", "image_count": 1010, "instance_count": 1694}, {"id": 142, "name": "Drum", "freebase_id": "/m/026t6", "image_count": 6693, "instance_count": 20291}, {"id": 143, "name": "Dessert", "freebase_id": "/m/0270h", "image_count": 6296, "instance_count": 15225}, {"id": 144, "name": "Wine rack", "freebase_id": "/m/0271qf7", "image_count": 92, "instance_count": 178}, {"id": 145, "name": "Drink", "freebase_id": "/m/0271t", "image_count": 13243, "instance_count": 29099}, {"id": 146, "name": "Zucchini", "freebase_id": "/m/027pcv", "image_count": 135, "instance_count": 442}, {"id": 147, "name": "Ladle", "freebase_id": "/m/027rl48", "image_count": 19, "instance_count": 53}, {"id": 148, "name": "Human mouth", "freebase_id": "/m/0283dt1", "image_count": 20878, "instance_count": 33204}, {"id": 149, "name": "Dairy Product", "freebase_id": "/m/0284d", "image_count": 2532, "instance_count": 5946}, {"id": 150, "name": "Dice", "freebase_id": "/m/029b3", "image_count": 180, "instance_count": 557}, {"id": 151, "name": "Oven", "freebase_id": "/m/029bxz", "image_count": 383, "instance_count": 477}, {"id": 152, "name": "Dinosaur", "freebase_id": "/m/029tx", "image_count": 947, "instance_count": 1464}, {"id": 153, "name": "Ratchet (Device)", "freebase_id": "/m/02bm9n", "image_count": 35, "instance_count": 200}, {"id": 154, "name": "Couch", "freebase_id": "/m/02crq1", "image_count": 3017, "instance_count": 3847}, {"id": 155, "name": "Cricket ball", "freebase_id": "/m/02ctlc", "image_count": 83, "instance_count": 107}, {"id": 156, "name": "Winter melon", "freebase_id": "/m/02cvgx", "image_count": 31, "instance_count": 31}, {"id": 157, "name": "Spatula", "freebase_id": "/m/02d1br", "image_count": 33, "instance_count": 50}, {"id": 158, "name": "Whiteboard", "freebase_id": "/m/02d9qx", "image_count": 885, "instance_count": 983}, {"id": 159, "name": "Pencil sharpener", "freebase_id": "/m/02ddwp", "image_count": 13, "instance_count": 21}, {"id": 160, "name": "Door", "freebase_id": "/m/02dgv", "image_count": 11793, "instance_count": 16893}, {"id": 161, "name": "Hat", "freebase_id": "/m/02dl1y", "image_count": 7366, "instance_count": 10747}, {"id": 162, "name": "Shower", "freebase_id": "/m/02f9f_", "image_count": 200, "instance_count": 229}, {"id": 163, "name": "Eraser", "freebase_id": "/m/02fh7f", "image_count": 24, "instance_count": 53}, {"id": 164, "name": "Fedora", "freebase_id": "/m/02fq_6", "image_count": 2660, "instance_count": 3231}, {"id": 165, "name": "Guacamole", "freebase_id": "/m/02g30s", "image_count": 156, "instance_count": 195}, {"id": 166, "name": "Dagger", "freebase_id": "/m/02gzp", "image_count": 258, "instance_count": 363}, {"id": 167, "name": "Scarf", "freebase_id": "/m/02h19r", "image_count": 1843, "instance_count": 2097}, {"id": 168, "name": "Dolphin", "freebase_id": "/m/02hj4", "image_count": 796, "instance_count": 1363}, {"id": 169, "name": "Sombrero", "freebase_id": "/m/02jfl0", "image_count": 439, "instance_count": 561}, {"id": 170, "name": "Tin can", "freebase_id": "/m/02jnhm", "image_count": 1059, "instance_count": 2175}, {"id": 171, "name": "Mug", "freebase_id": "/m/02jvh9", "image_count": 1466, "instance_count": 1969}, {"id": 172, "name": "Tap", "freebase_id": "/m/02jz0l", "image_count": 1031, "instance_count": 1463}, {"id": 173, "name": "Harbor seal", "freebase_id": "/m/02l8p9", "image_count": 745, "instance_count": 1319}, {"id": 174, "name": "Stretcher", "freebase_id": "/m/02lbcq", "image_count": 112, "instance_count": 163}, {"id": 175, "name": "Can opener", "freebase_id": "/m/02mqfb", "image_count": 6, "instance_count": 7}, {"id": 176, "name": "Goggles", "freebase_id": "/m/02_n6y", "image_count": 6447, "instance_count": 8292}, {"id": 177, "name": "Human body", "freebase_id": "/m/02p0tk3", "image_count": 34502, "instance_count": 102243}, {"id": 178, "name": "Roller skates", "freebase_id": "/m/02p3w7d", "image_count": 477, "instance_count": 3430}, {"id": 179, "name": "Coffee cup", "freebase_id": "/m/02p5f1q", "image_count": 3391, "instance_count": 4561}, {"id": 180, "name": "Cutting board", "freebase_id": "/m/02pdsw", "image_count": 167, "instance_count": 180}, {"id": 181, "name": "Blender", "freebase_id": "/m/02pjr4", "image_count": 133, "instance_count": 208}, {"id": 182, "name": "Plumbing fixture", "freebase_id": "/m/02pkr5", "image_count": 251, "instance_count": 461}, {"id": 183, "name": "Stop sign", "freebase_id": "/m/02pv19", "image_count": 318, "instance_count": 330}, {"id": 184, "name": "Office supplies", "freebase_id": "/m/02rdsp", "image_count": 1185, "instance_count": 5501}, {"id": 185, "name": "Volleyball (Ball)", "freebase_id": "/m/02rgn06", "image_count": 539, "instance_count": 610}, {"id": 186, "name": "Vase", "freebase_id": "/m/02s195", "image_count": 1067, "instance_count": 1653}, {"id": 187, "name": "Slow cooker", "freebase_id": "/m/02tsc9", "image_count": 89, "instance_count": 102}, {"id": 188, "name": "Wardrobe", "freebase_id": "/m/02vkqh8", "image_count": 169, "instance_count": 194}, {"id": 189, "name": "Coffee", "freebase_id": "/m/02vqfm", "image_count": 1731, "instance_count": 2060}, {"id": 190, "name": "Whisk", "freebase_id": "/m/02vwcm", "image_count": 157, "instance_count": 180}, {"id": 191, "name": "Paper towel", "freebase_id": "/m/02w3r3", "image_count": 123, "instance_count": 175}, {"id": 192, "name": "Personal care", "freebase_id": "/m/02w3_ws", "image_count": 115, "instance_count": 358}, {"id": 193, "name": "Food", "freebase_id": "/m/02wbm", "image_count": 15714, "instance_count": 43473}, {"id": 194, "name": "Sun hat", "freebase_id": "/m/02wbtzl", "image_count": 3547, "instance_count": 5325}, {"id": 195, "name": "Tree house", "freebase_id": "/m/02wg_p", "image_count": 85, "instance_count": 87}, {"id": 196, "name": "Flying disc", "freebase_id": "/m/02wmf", "image_count": 178, "instance_count": 201}, {"id": 197, "name": "Skirt", "freebase_id": "/m/02wv6h6", "image_count": 819, "instance_count": 1060}, {"id": 198, "name": "Gas stove", "freebase_id": "/m/02wv84t", "image_count": 369, "instance_count": 412}, {"id": 199, "name": "Salt and pepper shakers", "freebase_id": "/m/02x8cch", "image_count": 89, "instance_count": 167}, {"id": 200, "name": "Mechanical fan", "freebase_id": "/m/02x984l", "image_count": 542, "instance_count": 626}, {"id": 201, "name": "Face powder", "freebase_id": "/m/02xb7qb", "image_count": 45, "instance_count": 72}, {"id": 202, "name": "Fax", "freebase_id": "/m/02xqq", "image_count": 22, "instance_count": 28}, {"id": 203, "name": "Fruit", "freebase_id": "/m/02xwb", "image_count": 2074, "instance_count": 6691}, {"id": 204, "name": "French fries", "freebase_id": "/m/02y6n", "image_count": 64, "instance_count": 598}, {"id": 205, "name": "Nightstand", "freebase_id": "/m/02z51p", "image_count": 620, "instance_count": 917}, {"id": 206, "name": "Barrel", "freebase_id": "/m/02zn6n", "image_count": 368, "instance_count": 1227}, {"id": 207, "name": "Kite", "freebase_id": "/m/02zt3", "image_count": 313, "instance_count": 1373}, {"id": 208, "name": "Tart", "freebase_id": "/m/02zvsm", "image_count": 315, "instance_count": 579}, {"id": 209, "name": "Treadmill", "freebase_id": "/m/030610", "image_count": 90, "instance_count": 190}, {"id": 210, "name": "Fox", "freebase_id": "/m/0306r", "image_count": 404, "instance_count": 462}, {"id": 211, "name": "Flag", "freebase_id": "/m/03120", "image_count": 6289, "instance_count": 18394}, {"id": 212, "name": "French horn", "freebase_id": "/m/0319l", "image_count": 264, "instance_count": 874}, {"id": 213, "name": "Window blind", "freebase_id": "/m/031b6r", "image_count": 378, "instance_count": 535}, {"id": 214, "name": "Human foot", "freebase_id": "/m/031n1", "image_count": 920, "instance_count": 2034}, {"id": 215, "name": "Golf cart", "freebase_id": "/m/0323sq", "image_count": 240, "instance_count": 375}, {"id": 216, "name": "Jacket", "freebase_id": "/m/032b3c", "image_count": 10693, "instance_count": 20010}, {"id": 217, "name": "Egg (Food)", "freebase_id": "/m/033cnk", "image_count": 514, "instance_count": 1026}, {"id": 218, "name": "Street light", "freebase_id": "/m/033rq4", "image_count": 7025, "instance_count": 24201}, {"id": 219, "name": "Guitar", "freebase_id": "/m/0342h", "image_count": 16260, "instance_count": 23053}, {"id": 220, "name": "Pillow", "freebase_id": "/m/034c16", "image_count": 1183, "instance_count": 3280}, {"id": 221, "name": "Human leg", "freebase_id": "/m/035r7c", "image_count": 13140, "instance_count": 47109}, {"id": 222, "name": "Isopod", "freebase_id": "/m/035vxb", "image_count": 85, "instance_count": 141}, {"id": 223, "name": "Grape", "freebase_id": "/m/0388q", "image_count": 20, "instance_count": 161}, {"id": 224, "name": "Human ear", "freebase_id": "/m/039xj_", "image_count": 7339, "instance_count": 13645}, {"id": 225, "name": "Power plugs and sockets", "freebase_id": "/m/03bbps", "image_count": 139, "instance_count": 272}, {"id": 226, "name": "Panda", "freebase_id": "/m/03bj1", "image_count": 480, "instance_count": 706}, {"id": 227, "name": "Giraffe", "freebase_id": "/m/03bk1", "image_count": 680, "instance_count": 1024}, {"id": 228, "name": "Woman", "freebase_id": "/m/03bt1vf", "image_count": 211054, "instance_count": 519938}, {"id": 229, "name": "Door handle", "freebase_id": "/m/03c7gz", "image_count": 557, "instance_count": 716}, {"id": 230, "name": "Rhinoceros", "freebase_id": "/m/03d443", "image_count": 447, "instance_count": 611}, {"id": 231, "name": "Bathtub", "freebase_id": "/m/03dnzn", "image_count": 490, "instance_count": 501}, {"id": 232, "name": "Goldfish", "freebase_id": "/m/03fj2", "image_count": 325, "instance_count": 1409}, {"id": 233, "name": "Houseplant", "freebase_id": "/m/03fp41", "image_count": 5512, "instance_count": 11884}, {"id": 234, "name": "Goat", "freebase_id": "/m/03fwl", "image_count": 827, "instance_count": 1418}, {"id": 235, "name": "Baseball bat", "freebase_id": "/m/03g8mr", "image_count": 919, "instance_count": 1031}, {"id": 236, "name": "Baseball glove", "freebase_id": "/m/03grzl", "image_count": 1423, "instance_count": 2114}, {"id": 237, "name": "Mixing bowl", "freebase_id": "/m/03hj559", "image_count": 480, "instance_count": 761}, {"id": 238, "name": "Marine invertebrates", "freebase_id": "/m/03hl4l9", "image_count": 1335, "instance_count": 7073}, {"id": 239, "name": "Kitchen utensil", "freebase_id": "/m/03hlz0c", "image_count": 208, "instance_count": 390}, {"id": 240, "name": "Light switch", "freebase_id": "/m/03jbxj", "image_count": 78, "instance_count": 95}, {"id": 241, "name": "House", "freebase_id": "/m/03jm5", "image_count": 37094, "instance_count": 81831}, {"id": 242, "name": "Horse", "freebase_id": "/m/03k3r", "image_count": 5023, "instance_count": 9118}, {"id": 243, "name": "Stationary bicycle", "freebase_id": "/m/03kt2w", "image_count": 81, "instance_count": 226}, {"id": 244, "name": "Hammer", "freebase_id": "/m/03l9g", "image_count": 117, "instance_count": 136}, {"id": 245, "name": "Ceiling fan", "freebase_id": "/m/03ldnb", "image_count": 399, "instance_count": 442}, {"id": 246, "name": "Sofa bed", "freebase_id": "/m/03m3pdh", "image_count": 1031, "instance_count": 1360}, {"id": 247, "name": "Adhesive tape", "freebase_id": "/m/03m3vtv", "image_count": 94, "instance_count": 203}, {"id": 248, "name": "Harp", "freebase_id": "/m/03m5k", "image_count": 197, "instance_count": 227}, {"id": 249, "name": "Sandal", "freebase_id": "/m/03nfch", "image_count": 1214, "instance_count": 2617}, {"id": 250, "name": "Bicycle helmet", "freebase_id": "/m/03p3bw", "image_count": 2970, "instance_count": 6430}, {"id": 251, "name": "Saucer", "freebase_id": "/m/03q5c7", "image_count": 1388, "instance_count": 2349}, {"id": 252, "name": "Harpsichord", "freebase_id": "/m/03q5t", "image_count": 189, "instance_count": 206}, {"id": 253, "name": "Human hair", "freebase_id": "/m/03q69", "image_count": 43629, "instance_count": 125286}, {"id": 254, "name": "Heater", "freebase_id": "/m/03qhv5", "image_count": 32, "instance_count": 35}, {"id": 255, "name": "Harmonica", "freebase_id": "/m/03qjg", "image_count": 20, "instance_count": 38}, {"id": 256, "name": "Hamster", "freebase_id": "/m/03qrc", "image_count": 433, "instance_count": 518}, {"id": 257, "name": "Curtain", "freebase_id": "/m/03rszm", "image_count": 2271, "instance_count": 4094}, {"id": 258, "name": "Bed", "freebase_id": "/m/03ssj5", "image_count": 2667, "instance_count": 3172}, {"id": 259, "name": "Kettle", "freebase_id": "/m/03s_tn", "image_count": 418, "instance_count": 562}, {"id": 260, "name": "Fireplace", "freebase_id": "/m/03tw93", "image_count": 659, "instance_count": 685}, {"id": 261, "name": "Scale", "freebase_id": "/m/03txqz", "image_count": 130, "instance_count": 138}, {"id": 262, "name": "Drinking straw", "freebase_id": "/m/03v5tg", "image_count": 140, "instance_count": 236}, {"id": 263, "name": "Insect", "freebase_id": "/m/03vt0", "image_count": 5504, "instance_count": 7494}, {"id": 264, "name": "Hair dryer", "freebase_id": "/m/03wvsk", "image_count": 27, "instance_count": 27}, {"id": 265, "name": "Kitchenware", "freebase_id": "/m/03_wxk", "image_count": 0, "instance_count": 0}, {"id": 266, "name": "Indoor rower", "freebase_id": "/m/03wym", "image_count": 12, "instance_count": 13}, {"id": 267, "name": "Invertebrate", "freebase_id": "/m/03xxp", "image_count": 684, "instance_count": 1411}, {"id": 268, "name": "Food processor", "freebase_id": "/m/03y6mg", "image_count": 119, "instance_count": 176}, {"id": 269, "name": "Bookcase", "freebase_id": "/m/03__z0", "image_count": 781, "instance_count": 1155}, {"id": 270, "name": "Refrigerator", "freebase_id": "/m/040b_t", "image_count": 467, "instance_count": 506}, {"id": 271, "name": "Wood-burning stove", "freebase_id": "/m/04169hn", "image_count": 276, "instance_count": 289}, {"id": 272, "name": "Punching bag", "freebase_id": "/m/0420v5", "image_count": 117, "instance_count": 329}, {"id": 273, "name": "Common fig", "freebase_id": "/m/043nyj", "image_count": 65, "instance_count": 212}, {"id": 274, "name": "Cocktail shaker", "freebase_id": "/m/0440zs", "image_count": 23, "instance_count": 24}, {"id": 275, "name": "Jaguar (Animal)", "freebase_id": "/m/0449p", "image_count": 410, "instance_count": 468}, {"id": 276, "name": "Golf ball", "freebase_id": "/m/044r5d", "image_count": 279, "instance_count": 338}, {"id": 277, "name": "Fashion accessory", "freebase_id": "/m/0463sg", "image_count": 19718, "instance_count": 72153}, {"id": 278, "name": "Alarm clock", "freebase_id": "/m/046dlr", "image_count": 129, "instance_count": 162}, {"id": 279, "name": "Filing cabinet", "freebase_id": "/m/047j0r", "image_count": 119, "instance_count": 143}, {"id": 280, "name": "Artichoke", "freebase_id": "/m/047v4b", "image_count": 107, "instance_count": 217}, {"id": 281, "name": "Table", "freebase_id": "/m/04bcr3", "image_count": 35125, "instance_count": 63501}, {"id": 282, "name": "Tableware", "freebase_id": "/m/04brg2", "image_count": 3477, "instance_count": 20098}, {"id": 283, "name": "Kangaroo", "freebase_id": "/m/04c0y", "image_count": 379, "instance_count": 625}, {"id": 284, "name": "Koala", "freebase_id": "/m/04cp_", "image_count": 337, "instance_count": 379}, {"id": 285, "name": "Knife", "freebase_id": "/m/04ctx", "image_count": 569, "instance_count": 781}, {"id": 286, "name": "Bottle", "freebase_id": "/m/04dr76w", "image_count": 9697, "instance_count": 24636}, {"id": 287, "name": "Bottle opener", "freebase_id": "/m/04f5ws", "image_count": 17, "instance_count": 21}, {"id": 288, "name": "Lynx", "freebase_id": "/m/04g2r", "image_count": 191, "instance_count": 204}, {"id": 289, "name": "Lavender (Plant)", "freebase_id": "/m/04gth", "image_count": 230, "instance_count": 1711}, {"id": 290, "name": "Lighthouse", "freebase_id": "/m/04h7h", "image_count": 1285, "instance_count": 1334}, {"id": 291, "name": "Dumbbell", "freebase_id": "/m/04h8sr", "image_count": 82, "instance_count": 254}, {"id": 292, "name": "Human head", "freebase_id": "/m/04hgtk", "image_count": 39752, "instance_count": 109981}, {"id": 293, "name": "Bowl", "freebase_id": "/m/04kkgm", "image_count": 1178, "instance_count": 2754}, {"id": 294, "name": "Humidifier", "freebase_id": "/m/04lvq_", "image_count": 9, "instance_count": 11}, {"id": 295, "name": "Porch", "freebase_id": "/m/04m6gz", "image_count": 1740, "instance_count": 2379}, {"id": 296, "name": "Lizard", "freebase_id": "/m/04m9y", "image_count": 1702, "instance_count": 1954}, {"id": 297, "name": "Billiard table", "freebase_id": "/m/04p0qw", "image_count": 563, "instance_count": 765}, {"id": 298, "name": "Mammal", "freebase_id": "/m/04rky", "image_count": 23173, "instance_count": 81163}, {"id": 299, "name": "Mouse", "freebase_id": "/m/04rmv", "image_count": 662, "instance_count": 797}, {"id": 300, "name": "Motorcycle", "freebase_id": "/m/04_sv", "image_count": 5325, "instance_count": 9382}, {"id": 301, "name": "Musical instrument", "freebase_id": "/m/04szw", "image_count": 4253, "instance_count": 10878}, {"id": 302, "name": "Swim cap", "freebase_id": "/m/04tn4x", "image_count": 303, "instance_count": 584}, {"id": 303, "name": "Frying pan", "freebase_id": "/m/04v6l4", "image_count": 260, "instance_count": 324}, {"id": 304, "name": "Snowplow", "freebase_id": "/m/04vv5k", "image_count": 196, "instance_count": 252}, {"id": 305, "name": "Bathroom cabinet", "freebase_id": "/m/04y4h8h", "image_count": 256, "instance_count": 277}, {"id": 306, "name": "Missile", "freebase_id": "/m/04ylt", "image_count": 420, "instance_count": 581}, {"id": 307, "name": "Bust", "freebase_id": "/m/04yqq2", "image_count": 843, "instance_count": 985}, {"id": 308, "name": "Man", "freebase_id": "/m/04yx4", "image_count": 298992, "instance_count": 958133}, {"id": 309, "name": "Waffle iron", "freebase_id": "/m/04z4wx", "image_count": 22, "instance_count": 29}, {"id": 310, "name": "Milk", "freebase_id": "/m/04zpv", "image_count": 144, "instance_count": 195}, {"id": 311, "name": "Ring binder", "freebase_id": "/m/04zwwv", "image_count": 47, "instance_count": 82}, {"id": 312, "name": "Plate", "freebase_id": "/m/050gv4", "image_count": 1643, "instance_count": 3780}, {"id": 313, "name": "Mobile phone", "freebase_id": "/m/050k8", "image_count": 4145, "instance_count": 6051}, {"id": 314, "name": "Baked goods", "freebase_id": "/m/052lwg6", "image_count": 7485, "instance_count": 14300}, {"id": 315, "name": "Mushroom", "freebase_id": "/m/052sf", "image_count": 814, "instance_count": 1951}, {"id": 316, "name": "Crutch", "freebase_id": "/m/05441v", "image_count": 74, "instance_count": 136}, {"id": 317, "name": "Pitcher (Container)", "freebase_id": "/m/054fyh", "image_count": 252, "instance_count": 303}, {"id": 318, "name": "Mirror", "freebase_id": "/m/054_l", "image_count": 971, "instance_count": 1348}, {"id": 319, "name": "Personal flotation device", "freebase_id": "/m/054xkw", "image_count": 1025, "instance_count": 2793}, {"id": 320, "name": "Table tennis racket", "freebase_id": "/m/05_5p_0", "image_count": 566, "instance_count": 815}, {"id": 321, "name": "Pencil case", "freebase_id": "/m/05676x", "image_count": 89, "instance_count": 116}, {"id": 322, "name": "Musical keyboard", "freebase_id": "/m/057cc", "image_count": 1435, "instance_count": 1682}, {"id": 323, "name": "Scoreboard", "freebase_id": "/m/057p5t", "image_count": 347, "instance_count": 376}, {"id": 324, "name": "Briefcase", "freebase_id": "/m/0584n8", "image_count": 106, "instance_count": 135}, {"id": 325, "name": "Kitchen knife", "freebase_id": "/m/058qzx", "image_count": 240, "instance_count": 300}, {"id": 326, "name": "Nail (Construction)", "freebase_id": "/m/05bm6", "image_count": 118, "instance_count": 480}, {"id": 327, "name": "Tennis ball", "freebase_id": "/m/05ctyq", "image_count": 345, "instance_count": 426}, {"id": 328, "name": "Plastic bag", "freebase_id": "/m/05gqfk", "image_count": 391, "instance_count": 682}, {"id": 329, "name": "Oboe", "freebase_id": "/m/05kms", "image_count": 86, "instance_count": 137}, {"id": 330, "name": "Chest of drawers", "freebase_id": "/m/05kyg_", "image_count": 515, "instance_count": 650}, {"id": 331, "name": "Ostrich", "freebase_id": "/m/05n4y", "image_count": 303, "instance_count": 487}, {"id": 332, "name": "Piano", "freebase_id": "/m/05r5c", "image_count": 1184, "instance_count": 1301}, {"id": 333, "name": "Girl", "freebase_id": "/m/05r655", "image_count": 72741, "instance_count": 135861}, {"id": 334, "name": "Plant", "freebase_id": "/m/05s2s", "image_count": 17891, "instance_count": 62731}, {"id": 335, "name": "Potato", "freebase_id": "/m/05vtc", "image_count": 136, "instance_count": 274}, {"id": 336, "name": "Hair spray", "freebase_id": "/m/05w9t9", "image_count": 5, "instance_count": 9}, {"id": 337, "name": "Sports equipment", "freebase_id": "/m/05y5lj", "image_count": 6388, "instance_count": 25243}, {"id": 338, "name": "Pasta", "freebase_id": "/m/05z55", "image_count": 646, "instance_count": 654}, {"id": 339, "name": "Penguin", "freebase_id": "/m/05z6w", "image_count": 768, "instance_count": 3036}, {"id": 340, "name": "Pumpkin", "freebase_id": "/m/05zsy", "image_count": 1126, "instance_count": 3110}, {"id": 341, "name": "Pear", "freebase_id": "/m/061_f", "image_count": 224, "instance_count": 653}, {"id": 342, "name": "Infant bed", "freebase_id": "/m/061hd_", "image_count": 411, "instance_count": 444}, {"id": 343, "name": "Polar bear", "freebase_id": "/m/0633h", "image_count": 471, "instance_count": 630}, {"id": 344, "name": "Mixer", "freebase_id": "/m/063rgb", "image_count": 173, "instance_count": 207}, {"id": 345, "name": "Cupboard", "freebase_id": "/m/0642b4", "image_count": 531, "instance_count": 744}, {"id": 346, "name": "Jacuzzi", "freebase_id": "/m/065h6l", "image_count": 93, "instance_count": 94}, {"id": 347, "name": "Pizza", "freebase_id": "/m/0663v", "image_count": 1122, "instance_count": 1740}, {"id": 348, "name": "Digital clock", "freebase_id": "/m/06_72j", "image_count": 168, "instance_count": 198}, {"id": 349, "name": "Pig", "freebase_id": "/m/068zj", "image_count": 638, "instance_count": 1169}, {"id": 350, "name": "Reptile", "freebase_id": "/m/06bt6", "image_count": 413, "instance_count": 498}, {"id": 351, "name": "Rifle", "freebase_id": "/m/06c54", "image_count": 1548, "instance_count": 2153}, {"id": 352, "name": "Lipstick", "freebase_id": "/m/06c7f7", "image_count": 1063, "instance_count": 1276}, {"id": 353, "name": "Skateboard", "freebase_id": "/m/06_fw", "image_count": 907, "instance_count": 1485}, {"id": 354, "name": "Raven", "freebase_id": "/m/06j2d", "image_count": 377, "instance_count": 495}, {"id": 355, "name": "High heels", "freebase_id": "/m/06k2mb", "image_count": 1451, "instance_count": 2887}, {"id": 356, "name": "Red panda", "freebase_id": "/m/06l9r", "image_count": 287, "instance_count": 356}, {"id": 357, "name": "Rose", "freebase_id": "/m/06m11", "image_count": 3674, "instance_count": 8391}, {"id": 358, "name": "Rabbit", "freebase_id": "/m/06mf6", "image_count": 972, "instance_count": 1289}, {"id": 359, "name": "Sculpture", "freebase_id": "/m/06msq", "image_count": 14266, "instance_count": 26382}, {"id": 360, "name": "Saxophone", "freebase_id": "/m/06ncr", "image_count": 746, "instance_count": 980}, {"id": 361, "name": "Shotgun", "freebase_id": "/m/06nrc", "image_count": 406, "instance_count": 543}, {"id": 362, "name": "Seafood", "freebase_id": "/m/06nwz", "image_count": 543, "instance_count": 1021}, {"id": 363, "name": "Submarine sandwich", "freebase_id": "/m/06pcq", "image_count": 192, "instance_count": 222}, {"id": 364, "name": "Snowboard", "freebase_id": "/m/06__v", "image_count": 476, "instance_count": 717}, {"id": 365, "name": "Sword", "freebase_id": "/m/06y5r", "image_count": 385, "instance_count": 552}, {"id": 366, "name": "Picture frame", "freebase_id": "/m/06z37_", "image_count": 4917, "instance_count": 10425}, {"id": 367, "name": "Sushi", "freebase_id": "/m/07030", "image_count": 258, "instance_count": 773}, {"id": 368, "name": "Loveseat", "freebase_id": "/m/0703r8", "image_count": 465, "instance_count": 577}, {"id": 369, "name": "Ski", "freebase_id": "/m/071p9", "image_count": 931, "instance_count": 2075}, {"id": 370, "name": "Squirrel", "freebase_id": "/m/071qp", "image_count": 1506, "instance_count": 1590}, {"id": 371, "name": "Tripod", "freebase_id": "/m/073bxn", "image_count": 1067, "instance_count": 1281}, {"id": 372, "name": "Stethoscope", "freebase_id": "/m/073g6", "image_count": 74, "instance_count": 77}, {"id": 373, "name": "Submarine", "freebase_id": "/m/074d1", "image_count": 74, "instance_count": 80}, {"id": 374, "name": "Scorpion", "freebase_id": "/m/0755b", "image_count": 146, "instance_count": 179}, {"id": 375, "name": "Segway", "freebase_id": "/m/076bq", "image_count": 246, "instance_count": 494}, {"id": 376, "name": "Training bench", "freebase_id": "/m/076lb9", "image_count": 81, "instance_count": 149}, {"id": 377, "name": "Snake", "freebase_id": "/m/078jl", "image_count": 1112, "instance_count": 1292}, {"id": 378, "name": "Coffee table", "freebase_id": "/m/078n6m", "image_count": 2363, "instance_count": 4217}, {"id": 379, "name": "Skyscraper", "freebase_id": "/m/079cl", "image_count": 13904, "instance_count": 48273}, {"id": 380, "name": "Sheep", "freebase_id": "/m/07bgp", "image_count": 677, "instance_count": 1950}, {"id": 381, "name": "Television", "freebase_id": "/m/07c52", "image_count": 2487, "instance_count": 3340}, {"id": 382, "name": "Trombone", "freebase_id": "/m/07c6l", "image_count": 364, "instance_count": 639}, {"id": 383, "name": "Tea", "freebase_id": "/m/07clx", "image_count": 954, "instance_count": 1181}, {"id": 384, "name": "Tank", "freebase_id": "/m/07cmd", "image_count": 873, "instance_count": 1362}, {"id": 385, "name": "Taco", "freebase_id": "/m/07crc", "image_count": 306, "instance_count": 601}, {"id": 386, "name": "Telephone", "freebase_id": "/m/07cx4", "image_count": 211, "instance_count": 261}, {"id": 387, "name": "Torch", "freebase_id": "/m/07dd4", "image_count": 18, "instance_count": 20}, {"id": 388, "name": "Tiger", "freebase_id": "/m/07dm6", "image_count": 797, "instance_count": 963}, {"id": 389, "name": "Strawberry", "freebase_id": "/m/07fbm7", "image_count": 867, "instance_count": 5729}, {"id": 390, "name": "Trumpet", "freebase_id": "/m/07gql", "image_count": 696, "instance_count": 1160}, {"id": 391, "name": "Tree", "freebase_id": "/m/07j7r", "image_count": 106636, "instance_count": 375594}, {"id": 392, "name": "Tomato", "freebase_id": "/m/07j87", "image_count": 762, "instance_count": 3783}, {"id": 393, "name": "Train", "freebase_id": "/m/07jdr", "image_count": 7263, "instance_count": 9467}, {"id": 394, "name": "Tool", "freebase_id": "/m/07k1x", "image_count": 709, "instance_count": 1617}, {"id": 395, "name": "Picnic basket", "freebase_id": "/m/07kng9", "image_count": 241, "instance_count": 348}, {"id": 396, "name": "Cooking spray", "freebase_id": "/m/07mcwg", "image_count": 9, "instance_count": 42}, {"id": 397, "name": "Trousers", "freebase_id": "/m/07mhn", "image_count": 4002, "instance_count": 6654}, {"id": 398, "name": "Bowling equipment", "freebase_id": "/m/07pj7bq", "image_count": 245, "instance_count": 743}, {"id": 399, "name": "Football helmet", "freebase_id": "/m/07qxg_", "image_count": 1269, "instance_count": 5564}, {"id": 400, "name": "Truck", "freebase_id": "/m/07r04", "image_count": 6185, "instance_count": 9046}, {"id": 401, "name": "Measuring cup", "freebase_id": "/m/07v9_z", "image_count": 64, "instance_count": 73}, {"id": 402, "name": "Coffeemaker", "freebase_id": "/m/07xyvk", "image_count": 223, "instance_count": 311}, {"id": 403, "name": "Violin", "freebase_id": "/m/07y_7", "image_count": 1195, "instance_count": 2233}, {"id": 404, "name": "Vehicle", "freebase_id": "/m/07yv9", "image_count": 10989, "instance_count": 27848}, {"id": 405, "name": "Handbag", "freebase_id": "/m/080hkjn", "image_count": 1740, "instance_count": 2248}, {"id": 406, "name": "Paper cutter", "freebase_id": "/m/080n7g", "image_count": 3, "instance_count": 4}, {"id": 407, "name": "Wine", "freebase_id": "/m/081qc", "image_count": 3951, "instance_count": 9670}, {"id": 408, "name": "Weapon", "freebase_id": "/m/083kb", "image_count": 1383, "instance_count": 2360}, {"id": 409, "name": "Wheel", "freebase_id": "/m/083wq", "image_count": 58010, "instance_count": 226764}, {"id": 410, "name": "Worm", "freebase_id": "/m/084hf", "image_count": 183, "instance_count": 242}, {"id": 411, "name": "Wok", "freebase_id": "/m/084rd", "image_count": 330, "instance_count": 511}, {"id": 412, "name": "Whale", "freebase_id": "/m/084zz", "image_count": 672, "instance_count": 909}, {"id": 413, "name": "Zebra", "freebase_id": "/m/0898b", "image_count": 351, "instance_count": 555}, {"id": 414, "name": "Auto part", "freebase_id": "/m/08dz3q", "image_count": 2539, "instance_count": 5156}, {"id": 415, "name": "Jug", "freebase_id": "/m/08hvt4", "image_count": 343, "instance_count": 500}, {"id": 416, "name": "Pizza cutter", "freebase_id": "/m/08ks85", "image_count": 19, "instance_count": 20}, {"id": 417, "name": "Cream", "freebase_id": "/m/08p92x", "image_count": 68, "instance_count": 120}, {"id": 418, "name": "Monkey", "freebase_id": "/m/08pbxl", "image_count": 1774, "instance_count": 2484}, {"id": 419, "name": "Lion", "freebase_id": "/m/096mb", "image_count": 954, "instance_count": 1276}, {"id": 420, "name": "Bread", "freebase_id": "/m/09728", "image_count": 1280, "instance_count": 2639}, {"id": 421, "name": "Platter", "freebase_id": "/m/099ssp", "image_count": 986, "instance_count": 2243}, {"id": 422, "name": "Chicken", "freebase_id": "/m/09b5t", "image_count": 1153, "instance_count": 2229}, {"id": 423, "name": "Eagle", "freebase_id": "/m/09csl", "image_count": 1391, "instance_count": 1591}, {"id": 424, "name": "Helicopter", "freebase_id": "/m/09ct_", "image_count": 2179, "instance_count": 2715}, {"id": 425, "name": "Owl", "freebase_id": "/m/09d5_", "image_count": 1212, "instance_count": 1493}, {"id": 426, "name": "Duck", "freebase_id": "/m/09ddx", "image_count": 3773, "instance_count": 10447}, {"id": 427, "name": "Turtle", "freebase_id": "/m/09dzg", "image_count": 119, "instance_count": 165}, {"id": 428, "name": "Hippopotamus", "freebase_id": "/m/09f20", "image_count": 343, "instance_count": 571}, {"id": 429, "name": "Crocodile", "freebase_id": "/m/09f_2", "image_count": 606, "instance_count": 853}, {"id": 430, "name": "Toilet", "freebase_id": "/m/09g1w", "image_count": 811, "instance_count": 1033}, {"id": 431, "name": "Toilet paper", "freebase_id": "/m/09gtd", "image_count": 195, "instance_count": 313}, {"id": 432, "name": "Squid", "freebase_id": "/m/09gys", "image_count": 78, "instance_count": 137}, {"id": 433, "name": "Clothing", "freebase_id": "/m/09j2d", "image_count": 253553, "instance_count": 937287}, {"id": 434, "name": "Footwear", "freebase_id": "/m/09j5n", "image_count": 94846, "instance_count": 484352}, {"id": 435, "name": "Lemon", "freebase_id": "/m/09k_b", "image_count": 490, "instance_count": 1182}, {"id": 436, "name": "Spider", "freebase_id": "/m/09kmb", "image_count": 1621, "instance_count": 1930}, {"id": 437, "name": "Deer", "freebase_id": "/m/09kx5", "image_count": 1353, "instance_count": 2310}, {"id": 438, "name": "Frog", "freebase_id": "/m/09ld4", "image_count": 1248, "instance_count": 1465}, {"id": 439, "name": "Banana", "freebase_id": "/m/09qck", "image_count": 358, "instance_count": 667}, {"id": 440, "name": "Rocket", "freebase_id": "/m/09rvcxw", "image_count": 622, "instance_count": 890}, {"id": 441, "name": "Wine glass", "freebase_id": "/m/09tvcd", "image_count": 4101, "instance_count": 10326}, {"id": 442, "name": "Countertop", "freebase_id": "/m/0b3fp9", "image_count": 1608, "instance_count": 2240}, {"id": 443, "name": "Tablet computer", "freebase_id": "/m/0bh9flk", "image_count": 756, "instance_count": 936}, {"id": 444, "name": "Waste container", "freebase_id": "/m/0bjyj5", "image_count": 853, "instance_count": 1474}, {"id": 445, "name": "Swimming pool", "freebase_id": "/m/0b_rs", "image_count": 2872, "instance_count": 3057}, {"id": 446, "name": "Dog", "freebase_id": "/m/0bt9lr", "image_count": 18057, "instance_count": 24721}, {"id": 447, "name": "Book", "freebase_id": "/m/0bt_c3", "image_count": 3640, "instance_count": 7698}, {"id": 448, "name": "Elephant", "freebase_id": "/m/0bwd_0j", "image_count": 1225, "instance_count": 2263}, {"id": 449, "name": "Shark", "freebase_id": "/m/0by6g", "image_count": 486, "instance_count": 613}, {"id": 450, "name": "Candle", "freebase_id": "/m/0c06p", "image_count": 1005, "instance_count": 4531}, {"id": 451, "name": "Leopard", "freebase_id": "/m/0c29q", "image_count": 534, "instance_count": 613}, {"id": 452, "name": "Axe", "freebase_id": "/m/0c2jj", "image_count": 112, "instance_count": 145}, {"id": 453, "name": "Hand dryer", "freebase_id": "/m/0c3m8g", "image_count": 56, "instance_count": 70}, {"id": 454, "name": "Soap dispenser", "freebase_id": "/m/0c3mkw", "image_count": 58, "instance_count": 78}, {"id": 455, "name": "Porcupine", "freebase_id": "/m/0c568", "image_count": 182, "instance_count": 205}, {"id": 456, "name": "Flower", "freebase_id": "/m/0c9ph5", "image_count": 29498, "instance_count": 125304}, {"id": 457, "name": "Canary", "freebase_id": "/m/0ccs93", "image_count": 206, "instance_count": 322}, {"id": 458, "name": "Cheetah", "freebase_id": "/m/0cd4d", "image_count": 424, "instance_count": 533}, {"id": 459, "name": "Palm tree", "freebase_id": "/m/0cdl1", "image_count": 7987, "instance_count": 31443}, {"id": 460, "name": "Hamburger", "freebase_id": "/m/0cdn1", "image_count": 624, "instance_count": 835}, {"id": 461, "name": "Maple", "freebase_id": "/m/0cffdh", "image_count": 1628, "instance_count": 3515}, {"id": 462, "name": "Building", "freebase_id": "/m/0cgh4", "image_count": 64125, "instance_count": 102491}, {"id": 463, "name": "Fish", "freebase_id": "/m/0ch_cf", "image_count": 4327, "instance_count": 14862}, {"id": 464, "name": "Lobster", "freebase_id": "/m/0cjq5", "image_count": 261, "instance_count": 384}, {"id": 465, "name": "Garden Asparagus", "freebase_id": "/m/0cjs7", "image_count": 59, "instance_count": 84}, {"id": 466, "name": "Furniture", "freebase_id": "/m/0c_jw", "image_count": 11135, "instance_count": 27884}, {"id": 467, "name": "Hedgehog", "freebase_id": "/m/0cl4p", "image_count": 213, "instance_count": 235}, {"id": 468, "name": "Airplane", "freebase_id": "/m/0cmf2", "image_count": 11295, "instance_count": 19823}, {"id": 469, "name": "Spoon", "freebase_id": "/m/0cmx8", "image_count": 913, "instance_count": 1435}, {"id": 470, "name": "Otter", "freebase_id": "/m/0cn6p", "image_count": 439, "instance_count": 661}, {"id": 471, "name": "Bull", "freebase_id": "/m/0cnyhnx", "image_count": 829, "instance_count": 1187}, {"id": 472, "name": "Oyster", "freebase_id": "/m/0_cp5", "image_count": 235, "instance_count": 603}, {"id": 473, "name": "Horizontal bar", "freebase_id": "/m/0cqn2", "image_count": 48, "instance_count": 64}, {"id": 474, "name": "Convenience store", "freebase_id": "/m/0crjs", "image_count": 1233, "instance_count": 1240}, {"id": 475, "name": "Bomb", "freebase_id": "/m/0ct4f", "image_count": 6, "instance_count": 8}, {"id": 476, "name": "Bench", "freebase_id": "/m/0cvnqh", "image_count": 2085, "instance_count": 3801}, {"id": 477, "name": "Ice cream", "freebase_id": "/m/0cxn2", "image_count": 1331, "instance_count": 2451}, {"id": 478, "name": "Caterpillar", "freebase_id": "/m/0cydv", "image_count": 622, "instance_count": 779}, {"id": 479, "name": "Butterfly", "freebase_id": "/m/0cyf8", "image_count": 3871, "instance_count": 8739}, {"id": 480, "name": "Parachute", "freebase_id": "/m/0cyfs", "image_count": 974, "instance_count": 2342}, {"id": 481, "name": "Orange", "freebase_id": "/m/0cyhj_", "image_count": 653, "instance_count": 3820}, {"id": 482, "name": "Antelope", "freebase_id": "/m/0czz2", "image_count": 602, "instance_count": 1074}, {"id": 483, "name": "Beaker", "freebase_id": "/m/0d20w4", "image_count": 84, "instance_count": 165}, {"id": 484, "name": "Moths and butterflies", "freebase_id": "/m/0d_2m", "image_count": 1650, "instance_count": 1805}, {"id": 485, "name": "Window", "freebase_id": "/m/0d4v4", "image_count": 42733, "instance_count": 306327}, {"id": 486, "name": "Closet", "freebase_id": "/m/0d4w1", "image_count": 259, "instance_count": 452}, {"id": 487, "name": "Castle", "freebase_id": "/m/0d5gx", "image_count": 2649, "instance_count": 2987}, {"id": 488, "name": "Jellyfish", "freebase_id": "/m/0d8zb", "image_count": 632, "instance_count": 1626}, {"id": 489, "name": "Goose", "freebase_id": "/m/0dbvp", "image_count": 2052, "instance_count": 5910}, {"id": 490, "name": "Mule", "freebase_id": "/m/0dbzx", "image_count": 427, "instance_count": 770}, {"id": 491, "name": "Swan", "freebase_id": "/m/0dftk", "image_count": 1105, "instance_count": 2985}, {"id": 492, "name": "Peach", "freebase_id": "/m/0dj6p", "image_count": 86, "instance_count": 333}, {"id": 493, "name": "Coconut", "freebase_id": "/m/0djtd", "image_count": 81, "instance_count": 165}, {"id": 494, "name": "Seat belt", "freebase_id": "/m/0dkzw", "image_count": 311, "instance_count": 451}, {"id": 495, "name": "Raccoon", "freebase_id": "/m/0dq75", "image_count": 278, "instance_count": 336}, {"id": 496, "name": "Chisel", "freebase_id": "/m/0_dqb", "image_count": 20, "instance_count": 25}, {"id": 497, "name": "Fork", "freebase_id": "/m/0dt3t", "image_count": 885, "instance_count": 1442}, {"id": 498, "name": "Lamp", "freebase_id": "/m/0dtln", "image_count": 1420, "instance_count": 2912}, {"id": 499, "name": "Camera", "freebase_id": "/m/0dv5r", "image_count": 4726, "instance_count": 5933}, {"id": 500, "name": "Squash (Plant)", "freebase_id": "/m/0dv77", "image_count": 76, "instance_count": 157}, {"id": 501, "name": "Racket", "freebase_id": "/m/0dv9c", "image_count": 201, "instance_count": 236}, {"id": 502, "name": "Human face", "freebase_id": "/m/0dzct", "image_count": 286554, "instance_count": 762660}, {"id": 503, "name": "Human arm", "freebase_id": "/m/0dzf4", "image_count": 32749, "instance_count": 130607}, {"id": 504, "name": "Vegetable", "freebase_id": "/m/0f4s2w", "image_count": 1321, "instance_count": 4748}, {"id": 505, "name": "Diaper", "freebase_id": "/m/0f571", "image_count": 110, "instance_count": 146}, {"id": 506, "name": "Unicycle", "freebase_id": "/m/0f6nr", "image_count": 115, "instance_count": 159}, {"id": 507, "name": "Falcon", "freebase_id": "/m/0f6wt", "image_count": 1417, "instance_count": 1622}, {"id": 508, "name": "Chime", "freebase_id": "/m/0f8s22", "image_count": 21, "instance_count": 31}, {"id": 509, "name": "Snail", "freebase_id": "/m/0f9_l", "image_count": 552, "instance_count": 805}, {"id": 510, "name": "Shellfish", "freebase_id": "/m/0fbdv", "image_count": 245, "instance_count": 870}, {"id": 511, "name": "Cabbage", "freebase_id": "/m/0fbw6", "image_count": 98, "instance_count": 163}, {"id": 512, "name": "Carrot", "freebase_id": "/m/0fj52s", "image_count": 286, "instance_count": 699}, {"id": 513, "name": "Mango", "freebase_id": "/m/0fldg", "image_count": 57, "instance_count": 212}, {"id": 514, "name": "Jeans", "freebase_id": "/m/0fly7", "image_count": 24202, "instance_count": 56204}, {"id": 515, "name": "Flowerpot", "freebase_id": "/m/0fm3zh", "image_count": 4107, "instance_count": 9921}, {"id": 516, "name": "Pineapple", "freebase_id": "/m/0fp6w", "image_count": 230, "instance_count": 493}, {"id": 517, "name": "Drawer", "freebase_id": "/m/0fqfqc", "image_count": 617, "instance_count": 1892}, {"id": 518, "name": "Stool", "freebase_id": "/m/0fqt361", "image_count": 492, "instance_count": 1070}, {"id": 519, "name": "Envelope", "freebase_id": "/m/0frqm", "image_count": 116, "instance_count": 170}, {"id": 520, "name": "Cake", "freebase_id": "/m/0fszt", "image_count": 3076, "instance_count": 4100}, {"id": 521, "name": "Dragonfly", "freebase_id": "/m/0ft9s", "image_count": 1221, "instance_count": 1336}, {"id": 522, "name": "Common sunflower", "freebase_id": "/m/0ftb8", "image_count": 1419, "instance_count": 5807}, {"id": 523, "name": "Microwave oven", "freebase_id": "/m/0fx9l", "image_count": 337, "instance_count": 379}, {"id": 524, "name": "Honeycomb", "freebase_id": "/m/0fz0h", "image_count": 253, "instance_count": 272}, {"id": 525, "name": "Marine mammal", "freebase_id": "/m/0gd2v", "image_count": 873, "instance_count": 1428}, {"id": 526, "name": "Sea lion", "freebase_id": "/m/0gd36", "image_count": 737, "instance_count": 1406}, {"id": 527, "name": "Ladybug", "freebase_id": "/m/0gj37", "image_count": 519, "instance_count": 646}, {"id": 528, "name": "Shelf", "freebase_id": "/m/0gjbg72", "image_count": 2888, "instance_count": 9423}, {"id": 529, "name": "Watch", "freebase_id": "/m/0gjkl", "image_count": 1410, "instance_count": 1868}, {"id": 530, "name": "Candy", "freebase_id": "/m/0gm28", "image_count": 437, "instance_count": 1046}, {"id": 531, "name": "Salad", "freebase_id": "/m/0grw1", "image_count": 2241, "instance_count": 2576}, {"id": 532, "name": "Parrot", "freebase_id": "/m/0gv1x", "image_count": 1251, "instance_count": 1985}, {"id": 533, "name": "Handgun", "freebase_id": "/m/0gxl3", "image_count": 555, "instance_count": 710}, {"id": 534, "name": "Sparrow", "freebase_id": "/m/0h23m", "image_count": 1034, "instance_count": 1470}, {"id": 535, "name": "Van", "freebase_id": "/m/0h2r6", "image_count": 4349, "instance_count": 6200}, {"id": 536, "name": "Grinder", "freebase_id": "/m/0h8jyh6", "image_count": 10, "instance_count": 13}, {"id": 537, "name": "Spice rack", "freebase_id": "/m/0h8kx63", "image_count": 53, "instance_count": 105}, {"id": 538, "name": "Light bulb", "freebase_id": "/m/0h8l4fh", "image_count": 406, "instance_count": 1506}, {"id": 539, "name": "Corded phone", "freebase_id": "/m/0h8lkj8", "image_count": 344, "instance_count": 425}, {"id": 540, "name": "Sports uniform", "freebase_id": "/m/0h8mhzd", "image_count": 5416, "instance_count": 14241}, {"id": 541, "name": "Tennis racket", "freebase_id": "/m/0h8my_4", "image_count": 763, "instance_count": 884}, {"id": 542, "name": "Wall clock", "freebase_id": "/m/0h8mzrc", "image_count": 811, "instance_count": 983}, {"id": 543, "name": "Serving tray", "freebase_id": "/m/0h8n27j", "image_count": 99, "instance_count": 107}, {"id": 544, "name": "Kitchen & dining room table", "freebase_id": "/m/0h8n5zk", "image_count": 1495, "instance_count": 1597}, {"id": 545, "name": "Dog bed", "freebase_id": "/m/0h8n6f9", "image_count": 229, "instance_count": 253}, {"id": 546, "name": "Cake stand", "freebase_id": "/m/0h8n6ft", "image_count": 203, "instance_count": 276}, {"id": 547, "name": "Cat furniture", "freebase_id": "/m/0h8nm9j", "image_count": 180, "instance_count": 202}, {"id": 548, "name": "Bathroom accessory", "freebase_id": "/m/0h8nr_l", "image_count": 639, "instance_count": 2247}, {"id": 549, "name": "Facial tissue holder", "freebase_id": "/m/0h8nsvg", "image_count": 18, "instance_count": 19}, {"id": 550, "name": "Pressure cooker", "freebase_id": "/m/0h8ntjv", "image_count": 13, "instance_count": 14}, {"id": 551, "name": "Kitchen appliance", "freebase_id": "/m/0h99cwc", "image_count": 928, "instance_count": 3552}, {"id": 552, "name": "Tire", "freebase_id": "/m/0h9mv", "image_count": 23939, "instance_count": 83517}, {"id": 553, "name": "Ruler", "freebase_id": "/m/0hdln", "image_count": 230, "instance_count": 245}, {"id": 554, "name": "Luggage and bags", "freebase_id": "/m/0hf58v5", "image_count": 801, "instance_count": 1774}, {"id": 555, "name": "Microphone", "freebase_id": "/m/0hg7b", "image_count": 19830, "instance_count": 26336}, {"id": 556, "name": "Broccoli", "freebase_id": "/m/0hkxq", "image_count": 222, "instance_count": 712}, {"id": 557, "name": "Umbrella", "freebase_id": "/m/0hnnb", "image_count": 2273, "instance_count": 4705}, {"id": 558, "name": "Pastry", "freebase_id": "/m/0hnyx", "image_count": 642, "instance_count": 2094}, {"id": 559, "name": "Grapefruit", "freebase_id": "/m/0hqkz", "image_count": 297, "instance_count": 768}, {"id": 560, "name": "Band-aid", "freebase_id": "/m/0j496", "image_count": 20, "instance_count": 36}, {"id": 561, "name": "Animal", "freebase_id": "/m/0jbk", "image_count": 7214, "instance_count": 12475}, {"id": 562, "name": "Bell pepper", "freebase_id": "/m/0jg57", "image_count": 198, "instance_count": 490}, {"id": 563, "name": "Turkey", "freebase_id": "/m/0jly1", "image_count": 290, "instance_count": 570}, {"id": 564, "name": "Lily", "freebase_id": "/m/0jqgx", "image_count": 863, "instance_count": 1678}, {"id": 565, "name": "Pomegranate", "freebase_id": "/m/0jwn_", "image_count": 159, "instance_count": 343}, {"id": 566, "name": "Doughnut", "freebase_id": "/m/0jy4k", "image_count": 241, "instance_count": 552}, {"id": 567, "name": "Glasses", "freebase_id": "/m/0jyfg", "image_count": 38197, "instance_count": 50948}, {"id": 568, "name": "Human nose", "freebase_id": "/m/0k0pj", "image_count": 24508, "instance_count": 43663}, {"id": 569, "name": "Pen", "freebase_id": "/m/0k1tl", "image_count": 926, "instance_count": 1492}, {"id": 570, "name": "Ant", "freebase_id": "/m/0_k2", "image_count": 327, "instance_count": 784}, {"id": 571, "name": "Car", "freebase_id": "/m/0k4j", "image_count": 63478, "instance_count": 164003}, {"id": 572, "name": "Aircraft", "freebase_id": "/m/0k5j", "image_count": 1039, "instance_count": 1615}, {"id": 573, "name": "Human hand", "freebase_id": "/m/0k65p", "image_count": 18436, "instance_count": 51215}, {"id": 574, "name": "Skunk", "freebase_id": "/m/0km7z", "image_count": 36, "instance_count": 51}, {"id": 575, "name": "Teddy bear", "freebase_id": "/m/0kmg4", "image_count": 926, "instance_count": 1401}, {"id": 576, "name": "Watermelon", "freebase_id": "/m/0kpqd", "image_count": 255, "instance_count": 551}, {"id": 577, "name": "Cantaloupe", "freebase_id": "/m/0kpt_", "image_count": 69, "instance_count": 114}, {"id": 578, "name": "Dishwasher", "freebase_id": "/m/0ky7b", "image_count": 72, "instance_count": 74}, {"id": 579, "name": "Flute", "freebase_id": "/m/0l14j_", "image_count": 228, "instance_count": 340}, {"id": 580, "name": "Balance beam", "freebase_id": "/m/0l3ms", "image_count": 247, "instance_count": 309}, {"id": 581, "name": "Sandwich", "freebase_id": "/m/0l515", "image_count": 576, "instance_count": 831}, {"id": 582, "name": "Shrimp", "freebase_id": "/m/0ll1f78", "image_count": 373, "instance_count": 1344}, {"id": 583, "name": "Sewing machine", "freebase_id": "/m/0llzx", "image_count": 351, "instance_count": 425}, {"id": 584, "name": "Binoculars", "freebase_id": "/m/0lt4_", "image_count": 101, "instance_count": 115}, {"id": 585, "name": "Rays and skates", "freebase_id": "/m/0m53l", "image_count": 319, "instance_count": 479}, {"id": 586, "name": "Ipod", "freebase_id": "/m/0mcx2", "image_count": 403, "instance_count": 570}, {"id": 587, "name": "Accordion", "freebase_id": "/m/0mkg", "image_count": 774, "instance_count": 862}, {"id": 588, "name": "Willow", "freebase_id": "/m/0mw_6", "image_count": 26, "instance_count": 43}, {"id": 589, "name": "Crab", "freebase_id": "/m/0n28_", "image_count": 616, "instance_count": 828}, {"id": 590, "name": "Crown", "freebase_id": "/m/0nl46", "image_count": 514, "instance_count": 612}, {"id": 591, "name": "Seahorse", "freebase_id": "/m/0nybt", "image_count": 219, "instance_count": 284}, {"id": 592, "name": "Perfume", "freebase_id": "/m/0p833", "image_count": 193, "instance_count": 304}, {"id": 593, "name": "Alpaca", "freebase_id": "/m/0pcr", "image_count": 351, "instance_count": 593}, {"id": 594, "name": "Taxi", "freebase_id": "/m/0pg52", "image_count": 951, "instance_count": 2491}, {"id": 595, "name": "Canoe", "freebase_id": "/m/0ph39", "image_count": 1439, "instance_count": 2881}, {"id": 596, "name": "Remote control", "freebase_id": "/m/0qjjc", "image_count": 183, "instance_count": 221}, {"id": 597, "name": "Wheelchair", "freebase_id": "/m/0qmmr", "image_count": 737, "instance_count": 1181}, {"id": 598, "name": "Rugby ball", "freebase_id": "/m/0wdt60w", "image_count": 225, "instance_count": 244}, {"id": 599, "name": "Armadillo", "freebase_id": "/m/0xfy", "image_count": 42, "instance_count": 54}, {"id": 600, "name": "Maracas", "freebase_id": "/m/0xzly", "image_count": 3, "instance_count": 5}, {"id": 601, "name": "Helmet", "freebase_id": "/m/0zvk5", "image_count": 6360, "instance_count": 11798}]# fmt: on12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217import os
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets import load_sem_seg
from .coco import custom_register_coco_instances
PASCAL_CTX_59_CATEGORIES = [ {"color": [180, 120, 120], "id": 0, "isthing": 0, "name": "aeroplane"}, {"color": [6, 230, 230], "id": 1, "isthing": 0, "name": "bag"}, {"color": [80, 50, 50], "id": 2, "isthing": 0, "name": "bed"}, {"color": [4, 200, 3], "id": 3, "isthing": 0, "name": "bedclothes"}, {"color": [120, 120, 80], "id": 4, "isthing": 0, "name": "bench"}, {"color": [140, 140, 140], "id": 5, "isthing": 0, "name": "bicycle"}, {"color": [204, 5, 255], "id": 6, "isthing": 0, "name": "bird"}, {"color": [230, 230, 230], "id": 7, "isthing": 0, "name": "boat"}, {"color": [4, 250, 7], "id": 8, "isthing": 0, "name": "book"}, {"color": [224, 5, 255], "id": 9, "isthing": 0, "name": "bottle"}, {"color": [235, 255, 7], "id": 10, "isthing": 0, "name": "building"}, {"color": [150, 5, 61], "id": 11, "isthing": 0, "name": "bus"}, {"color": [120, 120, 70], "id": 12, "isthing": 0, "name": "cabinet"}, {"color": [8, 255, 51], "id": 13, "isthing": 0, "name": "car"}, {"color": [255, 6, 82], "id": 14, "isthing": 0, "name": "cat"}, {"color": [143, 255, 140], "id": 15, "isthing": 0, "name": "ceiling"}, {"color": [204, 255, 4], "id": 16, "isthing": 0, "name": "chair"}, {"color": [255, 51, 7], "id": 17, "isthing": 0, "name": "cloth"}, {"color": [204, 70, 3], "id": 18, "isthing": 0, "name": "computer"}, {"color": [0, 102, 200], "id": 19, "isthing": 0, "name": "cow"}, {"color": [61, 230, 250], "id": 20, "isthing": 0, "name": "cup"}, {"color": [255, 6, 51], "id": 21, "isthing": 0, "name": "curtain"}, {"color": [11, 102, 255], "id": 22, "isthing": 0, "name": "dog"}, {"color": [255, 7, 71], "id": 23, "isthing": 0, "name": "door"}, {"color": [255, 9, 224], "id": 24, "isthing": 0, "name": "fence"}, {"color": [9, 7, 230], "id": 25, "isthing": 0, "name": "floor"}, {"color": [220, 220, 220], "id": 26, "isthing": 0, "name": "flower"}, {"color": [255, 9, 92], "id": 27, "isthing": 0, "name": "food"}, {"color": [112, 9, 255], "id": 28, "isthing": 0, "name": "grass"}, {"color": [8, 255, 214], "id": 29, "isthing": 0, "name": "ground"}, {"color": [7, 255, 224], "id": 30, "isthing": 0, "name": "horse"}, {"color": [255, 184, 6], "id": 31, "isthing": 0, "name": "keyboard"}, {"color": [10, 255, 71], "id": 32, "isthing": 0, "name": "light"}, {"color": [255, 41, 10], "id": 33, "isthing": 0, "name": "motorbike"}, {"color": [7, 255, 255], "id": 34, "isthing": 0, "name": "mountain"}, {"color": [224, 255, 8], "id": 35, "isthing": 0, "name": "mouse"}, {"color": [102, 8, 255], "id": 36, "isthing": 0, "name": "person"}, {"color": [255, 61, 6], "id": 37, "isthing": 0, "name": "plate"}, {"color": [255, 194, 7], "id": 38, "isthing": 0, "name": "platform"}, {"color": [255, 122, 8], "id": 39, "isthing": 0, "name": "pottedplant"}, {"color": [0, 255, 20], "id": 40, "isthing": 0, "name": "road"}, {"color": [255, 8, 41], "id": 41, "isthing": 0, "name": "rock"}, {"color": [255, 5, 153], "id": 42, "isthing": 0, "name": "sheep"}, {"color": [6, 51, 255], "id": 43, "isthing": 0, "name": "shelves"}, {"color": [235, 12, 255], "id": 44, "isthing": 0, "name": "sidewalk"}, {"color": [160, 150, 20], "id": 45, "isthing": 0, "name": "sign"}, {"color": [0, 163, 255], "id": 46, "isthing": 0, "name": "sky"}, {"color": [140, 140, 140], "id": 47, "isthing": 0, "name": "snow"}, {"color": [250, 10, 15], "id": 48, "isthing": 0, "name": "sofa"}, {"color": [20, 255, 0], "id": 49, "isthing": 0, "name": "diningtable"}, {"color": [31, 255, 0], "id": 50, "isthing": 0, "name": "track"}, {"color": [255, 31, 0], "id": 51, "isthing": 0, "name": "train"}, {"color": [255, 224, 0], "id": 52, "isthing": 0, "name": "tree"}, {"color": [153, 255, 0], "id": 53, "isthing": 0, "name": "truck"}, {"color": [0, 0, 255], "id": 54, "isthing": 0, "name": "tvmonitor"}, {"color": [255, 71, 0], "id": 55, "isthing": 0, "name": "wall"}, {"color": [0, 235, 255], "id": 56, "isthing": 0, "name": "water"}, {"color": [0, 173, 255], "id": 57, "isthing": 0, "name": "window"}, {"color": [31, 0, 255], "id": 58, "isthing": 0, "name": "wood"},]
PASCAL_CTX_459_CATEGORIES = [ {"color": [120, 120, 120], "id": 0, "isthing": 0, "name": "accordion"}, {"color": [180, 120, 120], "id": 1, "isthing": 0, "name": "aeroplane"}, {"color": [6, 230, 230], "id": 2, "isthing": 0, "name": "air conditioner"}, {"color": [80, 50, 50], "id": 3, "isthing": 0, "name": "antenna"}, {"color": [4, 200, 3], "id": 4, "isthing": 0, "name": "artillery"}, {"color": [120, 120, 80], "id": 5, "isthing": 0, "name": "ashtray"}, {"color": [140, 140, 140], "id": 6, "isthing": 0, "name": "atrium"}, {"color": [204, 5, 255], "id": 7, "isthing": 0, "name": "baby carriage"}, {"color": [230, 230, 230], "id": 8, "isthing": 0, "name": "bag"}, {"color": [4, 250, 7], "id": 9, "isthing": 0, "name": "ball"}, {"color": [224, 5, 255], "id": 10, "isthing": 0, "name": "balloon"}, {"color": [235, 255, 7], "id": 11, "isthing": 0, "name": "bamboo weaving"}, {"color": [150, 5, 61], "id": 12, "isthing": 0, "name": "barrel"}, {"color": [120, 120, 70], "id": 13, "isthing": 0, "name": "baseball bat"}, {"color": [8, 255, 51], "id": 14, "isthing": 0, "name": "basket"}, {"color": [255, 6, 82], "id": 15, "isthing": 0, "name": "basketball backboard"}, {"color": [143, 255, 140], "id": 16, "isthing": 0, "name": "bathtub"}, {"color": [204, 255, 4], "id": 17, "isthing": 0, "name": "bed"}, {"color": [255, 51, 7], "id": 18, "isthing": 0, "name": "bedclothes"}, {"color": [204, 70, 3], "id": 19, "isthing": 0, "name": "beer"}, {"color": [0, 102, 200], "id": 20, "isthing": 0, "name": "bell"}, {"color": [61, 230, 250], "id": 21, "isthing": 0, "name": "bench"}, {"color": [255, 6, 51], "id": 22, "isthing": 0, "name": "bicycle"}, {"color": [11, 102, 255], "id": 23, "isthing": 0, "name": "binoculars"}, {"color": [255, 7, 71], "id": 24, "isthing": 0, "name": "bird"}, {"color": [255, 9, 224], "id": 25, "isthing": 0, "name": "bird cage"}, {"color": [9, 7, 230], "id": 26, "isthing": 0, "name": "bird feeder"}, {"color": [220, 220, 220], "id": 27, "isthing": 0, "name": "bird nest"}, {"color": [255, 9, 92], "id": 28, "isthing": 0, "name": "blackboard"}, {"color": [112, 9, 255], "id": 29, "isthing": 0, "name": "board"}, {"color": [8, 255, 214], "id": 30, "isthing": 0, "name": "boat"}, {"color": [7, 255, 224], "id": 31, "isthing": 0, "name": "bone"}, {"color": [255, 184, 6], "id": 32, "isthing": 0, "name": "book"}, {"color": [10, 255, 71], "id": 33, "isthing": 0, "name": "bottle"}, {"color": [255, 41, 10], "id": 34, "isthing": 0, "name": "bottle opener"}, {"color": [7, 255, 255], "id": 35, "isthing": 0, "name": "bowl"}, {"color": [224, 255, 8], "id": 36, "isthing": 0, "name": "box"}, {"color": [102, 8, 255], "id": 37, "isthing": 0, "name": "bracelet"}, {"color": [255, 61, 6], "id": 38, "isthing": 0, "name": "brick"}, {"color": [255, 194, 7], "id": 39, "isthing": 0, "name": "bridge"}, {"color": [255, 122, 8], "id": 40, "isthing": 0, "name": "broom"}, {"color": [0, 255, 20], "id": 41, "isthing": 0, "name": "brush"}, {"color": [255, 8, 41], "id": 42, "isthing": 0, "name": "bucket"}, {"color": [255, 5, 153], "id": 43, "isthing": 0, "name": "building"}, {"color": [6, 51, 255], "id": 44, "isthing": 0, "name": "bus"}, {"color": [235, 12, 255], "id": 45, "isthing": 0, "name": "cabinet"}, {"color": [160, 150, 20], "id": 46, "isthing": 0, "name": "cabinet door"}, {"color": [0, 163, 255], "id": 47, "isthing": 0, "name": "cage"}, {"color": [140, 140, 140], "id": 48, "isthing": 0, "name": "cake"}, {"color": [250, 10, 15], "id": 49, "isthing": 0, "name": "calculator"}, {"color": [20, 255, 0], "id": 50, "isthing": 0, "name": "calendar"}, {"color": [31, 255, 0], "id": 51, "isthing": 0, "name": "camel"}, {"color": [255, 31, 0], "id": 52, "isthing": 0, "name": "camera"}, {"color": [255, 224, 0], "id": 53, "isthing": 0, "name": "camera lens"}, {"color": [153, 255, 0], "id": 54, "isthing": 0, "name": "can"}, {"color": [0, 0, 255], "id": 55, "isthing": 0, "name": "candle"}, {"color": [255, 71, 0], "id": 56, "isthing": 0, "name": "candle holder"}, {"color": [0, 235, 255], "id": 57, "isthing": 0, "name": "cap"}, {"color": [0, 173, 255], "id": 58, "isthing": 0, "name": "car"}, {"color": [31, 0, 255], "id": 59, "isthing": 0, "name": "card"}, {"color": [120, 120, 120], "id": 60, "isthing": 0, "name": "cart"}, {"color": [180, 120, 120], "id": 61, "isthing": 0, "name": "case"}, {"color": [6, 230, 230], "id": 62, "isthing": 0, "name": "casette recorder"}, {"color": [80, 50, 50], "id": 63, "isthing": 0, "name": "cash register"}, {"color": [4, 200, 3], "id": 64, "isthing": 0, "name": "cat"}, {"color": [120, 120, 80], "id": 65, "isthing": 0, "name": "cd"}, {"color": [140, 140, 140], "id": 66, "isthing": 0, "name": "cd player"}, {"color": [204, 5, 255], "id": 67, "isthing": 0, "name": "ceiling"}, {"color": [230, 230, 230], "id": 68, "isthing": 0, "name": "cell phone"}, {"color": [4, 250, 7], "id": 69, "isthing": 0, "name": "cello"}, {"color": [224, 5, 255], "id": 70, "isthing": 0, "name": "chain"}, {"color": [235, 255, 7], "id": 71, "isthing": 0, "name": "chair"}, {"color": [150, 5, 61], "id": 72, "isthing": 0, "name": "chessboard"}, {"color": [120, 120, 70], "id": 73, "isthing": 0, "name": "chicken"}, {"color": [8, 255, 51], "id": 74, "isthing": 0, "name": "chopstick"}, {"color": [255, 6, 82], "id": 75, "isthing": 0, "name": "clip"}, {"color": [143, 255, 140], "id": 76, "isthing": 0, "name": "clippers"}, {"color": [204, 255, 4], "id": 77, "isthing": 0, "name": "clock"}, {"color": [255, 51, 7], "id": 78, "isthing": 0, "name": "closet"}, {"color": [204, 70, 3], "id": 79, "isthing": 0, "name": "cloth"}, {"color": [0, 102, 200], "id": 80, "isthing": 0, "name": "clothes tree"}, {"color": [61, 230, 250], "id": 81, "isthing": 0, "name": "coffee"}, {"color": [255, 6, 51], "id": 82, "isthing": 0, "name": "coffee machine"}, {"color": [11, 102, 255], "id": 83, "isthing": 0, "name": "comb"}, {"color": [255, 7, 71], "id": 84, "isthing": 0, "name": "computer"}, {"color": [255, 9, 224], "id": 85, "isthing": 0, "name": "concrete"}, {"color": [9, 7, 230], "id": 86, "isthing": 0, "name": "cone"}, {"color": [220, 220, 220], "id": 87, "isthing": 0, "name": "container"}, {"color": [255, 9, 92], "id": 88, "isthing": 0, "name": "control booth"}, {"color": [112, 9, 255], "id": 89, "isthing": 0, "name": "controller"}, {"color": [8, 255, 214], "id": 90, "isthing": 0, "name": "cooker"}, {"color": [7, 255, 224], "id": 91, "isthing": 0, "name": "copying machine"}, {"color": [255, 184, 6], "id": 92, "isthing": 0, "name": "coral"}, {"color": [10, 255, 71], "id": 93, "isthing": 0, "name": "cork"}, {"color": [255, 41, 10], "id": 94, "isthing": 0, "name": "corkscrew"}, {"color": [7, 255, 255], "id": 95, "isthing": 0, "name": "counter"}, {"color": [224, 255, 8], "id": 96, "isthing": 0, "name": "court"}, {"color": [102, 8, 255], "id": 97, "isthing": 0, "name": "cow"}, {"color": [255, 61, 6], "id": 98, "isthing": 0, "name": "crabstick"}, {"color": [255, 194, 7], "id": 99, "isthing": 0, "name": "crane"}, {"color": [255, 122, 8], "id": 100, "isthing": 0, "name": "crate"}, {"color": [0, 255, 20], "id": 101, "isthing": 0, "name": "cross"}, {"color": [255, 8, 41], "id": 102, "isthing": 0, "name": "crutch"}, {"color": [255, 5, 153], "id": 103, "isthing": 0, "name": "cup"}, {"color": [6, 51, 255], "id": 104, "isthing": 0, "name": "curtain"}, {"color": [235, 12, 255], "id": 105, "isthing": 0, "name": "cushion"}, {"color": [160, 150, 20], "id": 106, "isthing": 0, "name": "cutting board"}, {"color": [0, 163, 255], "id": 107, "isthing": 0, "name": "dais"}, {"color": [140, 140, 140], "id": 108, "isthing": 0, "name": "disc"}, {"color": [250, 10, 15], "id": 109, "isthing": 0, "name": "disc case"}, {"color": [20, 255, 0], "id": 110, "isthing": 0, "name": "dishwasher"}, {"color": [31, 255, 0], "id": 111, "isthing": 0, "name": "dock"}, {"color": [255, 31, 0], "id": 112, "isthing": 0, "name": "dog"}, {"color": [255, 224, 0], "id": 113, "isthing": 0, "name": "dolphin"}, {"color": [153, 255, 0], "id": 114, "isthing": 0, "name": "door"}, {"color": [0, 0, 255], "id": 115, "isthing": 0, "name": "drainer"}, {"color": [255, 71, 0], "id": 116, "isthing": 0, "name": "dray"}, {"color": [0, 235, 255], "id": 117, "isthing": 0, "name": "drink dispenser"}, {"color": [0, 173, 255], "id": 118, "isthing": 0, "name": "drinking machine"}, {"color": [31, 0, 255], "id": 119, "isthing": 0, "name": "drop"}, {"color": [120, 120, 120], "id": 120, "isthing": 0, "name": "drug"}, {"color": [180, 120, 120], "id": 121, "isthing": 0, "name": "drum"}, {"color": [6, 230, 230], "id": 122, "isthing": 0, "name": "drum kit"}, {"color": [80, 50, 50], "id": 123, "isthing": 0, "name": "duck"}, {"color": [4, 200, 3], "id": 124, "isthing": 0, "name": "dumbbell"}, {"color": [120, 120, 80], "id": 125, "isthing": 0, "name": "earphone"}, {"color": [140, 140, 140], "id": 126, "isthing": 0, "name": "earrings"}, {"color": [204, 5, 255], "id": 127, "isthing": 0, "name": "egg"}, {"color": [230, 230, 230], "id": 128, "isthing": 0, "name": "electric fan"}, {"color": [4, 250, 7], "id": 129, "isthing": 0, "name": "electric iron"}, {"color": [224, 5, 255], "id": 130, "isthing": 0, "name": "electric pot"}, {"color": [235, 255, 7], "id": 131, "isthing": 0, "name": "electric saw"}, {"color": [150, 5, 61], "id": 132, "isthing": 0, "name": "electronic keyboard"}, {"color": [120, 120, 70], "id": 133, "isthing": 0, "name": "engine"}, {"color": [8, 255, 51], "id": 134, "isthing": 0, "name": "envelope"}, {"color": [255, 6, 82], "id": 135, "isthing": 0, "name": "equipment"}, {"color": [143, 255, 140], "id": 136, "isthing": 0, "name": "escalator"}, {"color": [204, 255, 4], "id": 137, "isthing": 0, "name": "exhibition booth"}, {"color": [255, 51, 7], "id": 138, "isthing": 0, "name": "extinguisher"}, {"color": [204, 70, 3], "id": 139, "isthing": 0, "name": "eyeglass"}, {"color": [0, 102, 200], "id": 140, "isthing": 0, "name": "fan"}, {"color": [61, 230, 250], "id": 141, "isthing": 0, "name": "faucet"}, {"color": [255, 6, 51], "id": 142, "isthing": 0, "name": "fax machine"}, {"color": [11, 102, 255], "id": 143, "isthing": 0, "name": "fence"}, {"color": [255, 7, 71], "id": 144, "isthing": 0, "name": "ferris wheel"}, {"color": [255, 9, 224], "id": 145, "isthing": 0, "name": "fire extinguisher"}, {"color": [9, 7, 230], "id": 146, "isthing": 0, "name": "fire hydrant"}, {"color": [220, 220, 220], "id": 147, "isthing": 0, "name": "fire place"}, {"color": [255, 9, 92], "id": 148, "isthing": 0, "name": "fish"}, {"color": [112, 9, 255], "id": 149, "isthing": 0, "name": "fish tank"}, {"color": [8, 255, 214], "id": 150, "isthing": 0, "name": "fishbowl"}, {"color": [7, 255, 224], "id": 151, "isthing": 0, "name": "fishing net"}, {"color": [255, 184, 6], "id": 152, "isthing": 0, "name": "fishing pole"}, {"color": [10, 255, 71], "id": 153, "isthing": 0, "name": "flag"}, {"color": [255, 41, 10], "id": 154, "isthing": 0, "name": "flagstaff"}, {"color": [7, 255, 255], "id": 155, "isthing": 0, "name": "flame"}, {"color": [224, 255, 8], "id": 156, "isthing": 0, "name": "flashlight"}, {"color": [102, 8, 255], "id": 157, "isthing": 0, "name": "floor"}, {"color": [255, 61, 6], "id": 158, "isthing": 0, "name": "flower"}, {"color": [255, 194, 7], "id": 159, "isthing": 0, "name": "fly"}, {"color": [255, 122, 8], "id": 160, "isthing": 0, "name": "foam"}, {"color": [0, 255, 20], "id": 161, "isthing": 0, "name": "food"}, {"color": [255, 8, 41], "id": 162, "isthing": 0, "name": "footbridge"}, {"color": [255, 5, 153], "id": 163, "isthing": 0, "name": "forceps"}, {"color": [6, 51, 255], "id": 164, "isthing": 0, "name": "fork"}, {"color": [235, 12, 255], "id": 165, "isthing": 0, "name": "forklift"}, {"color": [160, 150, 20], "id": 166, "isthing": 0, "name": "fountain"}, {"color": [0, 163, 255], "id": 167, "isthing": 0, "name": "fox"}, {"color": [140, 140, 140], "id": 168, "isthing": 0, "name": "frame"}, {"color": [250, 10, 15], "id": 169, "isthing": 0, "name": "fridge"}, {"color": [20, 255, 0], "id": 170, "isthing": 0, "name": "frog"}, {"color": [31, 255, 0], "id": 171, "isthing": 0, "name": "fruit"}, {"color": [255, 31, 0], "id": 172, "isthing": 0, "name": "funnel"}, {"color": [255, 224, 0], "id": 173, "isthing": 0, "name": "furnace"}, {"color": [153, 255, 0], "id": 174, "isthing": 0, "name": "game controller"}, {"color": [0, 0, 255], "id": 175, "isthing": 0, "name": "game machine"}, {"color": [255, 71, 0], "id": 176, "isthing": 0, "name": "gas cylinder"}, {"color": [0, 235, 255], "id": 177, "isthing": 0, "name": "gas hood"}, {"color": [0, 173, 255], "id": 178, "isthing": 0, "name": "gas stove"}, {"color": [31, 0, 255], "id": 179, "isthing": 0, "name": "gift box"}, {"color": [120, 120, 120], "id": 180, "isthing": 0, "name": "glass"}, {"color": [180, 120, 120], "id": 181, "isthing": 0, "name": "glass marble"}, {"color": [6, 230, 230], "id": 182, "isthing": 0, "name": "globe"}, {"color": [80, 50, 50], "id": 183, "isthing": 0, "name": "glove"}, {"color": [4, 200, 3], "id": 184, "isthing": 0, "name": "goal"}, {"color": [120, 120, 80], "id": 185, "isthing": 0, "name": "grandstand"}, {"color": [140, 140, 140], "id": 186, "isthing": 0, "name": "grass"}, {"color": [204, 5, 255], "id": 187, "isthing": 0, "name": "gravestone"}, {"color": [230, 230, 230], "id": 188, "isthing": 0, "name": "ground"}, {"color": [4, 250, 7], "id": 189, "isthing": 0, "name": "guardrail"}, {"color": [224, 5, 255], "id": 190, "isthing": 0, "name": "guitar"}, {"color": [235, 255, 7], "id": 191, "isthing": 0, "name": "gun"}, {"color": [150, 5, 61], "id": 192, "isthing": 0, "name": "hammer"}, {"color": [120, 120, 70], "id": 193, "isthing": 0, "name": "hand cart"}, {"color": [8, 255, 51], "id": 194, "isthing": 0, "name": "handle"}, {"color": [255, 6, 82], "id": 195, "isthing": 0, "name": "handrail"}, {"color": [143, 255, 140], "id": 196, "isthing": 0, "name": "hanger"}, {"color": [204, 255, 4], "id": 197, "isthing": 0, "name": "hard disk drive"}, {"color": [255, 51, 7], "id": 198, "isthing": 0, "name": "hat"}, {"color": [204, 70, 3], "id": 199, "isthing": 0, "name": "hay"}, {"color": [0, 102, 200], "id": 200, "isthing": 0, "name": "headphone"}, {"color": [61, 230, 250], "id": 201, "isthing": 0, "name": "heater"}, {"color": [255, 6, 51], "id": 202, "isthing": 0, "name": "helicopter"}, {"color": [11, 102, 255], "id": 203, "isthing": 0, "name": "helmet"}, {"color": [255, 7, 71], "id": 204, "isthing": 0, "name": "holder"}, {"color": [255, 9, 224], "id": 205, "isthing": 0, "name": "hook"}, {"color": [9, 7, 230], "id": 206, "isthing": 0, "name": "horse"}, {"color": [220, 220, 220], "id": 207, "isthing": 0, "name": "horse-drawn carriage"}, {"color": [255, 9, 92], "id": 208, "isthing": 0, "name": "hot-air balloon"}, {"color": [112, 9, 255], "id": 209, "isthing": 0, "name": "hydrovalve"}, {"color": [8, 255, 214], "id": 210, "isthing": 0, "name": "ice"}, {"color": [7, 255, 224], "id": 211, "isthing": 0, "name": "inflator pump"}, {"color": [255, 184, 6], "id": 212, "isthing": 0, "name": "ipod"}, {"color": [10, 255, 71], "id": 213, "isthing": 0, "name": "iron"}, {"color": [255, 41, 10], "id": 214, "isthing": 0, "name": "ironing board"}, {"color": [7, 255, 255], "id": 215, "isthing": 0, "name": "jar"}, {"color": [224, 255, 8], "id": 216, "isthing": 0, "name": "kart"}, {"color": [102, 8, 255], "id": 217, "isthing": 0, "name": "kettle"}, {"color": [255, 61, 6], "id": 218, "isthing": 0, "name": "key"}, {"color": [255, 194, 7], "id": 219, "isthing": 0, "name": "keyboard"}, {"color": [255, 122, 8], "id": 220, "isthing": 0, "name": "kitchen range"}, {"color": [0, 255, 20], "id": 221, "isthing": 0, "name": "kite"}, {"color": [255, 8, 41], "id": 222, "isthing": 0, "name": "knife"}, {"color": [255, 5, 153], "id": 223, "isthing": 0, "name": "knife block"}, {"color": [6, 51, 255], "id": 224, "isthing": 0, "name": "ladder"}, {"color": [235, 12, 255], "id": 225, "isthing": 0, "name": "ladder truck"}, {"color": [160, 150, 20], "id": 226, "isthing": 0, "name": "ladle"}, {"color": [0, 163, 255], "id": 227, "isthing": 0, "name": "laptop"}, {"color": [140, 140, 140], "id": 228, "isthing": 0, "name": "leaves"}, {"color": [250, 10, 15], "id": 229, "isthing": 0, "name": "lid"}, {"color": [20, 255, 0], "id": 230, "isthing": 0, "name": "life buoy"}, {"color": [31, 255, 0], "id": 231, "isthing": 0, "name": "light"}, {"color": [255, 31, 0], "id": 232, "isthing": 0, "name": "light bulb"}, {"color": [255, 224, 0], "id": 233, "isthing": 0, "name": "lighter"}, {"color": [153, 255, 0], "id": 234, "isthing": 0, "name": "line"}, {"color": [0, 0, 255], "id": 235, "isthing": 0, "name": "lion"}, {"color": [255, 71, 0], "id": 236, "isthing": 0, "name": "lobster"}, {"color": [0, 235, 255], "id": 237, "isthing": 0, "name": "lock"}, {"color": [0, 173, 255], "id": 238, "isthing": 0, "name": "machine"}, {"color": [31, 0, 255], "id": 239, "isthing": 0, "name": "mailbox"}, {"color": [120, 120, 120], "id": 240, "isthing": 0, "name": "mannequin"}, {"color": [180, 120, 120], "id": 241, "isthing": 0, "name": "map"}, {"color": [6, 230, 230], "id": 242, "isthing": 0, "name": "mask"}, {"color": [80, 50, 50], "id": 243, "isthing": 0, "name": "mat"}, {"color": [4, 200, 3], "id": 244, "isthing": 0, "name": "match book"}, {"color": [120, 120, 80], "id": 245, "isthing": 0, "name": "mattress"}, {"color": [140, 140, 140], "id": 246, "isthing": 0, "name": "menu"}, {"color": [204, 5, 255], "id": 247, "isthing": 0, "name": "metal"}, {"color": [230, 230, 230], "id": 248, "isthing": 0, "name": "meter box"}, {"color": [4, 250, 7], "id": 249, "isthing": 0, "name": "microphone"}, {"color": [224, 5, 255], "id": 250, "isthing": 0, "name": "microwave"}, {"color": [235, 255, 7], "id": 251, "isthing": 0, "name": "mirror"}, {"color": [150, 5, 61], "id": 252, "isthing": 0, "name": "missile"}, {"color": [120, 120, 70], "id": 253, "isthing": 0, "name": "model"}, {"color": [8, 255, 51], "id": 254, "isthing": 0, "name": "money"}, {"color": [255, 6, 82], "id": 255, "isthing": 0, "name": "monkey"}, {"color": [143, 255, 140], "id": 256, "isthing": 0, "name": "mop"}, {"color": [204, 255, 4], "id": 257, "isthing": 0, "name": "motorbike"}, {"color": [255, 51, 7], "id": 258, "isthing": 0, "name": "mountain"}, {"color": [204, 70, 3], "id": 259, "isthing": 0, "name": "mouse"}, {"color": [0, 102, 200], "id": 260, "isthing": 0, "name": "mouse pad"}, {"color": [61, 230, 250], "id": 261, "isthing": 0, "name": "musical instrument"}, {"color": [255, 6, 51], "id": 262, "isthing": 0, "name": "napkin"}, {"color": [11, 102, 255], "id": 263, "isthing": 0, "name": "net"}, {"color": [255, 7, 71], "id": 264, "isthing": 0, "name": "newspaper"}, {"color": [255, 9, 224], "id": 265, "isthing": 0, "name": "oar"}, {"color": [9, 7, 230], "id": 266, "isthing": 0, "name": "ornament"}, {"color": [220, 220, 220], "id": 267, "isthing": 0, "name": "outlet"}, {"color": [255, 9, 92], "id": 268, "isthing": 0, "name": "oven"}, {"color": [112, 9, 255], "id": 269, "isthing": 0, "name": "oxygen bottle"}, {"color": [8, 255, 214], "id": 270, "isthing": 0, "name": "pack"}, {"color": [7, 255, 224], "id": 271, "isthing": 0, "name": "pan"}, {"color": [255, 184, 6], "id": 272, "isthing": 0, "name": "paper"}, {"color": [10, 255, 71], "id": 273, "isthing": 0, "name": "paper box"}, {"color": [255, 41, 10], "id": 274, "isthing": 0, "name": "paper cutter"}, {"color": [7, 255, 255], "id": 275, "isthing": 0, "name": "parachute"}, {"color": [224, 255, 8], "id": 276, "isthing": 0, "name": "parasol"}, {"color": [102, 8, 255], "id": 277, "isthing": 0, "name": "parterre"}, {"color": [255, 61, 6], "id": 278, "isthing": 0, "name": "patio"}, {"color": [255, 194, 7], "id": 279, "isthing": 0, "name": "pelage"}, {"color": [255, 122, 8], "id": 280, "isthing": 0, "name": "pen"}, {"color": [0, 255, 20], "id": 281, "isthing": 0, "name": "pen container"}, {"color": [255, 8, 41], "id": 282, "isthing": 0, "name": "pencil"}, {"color": [255, 5, 153], "id": 283, "isthing": 0, "name": "person"}, {"color": [6, 51, 255], "id": 284, "isthing": 0, "name": "photo"}, {"color": [235, 12, 255], "id": 285, "isthing": 0, "name": "piano"}, {"color": [160, 150, 20], "id": 286, "isthing": 0, "name": "picture"}, {"color": [0, 163, 255], "id": 287, "isthing": 0, "name": "pig"}, {"color": [140, 140, 140], "id": 288, "isthing": 0, "name": "pillar"}, {"color": [250, 10, 15], "id": 289, "isthing": 0, "name": "pillow"}, {"color": [20, 255, 0], "id": 290, "isthing": 0, "name": "pipe"}, {"color": [31, 255, 0], "id": 291, "isthing": 0, "name": "pitcher"}, {"color": [255, 31, 0], "id": 292, "isthing": 0, "name": "plant"}, {"color": [255, 224, 0], "id": 293, "isthing": 0, "name": "plastic"}, {"color": [153, 255, 0], "id": 294, "isthing": 0, "name": "plate"}, {"color": [0, 0, 255], "id": 295, "isthing": 0, "name": "platform"}, {"color": [255, 71, 0], "id": 296, "isthing": 0, "name": "player"}, {"color": [0, 235, 255], "id": 297, "isthing": 0, "name": "playground"}, {"color": [0, 173, 255], "id": 298, "isthing": 0, "name": "pliers"}, {"color": [31, 0, 255], "id": 299, "isthing": 0, "name": "plume"}, {"color": [120, 120, 120], "id": 300, "isthing": 0, "name": "poker"}, {"color": [180, 120, 120], "id": 301, "isthing": 0, "name": "poker chip"}, {"color": [6, 230, 230], "id": 302, "isthing": 0, "name": "pole"}, {"color": [80, 50, 50], "id": 303, "isthing": 0, "name": "pool table"}, {"color": [4, 200, 3], "id": 304, "isthing": 0, "name": "postcard"}, {"color": [120, 120, 80], "id": 305, "isthing": 0, "name": "poster"}, {"color": [140, 140, 140], "id": 306, "isthing": 0, "name": "pot"}, {"color": [204, 5, 255], "id": 307, "isthing": 0, "name": "pottedplant"}, {"color": [230, 230, 230], "id": 308, "isthing": 0, "name": "printer"}, {"color": [4, 250, 7], "id": 309, "isthing": 0, "name": "projector"}, {"color": [224, 5, 255], "id": 310, "isthing": 0, "name": "pumpkin"}, {"color": [235, 255, 7], "id": 311, "isthing": 0, "name": "rabbit"}, {"color": [150, 5, 61], "id": 312, "isthing": 0, "name": "racket"}, {"color": [120, 120, 70], "id": 313, "isthing": 0, "name": "radiator"}, {"color": [8, 255, 51], "id": 314, "isthing": 0, "name": "radio"}, {"color": [255, 6, 82], "id": 315, "isthing": 0, "name": "rail"}, {"color": [143, 255, 140], "id": 316, "isthing": 0, "name": "rake"}, {"color": [204, 255, 4], "id": 317, "isthing": 0, "name": "ramp"}, {"color": [255, 51, 7], "id": 318, "isthing": 0, "name": "range hood"}, {"color": [204, 70, 3], "id": 319, "isthing": 0, "name": "receiver"}, {"color": [0, 102, 200], "id": 320, "isthing": 0, "name": "recorder"}, {"color": [61, 230, 250], "id": 321, "isthing": 0, "name": "recreational machines"}, {"color": [255, 6, 51], "id": 322, "isthing": 0, "name": "remote control"}, {"color": [11, 102, 255], "id": 323, "isthing": 0, "name": "road"}, {"color": [255, 7, 71], "id": 324, "isthing": 0, "name": "robot"}, {"color": [255, 9, 224], "id": 325, "isthing": 0, "name": "rock"}, {"color": [9, 7, 230], "id": 326, "isthing": 0, "name": "rocket"}, {"color": [220, 220, 220], "id": 327, "isthing": 0, "name": "rocking horse"}, {"color": [255, 9, 92], "id": 328, "isthing": 0, "name": "rope"}, {"color": [112, 9, 255], "id": 329, "isthing": 0, "name": "rug"}, {"color": [8, 255, 214], "id": 330, "isthing": 0, "name": "ruler"}, {"color": [7, 255, 224], "id": 331, "isthing": 0, "name": "runway"}, {"color": [255, 184, 6], "id": 332, "isthing": 0, "name": "saddle"}, {"color": [10, 255, 71], "id": 333, "isthing": 0, "name": "sand"}, {"color": [255, 41, 10], "id": 334, "isthing": 0, "name": "saw"}, {"color": [7, 255, 255], "id": 335, "isthing": 0, "name": "scale"}, {"color": [224, 255, 8], "id": 336, "isthing": 0, "name": "scanner"}, {"color": [102, 8, 255], "id": 337, "isthing": 0, "name": "scissors"}, {"color": [255, 61, 6], "id": 338, "isthing": 0, "name": "scoop"}, {"color": [255, 194, 7], "id": 339, "isthing": 0, "name": "screen"}, {"color": [255, 122, 8], "id": 340, "isthing": 0, "name": "screwdriver"}, {"color": [0, 255, 20], "id": 341, "isthing": 0, "name": "sculpture"}, {"color": [255, 8, 41], "id": 342, "isthing": 0, "name": "scythe"}, {"color": [255, 5, 153], "id": 343, "isthing": 0, "name": "sewer"}, {"color": [6, 51, 255], "id": 344, "isthing": 0, "name": "sewing machine"}, {"color": [235, 12, 255], "id": 345, "isthing": 0, "name": "shed"}, {"color": [160, 150, 20], "id": 346, "isthing": 0, "name": "sheep"}, {"color": [0, 163, 255], "id": 347, "isthing": 0, "name": "shell"}, {"color": [140, 140, 140], "id": 348, "isthing": 0, "name": "shelves"}, {"color": [250, 10, 15], "id": 349, "isthing": 0, "name": "shoe"}, {"color": [20, 255, 0], "id": 350, "isthing": 0, "name": "shopping cart"}, {"color": [31, 255, 0], "id": 351, "isthing": 0, "name": "shovel"}, {"color": [255, 31, 0], "id": 352, "isthing": 0, "name": "sidecar"}, {"color": [255, 224, 0], "id": 353, "isthing": 0, "name": "sidewalk"}, {"color": [153, 255, 0], "id": 354, "isthing": 0, "name": "sign"}, {"color": [0, 0, 255], "id": 355, "isthing": 0, "name": "signal light"}, {"color": [255, 71, 0], "id": 356, "isthing": 0, "name": "sink"}, {"color": [0, 235, 255], "id": 357, "isthing": 0, "name": "skateboard"}, {"color": [0, 173, 255], "id": 358, "isthing": 0, "name": "ski"}, {"color": [31, 0, 255], "id": 359, "isthing": 0, "name": "sky"}, {"color": [120, 120, 120], "id": 360, "isthing": 0, "name": "sled"}, {"color": [180, 120, 120], "id": 361, "isthing": 0, "name": "slippers"}, {"color": [6, 230, 230], "id": 362, "isthing": 0, "name": "smoke"}, {"color": [80, 50, 50], "id": 363, "isthing": 0, "name": "snail"}, {"color": [4, 200, 3], "id": 364, "isthing": 0, "name": "snake"}, {"color": [120, 120, 80], "id": 365, "isthing": 0, "name": "snow"}, {"color": [140, 140, 140], "id": 366, "isthing": 0, "name": "snowmobiles"}, {"color": [204, 5, 255], "id": 367, "isthing": 0, "name": "sofa"}, {"color": [230, 230, 230], "id": 368, "isthing": 0, "name": "spanner"}, {"color": [4, 250, 7], "id": 369, "isthing": 0, "name": "spatula"}, {"color": [224, 5, 255], "id": 370, "isthing": 0, "name": "speaker"}, {"color": [235, 255, 7], "id": 371, "isthing": 0, "name": "speed bump"}, {"color": [150, 5, 61], "id": 372, "isthing": 0, "name": "spice container"}, {"color": [120, 120, 70], "id": 373, "isthing": 0, "name": "spoon"}, {"color": [8, 255, 51], "id": 374, "isthing": 0, "name": "sprayer"}, {"color": [255, 6, 82], "id": 375, "isthing": 0, "name": "squirrel"}, {"color": [143, 255, 140], "id": 376, "isthing": 0, "name": "stage"}, {"color": [204, 255, 4], "id": 377, "isthing": 0, "name": "stair"}, {"color": [255, 51, 7], "id": 378, "isthing": 0, "name": "stapler"}, {"color": [204, 70, 3], "id": 379, "isthing": 0, "name": "stick"}, {"color": [0, 102, 200], "id": 380, "isthing": 0, "name": "sticky note"}, {"color": [61, 230, 250], "id": 381, "isthing": 0, "name": "stone"}, {"color": [255, 6, 51], "id": 382, "isthing": 0, "name": "stool"}, {"color": [11, 102, 255], "id": 383, "isthing": 0, "name": "stove"}, {"color": [255, 7, 71], "id": 384, "isthing": 0, "name": "straw"}, {"color": [255, 9, 224], "id": 385, "isthing": 0, "name": "stretcher"}, {"color": [9, 7, 230], "id": 386, "isthing": 0, "name": "sun"}, {"color": [220, 220, 220], "id": 387, "isthing": 0, "name": "sunglass"}, {"color": [255, 9, 92], "id": 388, "isthing": 0, "name": "sunshade"}, {"color": [112, 9, 255], "id": 389, "isthing": 0, "name": "surveillance camera"}, {"color": [8, 255, 214], "id": 390, "isthing": 0, "name": "swan"}, {"color": [7, 255, 224], "id": 391, "isthing": 0, "name": "sweeper"}, {"color": [255, 184, 6], "id": 392, "isthing": 0, "name": "swim ring"}, {"color": [10, 255, 71], "id": 393, "isthing": 0, "name": "swimming pool"}, {"color": [255, 41, 10], "id": 394, "isthing": 0, "name": "swing"}, {"color": [7, 255, 255], "id": 395, "isthing": 0, "name": "switch"}, {"color": [224, 255, 8], "id": 396, "isthing": 0, "name": "table"}, {"color": [102, 8, 255], "id": 397, "isthing": 0, "name": "tableware"}, {"color": [255, 61, 6], "id": 398, "isthing": 0, "name": "tank"}, {"color": [255, 194, 7], "id": 399, "isthing": 0, "name": "tap"}, {"color": [255, 122, 8], "id": 400, "isthing": 0, "name": "tape"}, {"color": [0, 255, 20], "id": 401, "isthing": 0, "name": "tarp"}, {"color": [255, 8, 41], "id": 402, "isthing": 0, "name": "telephone"}, {"color": [255, 5, 153], "id": 403, "isthing": 0, "name": "telephone booth"}, {"color": [6, 51, 255], "id": 404, "isthing": 0, "name": "tent"}, {"color": [235, 12, 255], "id": 405, "isthing": 0, "name": "tire"}, {"color": [160, 150, 20], "id": 406, "isthing": 0, "name": "toaster"}, {"color": [0, 163, 255], "id": 407, "isthing": 0, "name": "toilet"}, {"color": [140, 140, 140], "id": 408, "isthing": 0, "name": "tong"}, {"color": [250, 10, 15], "id": 409, "isthing": 0, "name": "tool"}, {"color": [20, 255, 0], "id": 410, "isthing": 0, "name": "toothbrush"}, {"color": [31, 255, 0], "id": 411, "isthing": 0, "name": "towel"}, {"color": [255, 31, 0], "id": 412, "isthing": 0, "name": "toy"}, {"color": [255, 224, 0], "id": 413, "isthing": 0, "name": "toy car"}, {"color": [153, 255, 0], "id": 414, "isthing": 0, "name": "track"}, {"color": [0, 0, 255], "id": 415, "isthing": 0, "name": "train"}, {"color": [255, 71, 0], "id": 416, "isthing": 0, "name": "trampoline"}, {"color": [0, 235, 255], "id": 417, "isthing": 0, "name": "trash bin"}, {"color": [0, 173, 255], "id": 418, "isthing": 0, "name": "tray"}, {"color": [31, 0, 255], "id": 419, "isthing": 0, "name": "tree"}, {"color": [120, 120, 120], "id": 420, "isthing": 0, "name": "tricycle"}, {"color": [180, 120, 120], "id": 421, "isthing": 0, "name": "tripod"}, {"color": [6, 230, 230], "id": 422, "isthing": 0, "name": "trophy"}, {"color": [80, 50, 50], "id": 423, "isthing": 0, "name": "truck"}, {"color": [4, 200, 3], "id": 424, "isthing": 0, "name": "tube"}, {"color": [120, 120, 80], "id": 425, "isthing": 0, "name": "turtle"}, {"color": [140, 140, 140], "id": 426, "isthing": 0, "name": "tvmonitor"}, {"color": [204, 5, 255], "id": 427, "isthing": 0, "name": "tweezers"}, {"color": [230, 230, 230], "id": 428, "isthing": 0, "name": "typewriter"}, {"color": [4, 250, 7], "id": 429, "isthing": 0, "name": "umbrella"}, {"color": [224, 5, 255], "id": 430, "isthing": 0, "name": "unknown"}, {"color": [235, 255, 7], "id": 431, "isthing": 0, "name": "vacuum cleaner"}, {"color": [150, 5, 61], "id": 432, "isthing": 0, "name": "vending machine"}, {"color": [120, 120, 70], "id": 433, "isthing": 0, "name": "video camera"}, {"color": [8, 255, 51], "id": 434, "isthing": 0, "name": "video game console"}, {"color": [255, 6, 82], "id": 435, "isthing": 0, "name": "video player"}, {"color": [143, 255, 140], "id": 436, "isthing": 0, "name": "video tape"}, {"color": [204, 255, 4], "id": 437, "isthing": 0, "name": "violin"}, {"color": [255, 51, 7], "id": 438, "isthing": 0, "name": "wakeboard"}, {"color": [204, 70, 3], "id": 439, "isthing": 0, "name": "wall"}, {"color": [0, 102, 200], "id": 440, "isthing": 0, "name": "wallet"}, {"color": [61, 230, 250], "id": 441, "isthing": 0, "name": "wardrobe"}, {"color": [255, 6, 51], "id": 442, "isthing": 0, "name": "washing machine"}, {"color": [11, 102, 255], "id": 443, "isthing": 0, "name": "watch"}, {"color": [255, 7, 71], "id": 444, "isthing": 0, "name": "water"}, {"color": [255, 9, 224], "id": 445, "isthing": 0, "name": "water dispenser"}, {"color": [9, 7, 230], "id": 446, "isthing": 0, "name": "water pipe"}, {"color": [220, 220, 220], "id": 447, "isthing": 0, "name": "water skate board"}, {"color": [255, 9, 92], "id": 448, "isthing": 0, "name": "watermelon"}, {"color": [112, 9, 255], "id": 449, "isthing": 0, "name": "whale"}, {"color": [8, 255, 214], "id": 450, "isthing": 0, "name": "wharf"}, {"color": [7, 255, 224], "id": 451, "isthing": 0, "name": "wheel"}, {"color": [255, 184, 6], "id": 452, "isthing": 0, "name": "wheelchair"}, {"color": [10, 255, 71], "id": 453, "isthing": 0, "name": "window"}, {"color": [255, 41, 10], "id": 454, "isthing": 0, "name": "window blinds"}, {"color": [7, 255, 255], "id": 455, "isthing": 0, "name": "wineglass"}, {"color": [224, 255, 8], "id": 456, "isthing": 0, "name": "wire"}, {"color": [102, 8, 255], "id": 457, "isthing": 0, "name": "wood"}, {"color": [255, 61, 6], "id": 458, "isthing": 0, "name": "wool"},]
PASCAL_VOC_21_CATEGORIES = [ {"color": [0, 0, 0], "id": 0, "isthing": 1, "name": "background"}, {"color": [128, 0, 0], "id": 1, "isthing": 1, "name": "aeroplane"}, {"color": [0, 128, 0], "id": 2, "isthing": 1, "name": "bicycle"}, {"color": [128, 128, 0], "id": 3, "isthing": 1, "name": "bird"}, {"color": [0, 0, 128], "id": 4, "isthing": 1, "name": "boat"}, {"color": [128, 0, 128], "id": 5, "isthing": 1, "name": "bottle"}, {"color": [0, 128, 128], "id": 6, "isthing": 1, "name": "bus"}, {"color": [128, 128, 128], "id": 7, "isthing": 1, "name": "car"}, {"color": [64, 0, 0], "id": 8, "isthing": 1, "name": "cat"}, {"color": [192, 0, 0], "id": 9, "isthing": 1, "name": "chair"}, {"color": [64, 128, 0], "id": 10, "isthing": 1, "name": "cow"}, {"color": [192, 128, 0], "id": 11, "isthing": 1, "name": "diningtable"}, {"color": [64, 0, 128], "id": 12, "isthing": 1, "name": "dog"}, {"color": [192, 0, 128], "id": 13, "isthing": 1, "name": "horse"}, {"color": [64, 128, 128], "id": 14, "isthing": 1, "name": "motorbike"}, {"color": [192, 128, 128], "id": 15, "isthing": 1, "name": "person"}, {"color": [0, 64, 0], "id": 16, "isthing": 1, "name": "pottedplant"}, {"color": [128, 64, 0], "id": 17, "isthing": 1, "name": "sheep"}, {"color": [0, 192, 0], "id": 18, "isthing": 1, "name": "sofa"}, {"color": [128, 192, 0], "id": 19, "isthing": 1, "name": "train"}, {"color": [0, 64, 128], "id": 20, "isthing": 1, "name": "tvmonitor"},]
PASCAL_PARTS_CATEGORIES = [ {"id": 1, "name": "aeroplane body", "color": [231, 4, 237]}, {"id": 2, "name": "aeroplane stern", "color": [116, 80, 69]}, {"id": 3, "name": "aeroplane wing", "color": [214, 86, 123]}, {"id": 4, "name": "aeroplane tail", "color": [22, 174, 172]}, {"id": 5, "name": "aeroplane engine", "color": [197, 128, 182]}, {"id": 6, "name": "aeroplane wheel", "color": [82, 197, 247]}, {"id": 7, "name": "bicycle body", "color": [125, 34, 155]}, {"id": 8, "name": "bicycle wheel", "color": [240, 6, 206]}, {"id": 9, "name": "bicycle saddle", "color": [0, 67, 113]}, {"id": 10, "name": "bicycle handlebar", "color": [112, 158, 137]}, {"id": 11, "name": "bicycle headlight", "color": [255, 182, 87]}, {"id": 12, "name": "bird torso", "color": [189, 249, 133]}, {"id": 13, "name": "bird head", "color": [104, 202, 100]}, {"id": 14, "name": "bird neck", "color": [158, 181, 70]}, {"id": 15, "name": "bird wing", "color": [61, 245, 238]}, {"id": 16, "name": "bird leg", "color": [55, 126, 0]}, {"id": 17, "name": "bird foot", "color": [225, 182, 182]}, {"id": 18, "name": "bird tail", "color": [68, 62, 33]}, {"id": 19, "name": "boat ", "color": [200, 219, 162]}, {"id": 20, "name": "bottle body", "color": [172, 155, 96]}, {"id": 21, "name": "bottle cap", "color": [185, 14, 216]}, {"id": 22, "name": "bus body", "color": [3, 58, 66]}, {"id": 23, "name": "bus frontside", "color": [26, 173, 31]}, {"id": 24, "name": "bus leftside", "color": [205, 197, 47]}, {"id": 25, "name": "bus rightside", "color": [6, 223, 194]}, {"id": 26, "name": "bus backside", "color": [10, 232, 224]}, {"id": 27, "name": "bus roofside", "color": [189, 124, 163]}, {"id": 28, "name": "bus mirror", "color": [253, 98, 118]}, {"id": 29, "name": "bus fliplate", "color": [134, 124, 251]}, {"id": 30, "name": "bus bliplate", "color": [86, 248, 252]}, {"id": 31, "name": "bus door", "color": [104, 232, 186]}, {"id": 32, "name": "bus wheel", "color": [73, 10, 81]}, {"id": 33, "name": "bus headlight", "color": [83, 15, 206]}, {"id": 34, "name": "bus window", "color": [182, 248, 35]}, {"id": 35, "name": "car body", "color": [111, 175, 136]}, {"id": 36, "name": "car mirror", "color": [244, 27, 39]}, {"id": 37, "name": "car tmirror", "color": [60, 75, 197]}, {"id": 38, "name": "car fliplate", "color": [32, 124, 177]}, {"id": 39, "name": "car bliplate", "color": [132, 107, 137]}, {"id": 40, "name": "car door", "color": [29, 145, 220]}, {"id": 41, "name": "car wheel", "color": [211, 58, 216]}, {"id": 42, "name": "car headlight", "color": [253, 195, 114]}, {"id": 43, "name": "car window", "color": [51, 163, 166]}, {"id": 44, "name": "cat torso", "color": [68, 44, 17]}, {"id": 45, "name": "cat head", "color": [148, 109, 203]}, {"id": 46, "name": "cat eye", "color": [221, 235, 212]}, {"id": 47, "name": "cat ear", "color": [25, 226, 114]}, {"id": 48, "name": "cat nose", "color": [99, 126, 184]}, {"id": 49, "name": "cat neck", "color": [54, 164, 161]}, {"id": 50, "name": "cat leg", "color": [114, 251, 219]}, {"id": 51, "name": "cat pawn", "color": [145, 28, 176]}, {"id": 52, "name": "cat tail", "color": [22, 29, 245]}, {"id": 53, "name": "chair ", "color": [174, 108, 109]}, {"id": 54, "name": "cow torso", "color": [153, 207, 125]}, {"id": 55, "name": "cow head", "color": [243, 197, 251]}, {"id": 56, "name": "cow eye", "color": [99, 87, 120]}, {"id": 57, "name": "cow ear", "color": [194, 7, 114]}, {"id": 58, "name": "cow muzzle", "color": [242, 122, 177]}, {"id": 59, "name": "cow horn", "color": [202, 242, 232]}, {"id": 60, "name": "cow neck", "color": [250, 136, 178]}, {"id": 61, "name": "cow leg", "color": [171, 46, 206]}, {"id": 62, "name": "cow tail", "color": [186, 133, 2]}, {"id": 63, "name": "table ", "color": [201, 1, 108]}, {"id": 64, "name": "dog torso", "color": [245, 11, 186]}, {"id": 65, "name": "dog head", "color": [33, 191, 131]}, {"id": 66, "name": "dog eye", "color": [225, 95, 66]}, {"id": 67, "name": "dog ear", "color": [124, 25, 24]}, {"id": 68, "name": "dog nose", "color": [214, 234, 112]}, {"id": 69, "name": "dog neck", "color": [129, 83, 21]}, {"id": 70, "name": "dog leg", "color": [185, 76, 143]}, {"id": 71, "name": "dog pawn", "color": [180, 1, 74]}, {"id": 72, "name": "dog tail", "color": [121, 134, 63]}, {"id": 73, "name": "dog muzzle", "color": [90, 58, 214]}, {"id": 74, "name": "horse body", "color": [223, 7, 152]}, {"id": 75, "name": "horse head", "color": [154, 96, 130]}, {"id": 76, "name": "horse eye", "color": [221, 98, 183]}, {"id": 77, "name": "horse ear", "color": [230, 145, 183]}, {"id": 78, "name": "horse muzzle", "color": [213, 203, 88]}, {"id": 79, "name": "horse torso", "color": [183, 92, 254]}, {"id": 80, "name": "horse neck", "color": [206, 114, 11]}, {"id": 81, "name": "horse leg", "color": [214, 238, 15]}, {"id": 82, "name": "horse tail", "color": [57, 239, 109]}, {"id": 83, "name": "motorbike body", "color": [197, 138, 146]}, {"id": 84, "name": "motorbike wheel", "color": [124, 107, 252]}, {"id": 85, "name": "motorbike handlebar", "color": [163, 225, 169]}, {"id": 86, "name": "motorbike saddle", "color": [254, 180, 116]}, {"id": 87, "name": "motorbike headlight", "color": [119, 52, 22]}, {"id": 88, "name": "person body", "color": [198, 68, 18]}, {"id": 89, "name": "person head", "color": [40, 30, 77]}, {"id": 90, "name": "person eye", "color": [237, 64, 148]}, {"id": 91, "name": "person ear", "color": [49, 186, 234]}, {"id": 92, "name": "person ebrow", "color": [242, 204, 127]}, {"id": 93, "name": "person nose", "color": [101, 145, 176]}, {"id": 94, "name": "person mouth", "color": [31, 78, 216]}, {"id": 95, "name": "person hair", "color": [95, 148, 151]}, {"id": 96, "name": "person torso", "color": [126, 117, 235]}, {"id": 97, "name": "person neck", "color": [13, 146, 62]}, {"id": 98, "name": "person lower arm", "color": [9, 41, 5]}, {"id": 99, "name": "person upper arm", "color": [110, 109, 109]}, {"id": 100, "name": "person hand", "color": [58, 227, 163]}, {"id": 101, "name": "person lower leg", "color": [132, 63, 32]}, {"id": 102, "name": "person upper leg", "color": [212, 118, 174]}, {"id": 103, "name": "person foot", "color": [45, 66, 254]}, {"id": 104, "name": "pottedplant plant", "color": [236, 149, 209]}, {"id": 105, "name": "pottedplant pot", "color": [80, 197, 134]}, {"id": 106, "name": "sheep torso", "color": [241, 111, 194]}, {"id": 107, "name": "sheep head", "color": [31, 13, 13]}, {"id": 108, "name": "sheep eye", "color": [34, 207, 63]}, {"id": 109, "name": "sheep ear", "color": [249, 117, 121]}, {"id": 110, "name": "sheep muzzle", "color": [172, 128, 70]}, {"id": 111, "name": "sheep horn", "color": [97, 144, 104]}, {"id": 112, "name": "sheep neck", "color": [121, 163, 14]}, {"id": 113, "name": "sheep leg", "color": [38, 79, 231]}, {"id": 114, "name": "sheep tail", "color": [218, 195, 52]}, {"id": 115, "name": "sofa ", "color": [102, 8, 225]}, {"id": 116, "name": "train body", "color": [150, 44, 180]}, {"id": 117, "name": "train head", "color": [99, 250, 180]}, {"id": 118, "name": "train headlight", "color": [24, 148, 249]}, {"id": 119, "name": "train coach", "color": [143, 232, 181]}, {"id": 120, "name": "tvmonitor frame", "color": [68, 191, 134]}, {"id": 121, "name": "tvmonitor screen", "color": [186, 6, 38]}, {"id": 122, "name": "bag ", "color": [215, 253, 9]}, {"id": 123, "name": "basket ", "color": [150, 44, 154]}, {"id": 124, "name": "bed ", "color": [66, 132, 108]}, {"id": 125, "name": "bedclothes ", "color": [193, 84, 92]}, {"id": 126, "name": "bench ", "color": [84, 154, 254]}, {"id": 127, "name": "bird cage ", "color": [2, 93, 169]}, {"id": 128, "name": "board ", "color": [41, 254, 95]}, {"id": 129, "name": "book ", "color": [157, 228, 148]}, {"id": 130, "name": "bowl ", "color": [201, 198, 2]}, {"id": 131, "name": "box ", "color": [237, 151, 223]}, {"id": 132, "name": "bridge ", "color": [74, 200, 197]}, {"id": 133, "name": "brush ", "color": [157, 2, 192]}, {"id": 134, "name": "bucket ", "color": [62, 8, 145]}, {"id": 135, "name": "building ", "color": [244, 158, 23]}, {"id": 136, "name": "cabinet ", "color": [143, 34, 160]}, {"id": 137, "name": "cage ", "color": [74, 182, 153]}, {"id": 138, "name": "case ", "color": [44, 161, 32]}, {"id": 139, "name": "ceiling ", "color": [22, 207, 172]}, {"id": 140, "name": "cloth ", "color": [62, 233, 51]}, {"id": 141, "name": "computer ", "color": [203, 221, 8]}, {"id": 142, "name": "counter ", "color": [155, 154, 208]}, {"id": 143, "name": "cup ", "color": [136, 170, 161]}, {"id": 144, "name": "curtain ", "color": [69, 238, 67]}, {"id": 145, "name": "cushion ", "color": [250, 140, 63]}, {"id": 146, "name": "door ", "color": [228, 29, 142]}, {"id": 147, "name": "fence ", "color": [149, 149, 255]}, {"id": 148, "name": "fire place ", "color": [25, 17, 14]}, {"id": 149, "name": "floor ", "color": [141, 121, 107]}, {"id": 150, "name": "flower ", "color": [196, 171, 99]}, {"id": 151, "name": "food ", "color": [246, 30, 195]}, {"id": 152, "name": "fridge ", "color": [95, 2, 42]}, {"id": 153, "name": "grandstand ", "color": [174, 116, 162]}, {"id": 154, "name": "grass ", "color": [251, 58, 246]}, {"id": 155, "name": "ground ", "color": [138, 68, 168]}, {"id": 156, "name": "horse-drawn carriage ", "color": [236, 220, 194]}, {"id": 157, "name": "keyboard ", "color": [228, 180, 129]}, {"id": 158, "name": "laptop ", "color": [41, 39, 187]}, {"id": 159, "name": "light ", "color": [18, 155, 71]}, {"id": 160, "name": "mat ", "color": [81, 149, 168]}, {"id": 161, "name": "metal ", "color": [222, 250, 122]}, {"id": 162, "name": "mirror ", "color": [27, 14, 162]}, {"id": 163, "name": "mountain ", "color": [96, 67, 42]}, {"id": 164, "name": "mouse ", "color": [248, 27, 142]}, {"id": 165, "name": "pack ", "color": [48, 208, 79]}, {"id": 166, "name": "paper ", "color": [85, 44, 114]}, {"id": 167, "name": "picture ", "color": [8, 66, 36]}, {"id": 168, "name": "pillow ", "color": [199, 38, 36]}, {"id": 169, "name": "plant ", "color": [45, 67, 214]}, {"id": 170, "name": "plate ", "color": [176, 85, 199]}, {"id": 171, "name": "platform ", "color": [118, 46, 134]}, {"id": 172, "name": "pole ", "color": [66, 53, 97]}, {"id": 173, "name": "poster ", "color": [134, 95, 198]}, {"id": 174, "name": "pot ", "color": [56, 185, 27]}, {"id": 175, "name": "road ", "color": [12, 12, 242]}, {"id": 176, "name": "rock ", "color": [141, 182, 239]}, {"id": 177, "name": "rope ", "color": [242, 15, 134]}, {"id": 178, "name": "rug ", "color": [119, 78, 116]}, {"id": 179, "name": "sand ", "color": [159, 25, 177]}, {"id": 180, "name": "sculpture ", "color": [155, 71, 2]}, {"id": 181, "name": "shelves ", "color": [13, 156, 172]}, {"id": 182, "name": "sidewalk ", "color": [153, 56, 74]}, {"id": 183, "name": "sign ", "color": [132, 5, 169]}, {"id": 184, "name": "sink ", "color": [202, 115, 244]}, {"id": 185, "name": "sky ", "color": [189, 81, 126]}, {"id": 186, "name": "smoke ", "color": [50, 105, 141]}, {"id": 187, "name": "snow ", "color": [163, 75, 126]}, {"id": 188, "name": "speaker ", "color": [25, 28, 9]}, {"id": 189, "name": "stage ", "color": [57, 175, 211]}, {"id": 190, "name": "stair ", "color": [36, 182, 123]}, {"id": 191, "name": "tent ", "color": [210, 184, 159]}, {"id": 192, "name": "toy ", "color": [139, 14, 196]}, {"id": 193, "name": "track ", "color": [204, 225, 55]}, {"id": 194, "name": "tree ", "color": [145, 64, 92]}, {"id": 195, "name": "truck ", "color": [43, 65, 241]}, {"id": 196, "name": "wall ", "color": [220, 189, 61]}, {"id": 197, "name": "water ", "color": [250, 95, 220]}, {"id": 198, "name": "window ", "color": [176, 117, 245]}, {"id": 199, "name": "wineglass ", "color": [102, 162, 66]}, {"id": 200, "name": "wood ", "color": [100, 60, 45]},]
PASCAL_PARTS_PARTS_ONLY = [ {"id": 1, "name": "aeroplane body", "color": [30, 178, 112]}, {"id": 2, "name": "aeroplane stern", "color": [0, 80, 42]}, {"id": 3, "name": "aeroplane wing", "color": [160, 237, 245]}, {"id": 4, "name": "aeroplane engine", "color": [144, 222, 51]}, {"id": 5, "name": "aeroplane wheel", "color": [155, 121, 20]}, {"id": 6, "name": "bicycle body", "color": [24, 50, 96]}, {"id": 7, "name": "bicycle wheel", "color": [247, 201, 171]}, {"id": 8, "name": "bird torso", "color": [63, 162, 50]}, {"id": 9, "name": "bird head", "color": [143, 18, 27]}, {"id": 10, "name": "bird wing", "color": [204, 34, 128]}, {"id": 11, "name": "bird leg", "color": [31, 37, 39]}, {"id": 12, "name": "boat ", "color": [175, 16, 226]}, {"id": 13, "name": "bottle cap", "color": [31, 13, 221]}, {"id": 14, "name": "bottle body", "color": [120, 248, 33]}, {"id": 15, "name": "bus body", "color": [243, 104, 244]}, {"id": 16, "name": "bus wheel", "color": [247, 196, 104]}, {"id": 17, "name": "bus window", "color": [63, 138, 111]}, {"id": 18, "name": "car body", "color": [200, 176, 116]}, {"id": 19, "name": "car license plate", "color": [79, 146, 205]}, {"id": 20, "name": "car wheel", "color": [231, 126, 229]}, {"id": 21, "name": "car light", "color": [120, 219, 85]}, {"id": 22, "name": "car window", "color": [240, 73, 236]}, {"id": 23, "name": "cat torso", "color": [24, 254, 246]}, {"id": 24, "name": "cat head", "color": [38, 29, 151]}, {"id": 25, "name": "cat leg", "color": [229, 8, 161]}, {"id": 26, "name": "cat tail", "color": [212, 191, 142]}, {"id": 27, "name": "chair ", "color": [235, 90, 210]}, {"id": 28, "name": "cow torso", "color": [72, 26, 132]}, {"id": 29, "name": "cow head", "color": [28, 249, 68]}, {"id": 30, "name": "cow leg", "color": [69, 62, 39]}, {"id": 31, "name": "cow tail", "color": [238, 140, 59]}, {"id": 32, "name": "table ", "color": [73, 170, 102]}, {"id": 33, "name": "dog torso", "color": [51, 140, 200]}, {"id": 34, "name": "dog head", "color": [141, 130, 240]}, {"id": 35, "name": "dog leg", "color": [223, 199, 36]}, {"id": 36, "name": "dog tail", "color": [40, 192, 182]}, {"id": 37, "name": "horse torso", "color": [212, 206, 245]}, {"id": 38, "name": "horse head", "color": [59, 63, 103]}, {"id": 39, "name": "horse leg", "color": [50, 72, 178]}, {"id": 40, "name": "horse tail", "color": [49, 64, 103]}, {"id": 41, "name": "motorbike body", "color": [226, 39, 217]}, {"id": 42, "name": "motorbike wheel", "color": [11, 110, 195]}, {"id": 43, "name": "person torso", "color": [155, 219, 139]}, {"id": 44, "name": "person head", "color": [168, 137, 15]}, {"id": 45, "name": "person lower arm", "color": [187, 194, 167]}, {"id": 46, "name": "person upper arm", "color": [60, 80, 21]}, {"id": 47, "name": "person lower leg", "color": [180, 219, 17]}, {"id": 48, "name": "person upper leg", "color": [240, 249, 227]}, {"id": 49, "name": "pottedplant plant", "color": [191, 176, 151]}, {"id": 50, "name": "pottedplant pot", "color": [13, 133, 225]}, {"id": 51, "name": "sheep torso", "color": [178, 101, 246]}, {"id": 52, "name": "sheep head", "color": [52, 108, 42]}, {"id": 53, "name": "sheep leg", "color": [92, 169, 47]}, {"id": 54, "name": "sofa ", "color": [45, 45, 192]}, {"id": 55, "name": "train body", "color": [168, 7, 178]}, {"id": 56, "name": "tvmonitor frame", "color": [59, 89, 2]}, {"id": 57, "name": "tvmonitor screen", "color": [51, 85, 167]},]
def _get_ctx59_meta(): # Id 0 is reserved for ignore_label, we change ignore_label for 0 # to 255 in our pre-processing, so all ids are shifted by 1. stuff_ids = [k["id"] for k in PASCAL_CTX_59_CATEGORIES] assert len(stuff_ids) == 59, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 91], used in models) to ids in the dataset (used for processing results) stuff_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(stuff_ids)} stuff_classes = [k["name"] for k in PASCAL_CTX_59_CATEGORIES]
ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, } return ret
def register_all_ctx59(root): root = os.path.join(root, "pascal_ctx_d2") meta = _get_ctx59_meta() for name, dirname in [("train", "training"), ("val", "validation")]: image_dir = os.path.join(root, "images", dirname) gt_dir = os.path.join(root, "annotations_ctx59", dirname) name = f"ctx59_sem_seg_{name}" DatasetCatalog.register( name, lambda x=image_dir, y=gt_dir: load_sem_seg( y, x, gt_ext="png", image_ext="jpg", dataset_name="pascal_context_59" ), ) MetadataCatalog.get(name).set( stuff_classes=meta["stuff_classes"][:], thing_dataset_id_to_contiguous_id={}, # to make Mask2Former happy stuff_dataset_id_to_contiguous_id=meta["stuff_dataset_id_to_contiguous_id"], image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=255, )
def _get_pascal21_meta(): # Id 0 is reserved for ignore_label, we change ignore_label for 0 # to 255 in our pre-processing, so all ids are shifted by 1. stuff_ids = [k["id"] for k in PASCAL_VOC_21_CATEGORIES] assert len(stuff_ids) == 21, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 91], used in models) to ids in the dataset (used for processing results) stuff_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(stuff_ids)} stuff_classes = [k["name"] for k in PASCAL_VOC_21_CATEGORIES]
ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, } return ret
def register_all_pascal21(root): root = os.path.join(root, "pascal_voc_d2") meta = _get_pascal21_meta() for name, dirname in [("train", "training"), ("val", "validation")]: image_dir = os.path.join(root, "images", dirname) gt_dir = os.path.join(root, "annotations_pascal21", dirname) name = f"pascal21_sem_seg_{name}" DatasetCatalog.register( name, lambda x=image_dir, y=gt_dir: load_sem_seg( y, x, gt_ext="png", image_ext="jpg", dataset_name="pascal_voc_21" ), ) MetadataCatalog.get(name).set( stuff_classes=meta["stuff_classes"][:], thing_dataset_id_to_contiguous_id={}, # to make Mask2Former happy stuff_dataset_id_to_contiguous_id=meta["stuff_dataset_id_to_contiguous_id"], image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=255, )
def _get_ctx459_meta(): # Id 0 is reserved for ignore_label, we change ignore_label for 0 # to 255 in our pre-processing, so all ids are shifted by 1. stuff_ids = [k["id"] for k in PASCAL_CTX_459_CATEGORIES] assert len(stuff_ids) == 459, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 91], used in models) to ids in the dataset (used for processing results) stuff_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(stuff_ids)} stuff_classes = [k["name"] for k in PASCAL_CTX_459_CATEGORIES]
ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, } return ret
def register_all_ctx459(root): root = os.path.join(root, "pascal_ctx_d2") meta = _get_ctx459_meta() for name, dirname in [("train", "training"), ("val", "validation")]: image_dir = os.path.join(root, "images", dirname) gt_dir = os.path.join(root, "annotations_ctx459", dirname) name = f"ctx459_sem_seg_{name}" DatasetCatalog.register( name, lambda x=image_dir, y=gt_dir: load_sem_seg( y, x, gt_ext="tif", image_ext="jpg", dataset_name="pascal_context_459" ), ) MetadataCatalog.get(name).set( stuff_classes=meta["stuff_classes"][:], thing_dataset_id_to_contiguous_id={}, # to make Mask2Former happy stuff_dataset_id_to_contiguous_id=meta["stuff_dataset_id_to_contiguous_id"], image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=65535, # NOTE: gt is saved in 16-bit TIFF images )
def _get_parts_meta(): # Id 0 is reserved for ignore_label, we change ignore_label for 0 # to 255 in our pre-processing, so all ids are shifted by 1. stuff_ids = [k["id"] for k in PASCAL_PARTS_CATEGORIES] # assert len(stuff_ids) == 459, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 91], used in models) to ids in the dataset (used for processing results) stuff_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(stuff_ids)} stuff_classes = [k["name"] for k in PASCAL_PARTS_CATEGORIES]
ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, } return ret
def _get_parts_only_meta(): # Id 0 is reserved for ignore_label, we change ignore_label for 0 # to 255 in our pre-processing, so all ids are shifted by 1. stuff_ids = [k["id"] for k in PASCAL_PARTS_PARTS_ONLY] # assert len(stuff_ids) == 459, len(stuff_ids)
# For semantic segmentation, this mapping maps from contiguous stuff id # (in [0, 91], used in models) to ids in the dataset (used for processing results) stuff_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(stuff_ids)} stuff_classes = [k["name"] for k in PASCAL_PARTS_PARTS_ONLY]
ret = { "stuff_dataset_id_to_contiguous_id": stuff_dataset_id_to_contiguous_id, "stuff_classes": stuff_classes, } return ret
def register_all_pascal_parts_only(root): data_root = root root = os.path.join(root, "pascal_parts") meta = _get_parts_only_meta() for name, dirname in [ ("train", "training_merged"), ("val", "validation_merged"), ("test", "test_merged"), ]: image_dir = os.path.join(data_root, "VOCdevkit/VOC2010/JPEGImages") gt_dir = os.path.join(root, "labels", dirname) name = f"pascal_parts_merged_{name}" DatasetCatalog.register( name, lambda x=image_dir, y=gt_dir: load_sem_seg( y, x, gt_ext="tif", image_ext="jpg", dataset_name="pascal_parts_merged" ), ) MetadataCatalog.get(name).set( stuff_classes=meta["stuff_classes"][:], thing_dataset_id_to_contiguous_id={}, # to make Mask2Former happy stuff_dataset_id_to_contiguous_id=meta["stuff_dataset_id_to_contiguous_id"], image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=0, # NOTE: gt is saved in 16-bit TIFF images )
PASCAL_LABEL_PART_GROUP = { 1: 1, 2: 2, 3: 3, 4: 2, 5: 4, 6: 5, 7: 6, 8: 7, 9: 6, 10: 6, 11: 6, 12: 8, 13: 9, 14: 9, 15: 10, 16: 11, 17: 11, 18: 8, 19: 12, 20: 14, 21: 13, 22: 15, 23: 15, 24: 15, 25: 15, 26: 15, 27: 15, 28: 15, 29: 15, 30: 15, 31: 15, 32: 16, 33: 15, 34: 17, 35: 18, 36: 18, 37: 18, 38: 19, 39: 19, 40: 18, 41: 20, 42: 21, 43: 22, 44: 23, 45: 24, 46: 24, 47: 24, 48: 24, 49: 23, 50: 25, 51: 25, 52: 26, 53: 27, 54: 28, 55: 29, 56: 29, 57: 29, 58: 29, 59: 29, 60: 28, 61: 30, 62: 31, 63: 32, 64: 33, 65: 34, 66: 34, 67: 34, 68: 34, 69: 33, 70: 35, 71: 35, 72: 36, 73: 34, 74: 37, 75: 38, 76: 38, 77: 38, 78: 38, 79: 37, 80: 37, 81: 39, 82: 40, 83: 41, 84: 42, 85: 41, 86: 41, 87: 41, 88: 43, 89: 44, 90: 44, 91: 44, 92: 44, 93: 44, 94: 44, 95: 44, 96: 43, 97: 43, 98: 45, 99: 46, 100: 45, 101: 47, 102: 48, 103: 47, 104: 49, 105: 50, 106: 51, 107: 52, 108: 52, 109: 52, 110: 52, 111: 52, 112: 51, 113: 53, 114: 51, 115: 54, 116: 55, 117: 55, 118: 55, 119: 55, 120: 56, 121: 57,}
def register_all_pascal_parts(root): data_root = root register_all_pascal_parts_only(data_root) root = os.path.join(root, "pascal_parts") meta = _get_parts_meta() for name, dirname in [("train", "training"), ("val", "validation"), ("test", "test_pano")]: image_dir = os.path.join(data_root, "VOCdevkit/VOC2010/JPEGImages") gt_dir = os.path.join(root, "labels", dirname) name = f"pascal_parts_{name}" DatasetCatalog.register( name, lambda x=image_dir, y=gt_dir: load_sem_seg(y, x, gt_ext="tif", image_ext="jpg") ) MetadataCatalog.get(name).set( stuff_classes=meta["stuff_classes"][:], thing_dataset_id_to_contiguous_id={}, # to make Mask2Former happy stuff_dataset_id_to_contiguous_id=meta["stuff_dataset_id_to_contiguous_id"], image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", label_group=PASCAL_LABEL_PART_GROUP, # ignore_label=0, # NOTE: gt is saved in 16-bit TIFF images ignore_label=255, # NOTE: gt is saved in 16-bit TIFF images )
_PREDEFINED_SPLITS_PASCALVOCPART = {}_PREDEFINED_SPLITS_PASCALVOCPART["pascalvocpart"] = { "pascalvocpart": ( "VOCdevkit/VOC2010/JPEGImages", "pascal_parts/pascalvocpart_training_instance.json", ), "pascalvocpart_train": ( "VOCdevkit/VOC2010/JPEGImages", "pascal_parts/pascalvocpart_training_instance.json", ), "pascalvocpart_val": ( "VOCdevkit/VOC2010/JPEGImages", "pascal_parts/pascalvocpart_validation_instance.json", ),}
def _get_builtin_metadata(dataset_name): return _get_pascalvocpart_metadata([])
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_pascalvocpart_metadata(categories): if len(categories) == 0: return {} id_to_name = {x["id"]: x["name"] for x in categories} thing_dataset_id_to_contiguous_id = {i: i for i in range(len(categories))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
def register_all_pascalvocpart(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_PASCALVOCPART.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
# register_all_ctx59(os.getenv("DETECTRON2_DATASETS", "datasets"))# register_all_pascal21(os.getenv("DETECTRON2_DATASETS", "datasets"))# register_all_ctx459(os.getenv("DETECTRON2_DATASETS", "datasets"))
# True for open source;# Internally at fb, we register them elsewhereif __name__.endswith(".pascal_voc_external"): # Assume pre-defined datasets live in `./datasets`. _root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets")) # register_all_pascal_parts(_root) register_all_pascalvocpart(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import loggingimport os
from .coco import custom_register_coco_instances
logger = logging.getLogger(__name__)
def _get_builtin_metadata(dataset_name): return _get_phrasecut_metadata([])
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_phrasecut_metadata(categories): if len(categories) == 0: return {} id_to_name = {x["id"]: x["name"] for x in categories} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(categories))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_PHRASECUT = {}_PREDEFINED_SPLITS_PHRASECUT["phrasecut"] = { "phrasecut": ( "phrasecut/images", "phrasecut/phrasecut.json", ), "phrasecut_train": ( "phrasecut/images", "phrasecut/phrasecut_train.json", ), "phrasecut_val": ( "phrasecut/images", "phrasecut/phrasecut_val.json", ),}
def register_all_phrasecut(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_PHRASECUT.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
# True for open source;# Internally at fb, we register them elsewhereif __name__.endswith(".phrasecut"): # Assume pre-defined datasets live in `./datasets`. _root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets")) register_all_phrasecut(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337import contextlibimport ioimport loggingimport os
import numpy as npimport pycocotools.mask as mask_utilfrom PIL import Image
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.structures import Boxes, BoxMode, PolygonMasks, RotatedBoxesfrom detectron2.utils.file_io import PathManagerfrom fvcore.common.timer import Timerfrom iopath.common.file_io import file_lock
"""This file contains functions to parse COCO-format annotations into dicts in "Detectron2 format"."""
logger = logging.getLogger(__name__)
__all__ = ["load_refcoco_json", "convert_to_coco_json", "register_refcoco"]
REFCOCO_CATEGORIES = [ {"color": [220, 20, 60], "isthing": 1, "id": 1, "name": "object"}] # only one class for visual grounding
def _get_refcoco_meta(): thing_ids = [k["id"] for k in REFCOCO_CATEGORIES if k["isthing"] == 1] thing_colors = [k["color"] for k in REFCOCO_CATEGORIES if k["isthing"] == 1] assert len(thing_ids) == 1, len(thing_ids)
thing_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(thing_ids)} thing_classes = [k["name"] for k in REFCOCO_CATEGORIES if k["isthing"] == 1] ret = { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, "thing_colors": thing_colors, } return ret
def load_refcoco_json(json_file, image_root, dataset_name=None, extra_annotation_keys=None): """ Load a json file with COCO's instances annotation format. Currently supports instance detection, instance segmentation, and person keypoints annotations.
Args: json_file (str): full path to the json file in COCO instances annotation format. image_root (str or path-like): the directory where the images in this json file exists. dataset_name (str or None): the name of the dataset (e.g., coco_2017_train). When provided, this function will also do the following:
* Put "thing_classes" into the metadata associated with this dataset. * Map the category ids into a contiguous range (needed by standard dataset format), and add "thing_dataset_id_to_contiguous_id" to the metadata associated with this dataset.
This option should usually be provided, unless users need to load the original json content and apply more processing manually. extra_annotation_keys (list[str]): list of per-annotation keys that should also be loaded into the dataset dict (besides "iscrowd", "bbox", "keypoints", "category_id", "segmentation"). The values for these keys will be returned as-is. For example, the densepose annotations are loaded in this way.
Returns: list[dict]: a list of dicts in Detectron2 standard dataset dicts format (See `Using Custom Datasets </tutorials/datasets.html>`_ ) when `dataset_name` is not None. If `dataset_name` is None, the returned `category_ids` may be incontiguous and may not conform to the Detectron2 standard format.
Notes: 1. This function does not read the image files. The results do not have the "image" field. """ from pycocotools.coco import COCO
timer = Timer() json_file = PathManager.get_local_path(json_file) with contextlib.redirect_stdout(io.StringIO()): coco_api = COCO(json_file) if timer.seconds() > 1: logger.info("Loading {} takes {:.2f} seconds.".format(json_file, timer.seconds()))
id_map = None if dataset_name is not None: meta = MetadataCatalog.get(dataset_name) cat_ids = sorted(coco_api.getCatIds()) cats = coco_api.loadCats(cat_ids) # The categories in a custom json file may not be sorted. thing_classes = [c["name"] for c in sorted(cats, key=lambda x: x["id"])] meta.thing_classes = thing_classes
# In COCO, certain category ids are artificially removed, # and by convention they are always ignored. # We deal with COCO's id issue and translate # the category ids to contiguous ids in [0, 80).
# It works by looking at the "categories" field in the json, therefore # if users' own json also have incontiguous ids, we'll # apply this mapping as well but print a warning. if not (min(cat_ids) == 1 and max(cat_ids) == len(cat_ids)): if "coco" not in dataset_name: logger.warning( """Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.""" ) id_map = {v: i for i, v in enumerate(cat_ids)} meta.thing_dataset_id_to_contiguous_id = id_map
cat_ids = cat_ids + list(range(max(cat_ids) + 1, 100000)) id_map = {v: i for i, v in enumerate(cat_ids)}
# sort indices for reproducible results img_ids = sorted(coco_api.imgs.keys()) # imgs is a list of dicts, each looks something like: # {'license': 4, # 'url': 'http://farm6.staticflickr.com/5454/9413846304_881d5e5c3b_z.jpg', # 'file_name': 'COCO_val2014_000000001268.jpg', # 'height': 427, # 'width': 640, # 'date_captured': '2013-11-17 05:57:24', # 'id': 1268} imgs = coco_api.loadImgs(img_ids) # anns is a list[list[dict]], where each dict is an annotation # record for an object. The inner list enumerates the objects in an image # and the outer list enumerates over images. Example of anns[0]: # [{'segmentation': [[192.81, # 247.09, # ... # 219.03, # 249.06]], # 'area': 1035.749, # 'iscrowd': 0, # 'image_id': 1268, # 'bbox': [192.81, 224.8, 74.73, 33.43], # 'category_id': 16, # 'id': 42986}, # ...] anns = [coco_api.imgToAnns[img_id] for img_id in img_ids] total_num_valid_anns = sum([len(x) for x in anns]) total_num_anns = len(coco_api.anns) if total_num_valid_anns < total_num_anns: logger.warning( f"{json_file} contains {total_num_anns} annotations, but only " f"{total_num_valid_anns} of them match to images in the file." )
if "minival" not in json_file: # The popular valminusminival & minival annotations for COCO2014 contain this bug. # However the ratio of buggy annotations there is tiny and does not affect accuracy. # Therefore we explicitly white-list them. ann_ids = [ann["id"] for anns_per_image in anns for ann in anns_per_image] assert len(set(ann_ids)) == len(ann_ids), "Annotation ids in '{}' are not unique!".format( json_file )
imgs_anns = list(zip(imgs, anns)) logger.info("Loaded {} images in COCO format from {}".format(len(imgs_anns), json_file))
dataset_dicts = []
ann_keys = ["iscrowd", "bbox", "keypoints", "category_id"] + (extra_annotation_keys or [])
num_instances_without_valid_segmentation = 0
for (img_dict, anno_dict_list) in imgs_anns: record = {} record["file_name"] = os.path.join(image_root, img_dict["file_name"]) record["height"] = img_dict["height"] record["width"] = img_dict["width"] if "expressions" in img_dict: record["expressions"] = img_dict["expressions"] image_id = record["image_id"] = img_dict["id"]
objs = [] for anno in anno_dict_list: # Check that the image_id in this annotation is the same as # the image_id we're looking at. # This fails only when the data parsing logic or the annotation file is buggy.
# The original COCO valminusminival2014 & minival2014 annotation files # actually contains bugs that, together with certain ways of using COCO API, # can trigger this assertion. assert anno["image_id"] == image_id
assert anno.get("ignore", 0) == 0, '"ignore" in COCO json file is not supported.'
obj = {key: anno[key] for key in ann_keys if key in anno} if "bbox" in obj and len(obj["bbox"]) == 0: raise ValueError( f"One annotation of image {image_id} contains empty 'bbox' value! " "This json does not have valid COCO format." )
segm = anno.get("segmentation", None) if segm: # either list[list[float]] or dict(RLE) if isinstance(segm, dict): if isinstance(segm["counts"], list): # convert to compressed RLE segm = mask_util.frPyObjects(segm, *segm["size"]) else: # filter out invalid polygons (< 3 points) segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6] if len(segm) == 0: num_instances_without_valid_segmentation += 1 continue # ignore this instance obj["segmentation"] = segm
keypts = anno.get("keypoints", None) if keypts: # list[int] for idx, v in enumerate(keypts): if idx % 3 != 2: # COCO's segmentation coordinates are floating points in [0, H or W], # but keypoint coordinates are integers in [0, H-1 or W-1] # Therefore we assume the coordinates are "pixel indices" and # add 0.5 to convert to floating point coordinates. keypts[idx] = v + 0.5 obj["keypoints"] = keypts
phrase = anno.get("phrase", None) if phrase: obj["phrase"] = phrase obj["bbox_mode"] = BoxMode.XYWH_ABS if id_map: annotation_category_id = obj["category_id"] try: obj["category_id"] = id_map[annotation_category_id] except KeyError as e: raise KeyError( f"Encountered category_id={annotation_category_id} " "but this id does not exist in 'categories' of the json file." ) from e objs.append(obj) record["annotations"] = objs record["task"] = "grounding" dataset_dicts.append(record)
if num_instances_without_valid_segmentation > 0: logger.warning( "Filtered out {} instances without valid segmentation. ".format( num_instances_without_valid_segmentation ) + "There might be issues in your dataset generation process. Please " "check https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html carefully" ) return dataset_dicts
def register_refcoco(name, metadata, json_file, image_root): """ Register a dataset in COCO's json annotation format for instance detection, instance segmentation and keypoint detection. (i.e., Type 1 and 2 in http://cocodataset.org/#format-data. `instances*.json` and `person_keypoints*.json` in the dataset).
This is an example of how to register a new dataset. You can do something similar to this function, to register new datasets.
Args: name (str): the name that identifies a dataset, e.g. "coco_2014_train". metadata (dict): extra metadata associated with this dataset. You can leave it as an empty dict. json_file (str): path to the json instance annotation file. image_root (str or path-like): directory which contains all the images. """ assert isinstance(name, str), name assert isinstance(json_file, (str, os.PathLike)), json_file assert isinstance(image_root, (str, os.PathLike)), image_root # 1. register a function which returns dicts DatasetCatalog.register(name, lambda: load_refcoco_json(json_file, image_root, name))
# 2. Optionally, add metadata about this dataset, # since they might be useful in evaluation, visualization or logging MetadataCatalog.get(name).set( json_file=json_file, image_root=image_root, evaluator_type="refcoco", **metadata )
# ==== Predefined splits for REFCOCO datasets ===========_PREDEFINED_SPLITS_REFCOCO = { # refcoco "refcoco-unc-train": ("coco/train2014", "SeqTR/refcoco-unc/instances_cocofied_train.json"), "refcoco-unc-val": ("coco/train2014", "SeqTR/refcoco-unc/instances_cocofied_val.json"), "refcoco-unc-testA": ("coco/train2014", "SeqTR/refcoco-unc/instances_cocofied_testA.json"), "refcoco-unc-testB": ("coco/train2014", "SeqTR/refcoco-unc/instances_cocofied_testB.json"), # refcocog "refcocog-umd-train": ("coco/train2014", "SeqTR/refcocog-umd/instances_cocofied_train.json"), "refcocog-umd-val": ("coco/train2014", "SeqTR/refcocog-umd/instances_cocofied_val.json"), "refcocog-umd-test": ("coco/train2014", "SeqTR/refcocog-umd/instances_cocofied_test.json"), "refcocog-google-val": ("coco/train2014", "SeqTR/refcocog-google/instances_cocofied_val.json"), # refcoco+ "refcocoplus-unc-train": ( "coco/train2014", "SeqTR/refcocoplus-unc/instances_cocofied_train.json", ), "refcocoplus-unc-val": ("coco/train2014", "SeqTR/refcocoplus-unc/instances_cocofied_val.json"), "refcocoplus-unc-testA": ( "coco/train2014", "SeqTR/refcocoplus-unc/instances_cocofied_testA.json", ), "refcocoplus-unc-testB": ( "coco/train2014", "SeqTR/refcocoplus-unc/instances_cocofied_testB.json", ), # mixed "refcoco-mixed": ("coco/train2014", "SeqTR/refcoco-mixed/instances_cocofied_train.json"), "refcoco-mixed-filter": ( "coco/train2014", "SeqTR/refcoco-mixed/instances_cocofied_train_filter.json", ), "refcoco-mixed_group-by-image": ( "coco/train2014", "SeqTR/refcoco-mixed_group-by-image/instances_cocofied_train.json", ),}
def register_all_refcoco(root): for key, (image_root, json_file) in _PREDEFINED_SPLITS_REFCOCO.items(): # Assume pre-defined datasets live in `./datasets`. register_refcoco( key, _get_refcoco_meta(), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".refcoco"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_refcoco(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277# --------------------------------------------------------# X-Decoder -- Generalized Decoding for Pixel, Image, and Language# Copyright (c) 2022 Microsoft# Licensed under The MIT License [see LICENSE for details]# Modified by Xueyan Zou (xueyan@cs.wisc.edu)# --------------------------------------------------------# Copyright (c) Facebook, Inc. and its affiliates.import jsonimport osfrom collections import namedtuple
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.utils.file_io import PathManager
Label = namedtuple( "Label", [ "name", # The identifier of this label, e.g. 'car', 'person', ... . # We use them to uniquely name a class "id", # An integer ID that is associated with this label. # The IDs are used to represent the label in ground truth images An ID # of -1 means that this label does not have an ID and thus is ignored # when creating ground truth images (e.g. license plate). Do not modify # these IDs, since exactly these IDs are expected by the evaluation # server. "trainId", # Feel free to modify these IDs as suitable for your method. Then # create ground truth images with train IDs, using the tools provided # in the 'preparation' folder. However, make sure to validate or submit # results to our evaluation server using the regular IDs above! For # trainIds, multiple labels might have the same ID. Then, these labels # are mapped to the same class in the ground truth images. For the # inverse mapping, we use the label that is defined first in the list # below. For example, mapping all void-type classes to the same ID in # training, might make sense for some approaches. Max value is 255! "category", # The name of the category that this label belongs to "categoryId", # The ID of this category. Used to create ground truth images # on category level. "hasInstances", # Whether this label distinguishes between single instances or not "ignoreInEval", # Whether pixels having this class as ground truth label are ignored # during evaluations or not "color", # The color of this label ],)
# Our extended list of label types. Our train id is compatible with CityscapesBDD_CATEGORIES = [ # name id trainId category catId # hasInstances ignoreInEval color # Label("unlabeled", 0, 255, "void", 0, False, True, (0, 0, 0)), Label("dynamic", 1, 255, "void", 0, False, True, (111, 74, 0)), Label("ego vehicle", 2, 255, "void", 0, False, True, (0, 0, 0)), Label("ground", 3, 255, "void", 0, False, True, (81, 0, 81)), Label("static", 4, 255, "void", 0, False, True, (0, 0, 0)), Label("parking", 5, 255, "flat", 1, False, True, (250, 170, 160)), Label("rail track", 6, 255, "flat", 1, False, True, (230, 150, 140)), Label("road", 7, 0, "flat", 1, False, False, (128, 64, 128)), Label("sidewalk", 8, 1, "flat", 1, False, False, (244, 35, 232)), Label("bridge", 9, 255, "construction", 2, False, True, (150, 100, 100)), Label("building", 10, 2, "construction", 2, False, False, (70, 70, 70)), Label("fence", 11, 4, "construction", 2, False, False, (190, 153, 153)), Label("garage", 12, 255, "construction", 2, False, True, (180, 100, 180)), Label("guard rail", 13, 255, "construction", 2, False, True, (180, 165, 180)), Label("tunnel", 14, 255, "construction", 2, False, True, (150, 120, 90)), Label("wall", 15, 3, "construction", 2, False, False, (102, 102, 156)), Label("banner", 16, 255, "object", 3, False, True, (250, 170, 100)), Label("billboard", 17, 255, "object", 3, False, True, (220, 220, 250)), Label("lane divider", 18, 255, "object", 3, False, True, (255, 165, 0)), Label("parking sign", 19, 255, "object", 3, False, False, (220, 20, 60)), Label("pole", 20, 5, "object", 3, False, False, (153, 153, 153)), Label("polegroup", 21, 255, "object", 3, False, True, (153, 153, 153)), Label("street light", 22, 255, "object", 3, False, True, (220, 220, 100)), Label("traffic cone", 23, 255, "object", 3, False, True, (255, 70, 0)), Label("traffic device", 24, 255, "object", 3, False, True, (220, 220, 220)), Label("traffic light", 25, 6, "object", 3, False, False, (250, 170, 30)), Label("traffic sign", 26, 7, "object", 3, False, False, (220, 220, 0)), Label( "traffic sign frame", 27, 255, "object", 3, False, True, (250, 170, 250), ), Label("terrain", 28, 9, "nature", 4, False, False, (152, 251, 152)), Label("vegetation", 29, 8, "nature", 4, False, False, (107, 142, 35)), Label("sky", 30, 10, "sky", 5, False, False, (70, 130, 180)), Label("person", 31, 11, "human", 6, True, False, (220, 20, 60)), Label("rider", 32, 12, "human", 6, True, False, (255, 0, 0)), Label("bicycle", 33, 18, "vehicle", 7, True, False, (119, 11, 32)), Label("bus", 34, 15, "vehicle", 7, True, False, (0, 60, 100)), Label("car", 35, 13, "vehicle", 7, True, False, (0, 0, 142)), Label("caravan", 36, 255, "vehicle", 7, True, True, (0, 0, 90)), Label("motorcycle", 37, 17, "vehicle", 7, True, False, (0, 0, 230)), Label("trailer", 38, 255, "vehicle", 7, True, True, (0, 0, 110)), Label("train", 39, 16, "vehicle", 7, True, False, (0, 80, 100)), Label("truck", 40, 14, "vehicle", 7, True, False, (0, 0, 70)),]
BDD_COLORS = [k.color for k in BDD_CATEGORIES]
MetadataCatalog.get("bdd100k_pano_val").set( stuff_colors=BDD_COLORS[:],)
def load_bdd_panoptic_json(json_file, image_dir, gt_dir, meta): """ Args: image_dir (str): path to the raw dataset. e.g., "~/coco/train2017". gt_dir (str): path to the raw annotations. e.g., "~/coco/panoptic_train2017". json_file (str): path to the json file. e.g., "~/coco/annotations/panoptic_train2017.json". Returns: list[dict]: a list of dicts in Detectron2 standard format. (See `Using Custom Datasets </tutorials/datasets.html>`_ ) """
def _convert_category_id(segment_info, meta): if segment_info["category_id"] in meta["thing_dataset_id_to_contiguous_id"]: segment_info["category_id"] = meta["thing_dataset_id_to_contiguous_id"][ segment_info["category_id"] ] segment_info["isthing"] = True else: segment_info["category_id"] = meta["stuff_dataset_id_to_contiguous_id"][ segment_info["category_id"] ] segment_info["isthing"] = False return segment_info
with PathManager.open(json_file) as f: json_info = json.load(f)
ret = [] for ann in json_info["annotations"]: image_id = ann["image_id"] # TODO: currently we assume image and label has the same filename but # different extension, and images have extension ".jpg" for COCO. Need # to make image extension a user-provided argument if we extend this # function to support other COCO-like datasets. file_name = ann["file_name"].replace("png", "jpg")
image_file = os.path.join(image_dir, file_name) label_file = os.path.join(gt_dir, ann["file_name"])
segments_info = [_convert_category_id(x, meta) for x in ann["segments_info"]] ret.append( { "file_name": image_file, "image_id": image_id, "pan_seg_file_name": label_file, "segments_info": segments_info, } ) assert len(ret), f"No images found in {image_dir}!" assert PathManager.isfile(ret[0]["file_name"]), ret[0]["file_name"] assert PathManager.isfile(ret[0]["pan_seg_file_name"]), ret[0]["pan_seg_file_name"] return ret
def register_bdd_panoptic( name, metadata, image_root, panoptic_root, panoptic_json,): """ Register a "standard" version of ADE20k panoptic segmentation dataset named `name`. The dictionaries in this registered dataset follows detectron2's standard format. Hence it's called "standard". Args: name (str): the name that identifies a dataset, e.g. "ade20k_panoptic_train" metadata (dict): extra metadata associated with this dataset. image_root (str): directory which contains all the images panoptic_root (str): directory which contains panoptic annotation images in COCO format panoptic_json (str): path to the json panoptic annotation file in COCO format sem_seg_root (none): not used, to be consistent with `register_coco_panoptic_separated`. instances_json (str): path to the json instance annotation file """ panoptic_name = name DatasetCatalog.register( panoptic_name, lambda: load_bdd_panoptic_json(panoptic_json, image_root, panoptic_root, metadata), ) MetadataCatalog.get(panoptic_name).set( panoptic_root=panoptic_root, image_root=image_root, panoptic_json=panoptic_json, evaluator_type="bdd_panoptic_pano", ignore_label=0, label_divisor=1000, **metadata, )
_PREDEFINED_SPLITS_SCANNET_PANOPTIC = { "bdd10k_40_panoptic_val": ( "bdd100k/images/10k/val", "bdd100k/labels/pan_seg/coco_pano/val", "bdd100k/labels/pan_seg/meta/coco_val.json", ),}
def get_metadata(): meta = {} # The following metadata maps contiguous id from [0, #thing categories + # #stuff categories) to their names and colors. We have to replica of the # same name and color under "thing_*" and "stuff_*" because the current # visualization function in D2 handles thing and class classes differently # due to some heuristic used in Panoptic FPN. We keep the same naming to # enable reusing existing visualization functions. thing_classes = [k.name for k in BDD_CATEGORIES if k.hasInstances == True] thing_colors = [k.color for k in BDD_CATEGORIES if k.hasInstances == True] stuff_classes = [k.name for k in BDD_CATEGORIES] stuff_colors = [k.color for k in BDD_CATEGORIES]
meta["thing_classes"] = thing_classes meta["thing_colors"] = thing_colors meta["stuff_classes"] = stuff_classes meta["stuff_colors"] = stuff_colors
# Convert category id for training: # category id: like semantic segmentation, it is the class id for each # pixel. Since there are some classes not used in evaluation, the category # id is not always contiguous and thus we have two set of category ids: # - original category id: category id in the original dataset, mainly # used for evaluation. # - contiguous category id: [0, #classes), in order to train the linear # softmax classifier. thing_dataset_id_to_contiguous_id = {} stuff_dataset_id_to_contiguous_id = {}
for i, cat in enumerate(BDD_CATEGORIES): if cat.hasInstances: thing_dataset_id_to_contiguous_id[cat.id] = i # else: # stuff_dataset_id_to_contiguous_id[cat["id"]] = i
# in order to use sem_seg evaluator stuff_dataset_id_to_contiguous_id[cat.id] = i
meta["thing_dataset_id_to_contiguous_id"] = thing_dataset_id_to_contiguous_id meta["stuff_dataset_id_to_contiguous_id"] = stuff_dataset_id_to_contiguous_id return meta
def register_all_bdd_panoptic(root): metadata = get_metadata() for ( prefix, (image_root, panoptic_root, panoptic_json), ) in _PREDEFINED_SPLITS_SCANNET_PANOPTIC.items(): # The "standard" version of COCO panoptic segmentation dataset, # e.g. used by Panoptic-DeepLab register_bdd_panoptic( prefix, metadata, os.path.join(root, image_root), os.path.join(root, panoptic_root), os.path.join(root, panoptic_json), )
if __name__.endswith(".register_bdd100k_panoseg"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_bdd_panoptic(_root)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798# --------------------------------------------------------# X-Decoder -- Generalized Decoding for Pixel, Image, and Language# Copyright (c) 2022 Microsoft# Licensed under The MIT License [see LICENSE for details]# Modified by Xueyan Zou (xueyan@cs.wisc.edu)# --------------------------------------------------------# Copyright (c) Facebook, Inc. and its affiliates.import globimport osfrom typing import List, Tuple, Union
import numpy as np
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.utils.file_io import PathManager
BDD_SEM = [ "road", "sidewalk", "building", "wall", "fence", "pole", "traffic light", "traffic sign", "vegetation", "terrain", "sky", "person", "rider", "car", "truck", "bus", "train", "motorcycle", "bicycle",]
__all__ = ["load_scannet_instances", "register_scannet_context"]
def load_bdd_instances( name: str, dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]): """ Load BDD annotations to Detectron2 format.
Args: dirname: Contain "Annotations", "ImageSets", "JPEGImages" split (str): one of "train", "test", "val", "trainval" class_names: list or tuple of class names """ img_folder = os.path.join(dirname, "images", "10k", split) img_pths = sorted(glob.glob(os.path.join(img_folder, "*.jpg")))
sem_folder = os.path.join(dirname, "labels", "sem_seg", "masks", split) sem_pths = sorted(glob.glob(os.path.join(sem_folder, "*.png")))
assert len(img_pths) == len(sem_pths)
dicts = [] for img_pth, sem_pth in zip(img_pths, sem_pths): r = { "file_name": img_pth, "sem_seg_file_name": sem_pth, "image_id": img_pth.split("/")[-1].split(".")[0], } dicts.append(r) return dicts
def register_bdd_context(name, dirname, split, class_names=BDD_SEM): DatasetCatalog.register(name, lambda: load_bdd_instances(name, dirname, split, class_names)) MetadataCatalog.get(name).set( stuff_classes=class_names, dirname=dirname, split=split, ignore_label=[255], thing_dataset_id_to_contiguous_id={}, class_offset=0, keep_sem_bgd=False, )
def register_all_bdd_semseg(root): SPLITS = [ ("bdd10k_val_sem_seg", "bdd100k", "val"), ]
for name, dirname, split in SPLITS: register_bdd_context(name, os.path.join(root, dirname), split) MetadataCatalog.get(name).evaluator_type = "sem_seg"
if __name__.endswith(".register_bdd100k_semseg"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DATASET", "datasets") register_all_bdd_semseg(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587# Copyright (c) Facebook, Inc. and its affiliates.import os
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets import load_sem_seg
PASCALCONTEX59_NAMES = ( "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "table", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor", "bag", "bed", "bench", "book", "building", "cabinet", "ceiling", "cloth", "computer", "cup", "door", "fence", "floor", "flower", "food", "grass", "ground", "keyboard", "light", "mountain", "mouse", "curtain", "platform", "sign", "plate", "road", "rock", "shelves", "sidewalk", "sky", "snow", "bedclothes", "track", "tree", "truck", "wall", "water", "window", "wood",)
PASCALCONTEX459_NAMES = ( "accordion", "aeroplane", "air conditioner", "antenna", "artillery", "ashtray", "atrium", "baby carriage", "bag", "ball", "balloon", "bamboo weaving", "barrel", "baseball bat", "basket", "basketball backboard", "bathtub", "bed", "bedclothes", "beer", "bell", "bench", "bicycle", "binoculars", "bird", "bird cage", "bird feeder", "bird nest", "blackboard", "board", "boat", "bone", "book", "bottle", "bottle opener", "bowl", "box", "bracelet", "brick", "bridge", "broom", "brush", "bucket", "building", "bus", "cabinet", "cabinet door", "cage", "cake", "calculator", "calendar", "camel", "camera", "camera lens", "can", "candle", "candle holder", "cap", "car", "card", "cart", "case", "casette recorder", "cash register", "cat", "cd", "cd player", "ceiling", "cell phone", "cello", "chain", "chair", "chessboard", "chicken", "chopstick", "clip", "clippers", "clock", "closet", "cloth", "clothes tree", "coffee", "coffee machine", "comb", "computer", "concrete", "cone", "container", "control booth", "controller", "cooker", "copying machine", "coral", "cork", "corkscrew", "counter", "court", "cow", "crabstick", "crane", "crate", "cross", "crutch", "cup", "curtain", "cushion", "cutting board", "dais", "disc", "disc case", "dishwasher", "dock", "dog", "dolphin", "door", "drainer", "dray", "drink dispenser", "drinking machine", "drop", "drug", "drum", "drum kit", "duck", "dumbbell", "earphone", "earrings", "egg", "electric fan", "electric iron", "electric pot", "electric saw", "electronic keyboard", "engine", "envelope", "equipment", "escalator", "exhibition booth", "extinguisher", "eyeglass", "fan", "faucet", "fax machine", "fence", "ferris wheel", "fire extinguisher", "fire hydrant", "fire place", "fish", "fish tank", "fishbowl", "fishing net", "fishing pole", "flag", "flagstaff", "flame", "flashlight", "floor", "flower", "fly", "foam", "food", "footbridge", "forceps", "fork", "forklift", "fountain", "fox", "frame", "fridge", "frog", "fruit", "funnel", "furnace", "game controller", "game machine", "gas cylinder", "gas hood", "gas stove", "gift box", "glass", "glass marble", "globe", "glove", "goal", "grandstand", "grass", "gravestone", "ground", "guardrail", "guitar", "gun", "hammer", "hand cart", "handle", "handrail", "hanger", "hard disk drive", "hat", "hay", "headphone", "heater", "helicopter", "helmet", "holder", "hook", "horse", "horse-drawn carriage", "hot-air balloon", "hydrovalve", "ice", "inflator pump", "ipod", "iron", "ironing board", "jar", "kart", "kettle", "key", "keyboard", "kitchen range", "kite", "knife", "knife block", "ladder", "ladder truck", "ladle", "laptop", "leaves", "lid", "life buoy", "light", "light bulb", "lighter", "line", "lion", "lobster", "lock", "machine", "mailbox", "mannequin", "map", "mask", "mat", "match book", "mattress", "menu", "metal", "meter box", "microphone", "microwave", "mirror", "missile", "model", "money", "monkey", "mop", "motorbike", "mountain", "mouse", "mouse pad", "musical instrument", "napkin", "net", "newspaper", "oar", "ornament", "outlet", "oven", "oxygen bottle", "pack", "pan", "paper", "paper box", "paper cutter", "parachute", "parasol", "parterre", "patio", "pelage", "pen", "pen container", "pencil", "person", "photo", "piano", "picture", "pig", "pillar", "pillow", "pipe", "pitcher", "plant", "plastic", "plate", "platform", "player", "playground", "pliers", "plume", "poker", "poker chip", "pole", "pool table", "postcard", "poster", "pot", "pottedplant", "printer", "projector", "pumpkin", "rabbit", "racket", "radiator", "radio", "rail", "rake", "ramp", "range hood", "receiver", "recorder", "recreational machines", "remote control", "road", "robot", "rock", "rocket", "rocking horse", "rope", "rug", "ruler", "runway", "saddle", "sand", "saw", "scale", "scanner", "scissors", "scoop", "screen", "screwdriver", "sculpture", "scythe", "sewer", "sewing machine", "shed", "sheep", "shell", "shelves", "shoe", "shopping cart", "shovel", "sidecar", "sidewalk", "sign", "signal light", "sink", "skateboard", "ski", "sky", "sled", "slippers", "smoke", "snail", "snake", "snow", "snowmobiles", "sofa", "spanner", "spatula", "speaker", "speed bump", "spice container", "spoon", "sprayer", "squirrel", "stage", "stair", "stapler", "stick", "sticky note", "stone", "stool", "stove", "straw", "stretcher", "sun", "sunglass", "sunshade", "surveillance camera", "swan", "sweeper", "swim ring", "swimming pool", "swing", "switch", "table", "tableware", "tank", "tap", "tape", "tarp", "telephone", "telephone booth", "tent", "tire", "toaster", "toilet", "tong", "tool", "toothbrush", "towel", "toy", "toy car", "track", "train", "trampoline", "trash bin", "tray", "tree", "tricycle", "tripod", "trophy", "truck", "tube", "turtle", "tvmonitor", "tweezers", "typewriter", "umbrella", "unknown", "vacuum cleaner", "vending machine", "video camera", "video game console", "video player", "video tape", "violin", "wakeboard", "wall", "wallet", "wardrobe", "washing machine", "watch", "water", "water dispenser", "water pipe", "water skate board", "watermelon", "whale", "wharf", "wheel", "wheelchair", "window", "window blinds", "wineglass", "wire", "wood", "wool",)
def _get_voc_meta(cat_list): ret = { "stuff_classes": cat_list, } return ret
def register_pascal_context_59(root): root = os.path.join(root, "VOCdevkit/VOC2010") meta = _get_voc_meta(PASCALCONTEX59_NAMES) for name, image_dirname, sem_seg_dirname in [ ("val", "JPEGImages", "annotations_detectron2/pc59_val"), ]: image_dir = os.path.join(root, image_dirname) gt_dir = os.path.join(root, sem_seg_dirname) all_name = f"pascal_context_59_sem_seg_{name}" DatasetCatalog.register( all_name, lambda x=image_dir, y=gt_dir: load_sem_seg(y, x, gt_ext="png", image_ext="jpg"), ) MetadataCatalog.get(all_name).set( image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=255, **meta, )
def register_pascal_context_459(root): root = os.path.join(root, "VOCdevkit/VOC2010") meta = _get_voc_meta(PASCALCONTEX459_NAMES) for name, image_dirname, sem_seg_dirname in [ ("val", "JPEGImages", "annotations_detectron2/pc459_val"), ]: image_dir = os.path.join(root, image_dirname) gt_dir = os.path.join(root, sem_seg_dirname) all_name = f"pascal_context_459_sem_seg_{name}" DatasetCatalog.register( all_name, lambda x=image_dir, y=gt_dir: load_sem_seg(y, x, gt_ext="tif", image_ext="jpg"), ) MetadataCatalog.get(all_name).set( image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=65535, # NOTE: gt is saved in 16-bit TIFF images **meta, )
if __name__.endswith(".register_pascal_context"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_pascal_context_59(_root) register_pascal_context_459(_root)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364# Copyright (c) Facebook, Inc. and its affiliates.import os
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets import load_sem_seg
PASCALVOC20_NAMES = ( "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor",)
def _get_voc_meta(cat_list): ret = { "stuff_classes": cat_list, } return ret
def register_pascalvoc(root): root = os.path.join(root, "VOCdevkit/VOC2012") meta = _get_voc_meta(PASCALVOC20_NAMES)
for name, image_dirname, sem_seg_dirname in [ ("val", "JPEGImages", "annotations_detectron2/val"), ]: image_dir = os.path.join(root, image_dirname) gt_dir = os.path.join(root, sem_seg_dirname) all_name = f"pascalvoc20_sem_seg_{name}" DatasetCatalog.register( all_name, lambda x=image_dir, y=gt_dir: load_sem_seg(y, x, gt_ext="png", image_ext="jpg"), ) MetadataCatalog.get(all_name).set( image_root=image_dir, sem_seg_root=gt_dir, evaluator_type="sem_seg", ignore_label=255, **meta, )
if __name__.endswith(".register_voc_seg"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_pascalvoc(_root)1234567891011121314151617181920212223242526272829303132333435363738394041424344import os
from detectron2.data.datasets.register_coco import register_coco_instances
SA1B_CATEGORIES = [ {"id": 1, "name": "object"},]
def _get_builtin_metadata(key): id_to_name = {x["id"]: x["name"] for x in SA1B_CATEGORIES} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(SA1B_CATEGORIES))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_SA1B = { "sa1b": ("SA-1B/images", "SA-1B/sam1b_instance.json"), "sa1b_1m": ("SA-1B/images", "SA-1B/sam1b_instance_1000000.json"), "sa1b_2m": ("SA-1B/images", "SA-1B/sam1b_instance_2000000.json"), "sa1b_4m": ("SA-1B/images", "SA-1B/sam1b_instance_4000000.json"), "sa1b_6m": ("SA-1B/images", "SA-1B/sam1b_instance_6000000.json"), "sa1b_8m": ("SA-1B/images", "SA-1B/sam1b_instance_8000000.json"), "sa1b_10m": ("SA-1B/images", "SA-1B/sam1b_instance_10000000.json"),}
def register_all_sa1b(root): for key, (image_root, json_file) in _PREDEFINED_SPLITS_SA1B.items(): register_coco_instances( key, _get_builtin_metadata(key), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".sa1b"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DETECTRON2_DATASETS", "datasets") register_all_sa1b(_root)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889SEGINW_CATEGORIES = { "seginw_Helmet-Head": ["Helmet"], "seginw_Line-Contour": ["line-structure"], "seginw_Elephants": ["elephant"], "seginw_Hand-Metal": ["hand", "metal"], "seginw_Watermelon": ["watermelon"], "seginw_House-Parts": [ "aluminium door", "aluminium window", "cellar window", "mint cond roof", "plaster", "plastic door", "plastic window", "plate fascade", "wooden door", "wooden fascade", "wooden window", "worn cond roof", ], "seginw_HouseHold-Items": ["bottle", "mouse", "perfume", "phone"], "seginw_Strawberry": ["R_strawberry", "people"], "seginw_WareHouse-Box": ["box", "dmg box", "label"], "seginw_Fruits": ["apple", "lemon", "orange", "pear", "strawberry"], "seginw_Nutterfly-Squireel": ["butterfly", "squirrel"], "seginw_Hand": ["Hand-Segmentation", "hand"], "seginw_Garbage": ["bin", "garbage", "pavement", "road"], "seginw_Chicken": ["chicken"], "seginw_Rail": ["rail"], "seginw_Airplane-Parts": ["Airplane", "Body", "Cockpit", "Engine", "Wing"], "seginw_Face-Mask": ["Mask"], "seginw_Brain-Tumor": ["tumor"], "seginw_Poles": ["poles"], "seginw_Car-Parts": [ "back_bumper", "back_door", "back_glass", "back_light", "front_bumper", "front_door", "front_glass", "front_light", "hood", ], "seginw_Electric-Shaver": ["caorau"], "seginw_Bottles": ["bottle", "can", "label"], "seginw_Toolkits": [ "Allen-key", "block", "gasket", "plier", "prism", "screw", "screwdriver", "wrench", ], "seginw_Trash": [ "Aluminium foil", "Cigarette", "Clear plastic bottle", "Corrugated carton", "Disposable plastic cup", "Drink Can", "Egg Carton", "Foam cup", "Food Can", "Garbage bag", "Glass bottle", "Glass cup", "Metal bottle cap", "Other carton", "Other plastic bottle", "Paper cup", "Plastic bag - wrapper", "Plastic bottle cap", "Plastic lid", "Plastic straw", "Pop tab", "Styrofoam piece", ], "seginw_Salmon-Fillet": ["Salmon_fillet"], "seginw_Puppies": ["puppy"], "seginw_Tablets": ["tablets"], "seginw_Cable": ["cable"], "seginw_Fire": ["fire"], "seginw_Phones": ["phone"], "seginw_Cows": ["cow"], "seginw_Ginger-Garlic": ["garlic", "ginger"],}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142# Copyright (c) Facebook, Inc. and its affiliates.import collectionsimport jsonimport os
from detectron2.data import DatasetCatalog, MetadataCatalogfrom detectron2.data.datasets import load_sem_segfrom detectron2.data.datasets.builtin_meta import COCO_CATEGORIESfrom detectron2.utils.file_io import PathManager
from .seginw_categories import SEGINW_CATEGORIES
_CATEGORIES = [ "Elephants", "Hand-Metal", "Watermelon", "House-Parts", "HouseHold-Items", "Strawberry", "Fruits", "Nutterfly-Squireel", "Hand", "Garbage", "Chicken", "Rail", "Airplane-Parts", "Brain-Tumor", "Poles", "Electric-Shaver", "Bottles", "Toolkits", "Trash", "Salmon-Fillet", "Puppies", "Tablets", "Phones", "Cows", "Ginger-Garlic",]
_PREDEFINED_SPLITS_SEGINW = { "seginw_{}_val".format(cat): ( "valid", "seginw/{}".format(cat), # image_root "_annotations_min1cat.coco.json", # annot_root ) for cat in _CATEGORIES}_PREDEFINED_SPLITS_SEGINW.update( { "seginw_{}_train".format(cat): ( "train", "seginw/{}".format(cat), # image_root "_annotations_min1cat.coco.json", # annot_root ) for cat in _CATEGORIES })
def get_metadata(name): # meta = {"thing_dataset_id_to_contiguous_id": {}} meta = {} meta["thing_classes"] = SEGINW_CATEGORIES[name.replace("_train", "").replace("_val", "")] meta["thing_dataset_id_to_contiguous_id"] = {i: i for i in range(len(meta["thing_classes"]))} return meta
def load_seginw_json(name, image_root, annot_json, metadata): """ Args: image_dir (str): path to the raw dataset. e.g., "~/coco/train2017". gt_dir (str): path to the raw annotations. e.g., "~/coco/panoptic_train2017". json_file (str): path to the json file. e.g., "~/coco/annotations/panoptic_train2017.json". Returns: list[dict]: a list of dicts in Detectron2 standard format. (See `Using Custom Datasets </tutorials/datasets.html>`_ ) """
with PathManager.open(annot_json) as f: json_info = json.load(f)
# build dictionary for grounding grd_dict = collections.defaultdict(list) for grd_ann in json_info["annotations"]: image_id = int(grd_ann["image_id"]) grd_dict[image_id].append(grd_ann)
ret = [] for image in json_info["images"]: image_id = int(image["id"]) image_file = os.path.join(image_root, image["file_name"]) grounding_anno = grd_dict[image_id]
if "train" in name and len(grounding_anno) == 0: continue
ret.append( { "file_name": image_file, "image_id": image_id, "inst_info": grounding_anno, } )
assert len(ret), f"No images found in {image_root}!" assert PathManager.isfile(ret[0]["file_name"]), ret[0]["file_name"] return ret
def register_seginw(name, metadata, image_root, annot_json): DatasetCatalog.register( name, lambda: load_seginw_json(name, image_root, annot_json, metadata), ) MetadataCatalog.get(name).set( image_root=image_root, json_file=annot_json, evaluator_type="seginw", ignore_label=255, label_divisor=1000, **metadata, )
def register_all_seginw(root): for ( prefix, (split, folder_name, annot_name), ) in _PREDEFINED_SPLITS_SEGINW.items(): register_seginw( prefix, get_metadata(prefix), os.path.join(root, folder_name, split), os.path.join(root, folder_name, split, annot_name), )
if __name__.endswith(".seginw_instance"): # Assume pre-defined datasets live in `./datasets`. _root = os.getenv("DATASET", "datasets") register_all_seginw(_root)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220import loggingimport os
from .coco import custom_register_coco_instancesfrom .visualgenome_categories import ( VISUALGENOME_150_CATEGORIES, VISUALGENOME_1356_CATEGORIES, VISUALGENOME_1356MINUS150_CATEGORIES, VISUALGENOME_77962_CATEGORIES, VISUALGENOME_77962MINUS150_CATEGORIES,)
logger = logging.getLogger(__name__)
def _get_builtin_metadata(dataset_name): if dataset_name == "visualgenome_150_box": return _get_visualgenome_metadata(VISUALGENOME_150_CATEGORIES)
if dataset_name == "visualgenome_region": return _get_visualgenome_metadata([])
if dataset_name == "visualgenome_150_box_and_region": return _get_visualgenome_metadata(VISUALGENOME_150_CATEGORIES)
if dataset_name == "visualgenome_77962_box_and_region": return _get_visualgenome_metadata(VISUALGENOME_77962_CATEGORIES)
if dataset_name == "visualgenome_77962_box": return _get_visualgenome_metadata(VISUALGENOME_77962_CATEGORIES)
if dataset_name == "visualgenome_77962minus150_box": return _get_visualgenome_metadata(VISUALGENOME_77962MINUS150_CATEGORIES)
if dataset_name == "visualgenome_77962minus2319_box": return _get_visualgenome_metadata(VISUALGENOME_77962MINUS150_CATEGORIES)
if dataset_name == "visualgenome_1356_box": return _get_visualgenome_metadata(VISUALGENOME_1356_CATEGORIES)
if dataset_name == "visualgenome_1356minus150_box": return _get_visualgenome_metadata(VISUALGENOME_1356MINUS150_CATEGORIES)
if dataset_name == "visualgenome_1356minus2319_box": return _get_visualgenome_metadata(VISUALGENOME_1356MINUS150_CATEGORIES)
raise KeyError("No built-in metadata for dataset {}".format(dataset_name))
def _get_visualgenome_metadata(categories): if len(categories) == 0: return {} id_to_name = {x["id"]: x["name"] for x in categories} thing_dataset_id_to_contiguous_id = {i + 1: i for i in range(len(categories))} thing_classes = [id_to_name[k] for k in sorted(id_to_name)] return { "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id, "thing_classes": thing_classes, }
_PREDEFINED_SPLITS_VISUALGENOME = {}_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_150_box"] = { "visualgenome_150_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_150_box_train.json", ), "visualgenome_150_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_150_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_150_box_and_region"] = { "visualgenome_150_box_and_region_train": ( "visualgenome", "visualgenome/annotations/visualgenome_150_box_and_region_train.json", ), "visualgenome_150_box_and_region_val": ( "visualgenome", "visualgenome/annotations/visualgenome_150_box_and_region_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_77962_box"] = { "visualgenome_77962_box": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box.json", ), "visualgenome_77962_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box_train.json", ), "visualgenome_77962_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_77962_box_and_region"] = { "visualgenome_77962_box_and_region": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box_and_region.json", ), "visualgenome_77962_box_and_region_train": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box_and_region_train.json", ), "visualgenome_77962_box_and_region_val": ( "visualgenome", "visualgenome/annotations/visualgenome_77962_box_and_region_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_region"] = { "visualgenome_region": ( "visualgenome", "visualgenome/annotations/visualgenome_region.json", ), "visualgenome_region_train": ( "visualgenome", "visualgenome/annotations/visualgenome_region_train.json", ), "visualgenome_region_val": ( "visualgenome", "visualgenome/annotations/visualgenome_region_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_77962minus150_box"] = { "visualgenome_77962minus150_box": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus150_box.json", ), "visualgenome_77962minus150_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus150_box_train.json", ), "visualgenome_77962minus150_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus150_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_77962minus2319_box"] = { "visualgenome_77962minus2319_box": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus2319_box.json", ), "visualgenome_77962minus2319_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus2319_box_train.json", ), "visualgenome_77962minus2319_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_77962minus2319_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_1356_box"] = { "visualgenome_1356_box": ( "visualgenome", "visualgenome/annotations/visualgenome_1356_box.json", ), "visualgenome_1356_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_1356_box_train.json", ), "visualgenome_1356_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_1356_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_1356minus150_box"] = { "visualgenome_1356minus150_box": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus150_box.json", ), "visualgenome_1356minus150_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus150_box_train.json", ), "visualgenome_1356minus150_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus150_box_val.json", ),}
_PREDEFINED_SPLITS_VISUALGENOME["visualgenome_1356minus2319_box"] = { "visualgenome_1356minus2319_box": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus2319_box.json", ), "visualgenome_1356minus2319_box_train": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus2319_box_train.json", ), "visualgenome_1356minus2319_box_val": ( "visualgenome", "visualgenome/annotations/visualgenome_1356minus2319_box_val.json", ),}
def register_all_visualgenome(root): for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_VISUALGENOME.items(): for key, (image_root, json_file) in splits_per_dataset.items(): custom_register_coco_instances( key, _get_builtin_metadata(dataset_name), os.path.join(root, json_file) if "://" not in json_file else json_file, os.path.join(root, image_root), )
if __name__.endswith(".visualgenome"): # Assume pre-defined datasets live in `./datasets`. _root = os.path.expanduser(os.getenv("DETECTRON2_DATASETS", "datasets")) register_all_visualgenome(_root)12345from .distributed_sampler_multi_dataset import MultiDatasetTrainingSampler
__all__ = [ "MultiDatasetTrainingSampler",]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137# Copyright (c) Facebook, Inc. and its affiliates.import itertoolsimport loggingimport mathfrom collections import defaultdictfrom typing import Optional
import torchfrom torch.utils.data.sampler import Sampler
from detectron2.data.samplers import RepeatFactorTrainingSamplerfrom detectron2.utils import comm
logger = logging.getLogger(__name__)
class MultiDatasetTrainingSampler(Sampler): def __init__(self, repeat_factors, *, shuffle=True, seed=None): self._shuffle = shuffle if seed is None: seed = comm.shared_random_seed() self._seed = int(seed)
self._rank = comm.get_rank() self._world_size = comm.get_world_size()
# Split into whole number (_int_part) and fractional (_frac_part) parts. self._int_part = torch.trunc(repeat_factors) self._frac_part = repeat_factors - self._int_part
@staticmethod def get_repeat_factors( dataset_dicts, num_datasets, dataset_ratio, use_rfs, use_cas, repeat_thresh, cas_lambda ): sizes = [0 for _ in range(num_datasets)] for d in dataset_dicts: sizes[d["dataset_id"]] += 1
assert len(dataset_ratio) == len( sizes ), "length of dataset ratio {} should be equal to number if dataset {}".format( len(dataset_ratio), len(sizes) ) dataset_weight = [ torch.ones(s, dtype=torch.float32) * max(sizes) / s * r for i, (r, s) in enumerate(zip(dataset_ratio, sizes)) ]
logger = logging.getLogger(__name__) logger.info( "Training sampler dataset weight: {}".format( str([max(sizes) / s * r for i, (r, s) in enumerate(zip(dataset_ratio, sizes))]) ) )
st = 0 repeat_factors = [] for i, s in enumerate(sizes): assert use_rfs[i] * use_cas[i] == 0 if use_rfs[i]: repeat_factor = RepeatFactorTrainingSampler.repeat_factors_from_category_frequency( dataset_dicts[st : st + s], repeat_thresh ) elif use_cas[i]: repeat_factor = MultiDatasetTrainingSampler.get_class_balance_factor_per_dataset( dataset_dicts[st : st + s], l=cas_lambda ) repeat_factor = repeat_factor * (s / repeat_factor.sum()) else: repeat_factor = torch.ones(s, dtype=torch.float32) logger.info( "Training sampler class weight: {} {} {}".format( repeat_factor.size(), repeat_factor.max(), repeat_factor.min() ) ) repeat_factors.append(repeat_factor) st = st + s repeat_factors = torch.cat(repeat_factors) dataset_weight = torch.cat(dataset_weight) repeat_factors = dataset_weight * repeat_factors
return repeat_factors
@staticmethod def get_class_balance_factor_per_dataset(dataset_dicts, l=1.0): rep_factors = [] category_freq = defaultdict(int) for dataset_dict in dataset_dicts: # For each image (without repeats) cat_ids = {ann["category_id"] for ann in dataset_dict["annotations"]} for cat_id in cat_ids: category_freq[cat_id] += 1 for dataset_dict in dataset_dicts: cat_ids = {ann["category_id"] for ann in dataset_dict["annotations"]} rep_factor = sum([1.0 / (category_freq[cat_id] ** l) for cat_id in cat_ids]) rep_factors.append(rep_factor)
return torch.tensor(rep_factors, dtype=torch.float32)
def _get_epoch_indices(self, generator): """ Create a list of dataset indices (with repeats) to use for one epoch.
Args: generator (torch.Generator): pseudo random number generator used for stochastic rounding.
Returns: torch.Tensor: list of dataset indices to use in one epoch. Each index is repeated based on its calculated repeat factor. """ # Since repeat factors are fractional, we use stochastic rounding so # that the target repeat factor is achieved in expectation over the # course of training rands = torch.rand(len(self._frac_part), generator=generator) rep_factors = self._int_part + (rands < self._frac_part).float() # Construct a list of indices in which we repeat images as specified indices = [] for dataset_index, rep_factor in enumerate(rep_factors): indices.extend([dataset_index] * int(rep_factor.item())) return torch.tensor(indices, dtype=torch.int64)
def __iter__(self): start = self._rank yield from itertools.islice(self._infinite_indices(), start, None, self._world_size)
def _infinite_indices(self): g = torch.Generator() g.manual_seed(self._seed) while True: # Sample indices with repeats determined by stochastic rounding; each # "epoch" may have a slightly different size due to the rounding. indices = self._get_epoch_indices(g) if self._shuffle: randperm = torch.randperm(len(indices), generator=g) yield from indices[randperm].tolist() else: yield from indices.tolist()12345# Copyright (c) Facebook, Inc. and its affiliates.from .augmentation_aa import *from .augmentation_lsj import *
__all__ = [k for k in globals().keys() if not k.startswith("_")]123456789101112131415161718192021222324252627282930313233343536373839from detectron2.data import transforms as Tfrom fvcore.transforms.transform import Transform, TransformList
class AutoAugment(T.Augmentation): def __init__(self, cfg): super().__init__() self.resize = T.AugmentationList( [ T.ResizeShortestEdge( [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800], 1333, sample_style="choice", ), ] ) self.resize_crop_resize = T.AugmentationList( [ T.ResizeShortestEdge([400, 500, 600], 1333, sample_style="choice"), T.RandomCrop("absolute_range", (384, 600)), T.ResizeShortestEdge( [480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800], 1333, sample_style="choice", ), ] )
def __call__(self, aug_input) -> Transform:
do = self._rand_range(low=0.0, high=1.0) if do > 0.5: return self.resize(aug_input) else: return self.resize_crop_resize(aug_input)
def __repr__(self): msgs = [str(self.resize), str(self.resize_crop_resize)] return "AutoAugment[{}]".format(", ".join(msgs))1234567891011121314151617181920212223242526272829303132333435363738from detectron2.data import transforms as Tfrom fvcore.transforms.transform import Transform, TransformList
class LargeScaleJitter(T.Augmentation): def __init__(self, cfg): super().__init__()
image_size = cfg.INPUT.LSJ.IMAGE_SIZE min_scale = cfg.INPUT.LSJ.MIN_SCALE max_scale = cfg.INPUT.LSJ.MAX_SCALE # pad_value = 128.0 pad_value = 1.0 * sum(cfg.MODEL.PIXEL_MEAN) / len(cfg.MODEL.PIXEL_MEAN) seg_pad_value = cfg.INPUT.SEG_PAD_VALUE
self.resize_crop = T.AugmentationList( [ T.ResizeScale( min_scale=min_scale, max_scale=max_scale, target_height=image_size, target_width=image_size, ), T.FixedSizeCrop( crop_size=(image_size, image_size), pad_value=pad_value, seg_pad_value=seg_pad_value, ), ] )
def __call__(self, aug_input) -> Transform:
return self.resize_crop(aug_input)
def __repr__(self): msgs = str(self.resize_crop) return "LargeScaleJitter[{}]".format(msgs)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reservedimport mathimport numpy as npfrom scipy import interpolateimport torchimport torch.nn as nnimport torch.nn.functional as F
__all__ = [ "window_partition", "window_unpartition", "add_decomposed_rel_pos", "get_abs_pos", "PatchEmbed",]
def window_partition(x, window_size): """ Partition into non-overlapping windows with padding if needed. Args: x (tensor): input tokens with [B, H, W, C]. window_size (int): window size.
Returns: windows: windows after partition with [B * num_windows, window_size, window_size, C]. (Hp, Wp): padded height and width before partition """ B, H, W, C = x.shape
pad_h = (window_size - H % window_size) % window_size pad_w = (window_size - W % window_size) % window_size if pad_h > 0 or pad_w > 0: x = F.pad(x, (0, 0, 0, pad_w, 0, pad_h)) Hp, Wp = H + pad_h, W + pad_w
x = x.view(B, Hp // window_size, window_size, Wp // window_size, window_size, C) windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C) return windows, (Hp, Wp)
def window_unpartition(windows, window_size, pad_hw, hw): """ Window unpartition into original sequences and removing padding. Args: x (tensor): input tokens with [B * num_windows, window_size, window_size, C]. window_size (int): window size. pad_hw (Tuple): padded height and width (Hp, Wp). hw (Tuple): original height and width (H, W) before padding.
Returns: x: unpartitioned sequences with [B, H, W, C]. """ Hp, Wp = pad_hw H, W = hw B = windows.shape[0] // (Hp * Wp // window_size // window_size) x = windows.view(B, Hp // window_size, Wp // window_size, window_size, window_size, -1) x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, Hp, Wp, -1)
if Hp > H or Wp > W: x = x[:, :H, :W, :].contiguous() return x
def get_rel_pos(q_size, k_size, rel_pos, interp_type): """ Get relative positional embeddings according to the relative positions of query and key sizes. Args: q_size (int): size of query q. k_size (int): size of key k. rel_pos (Tensor): relative position embeddings (L, C).
Returns: Extracted positional embeddings according to relative positions. """ max_rel_dist = int(2 * max(q_size, k_size) - 1) # Interpolate rel pos if needed. if rel_pos.shape[0] != max_rel_dist: if interp_type == "vitdet": # the vitdet impl: # https://github.com/facebookresearch/detectron2/blob/96c752ce821a3340e27edd51c28a00665dd32a30/detectron2/modeling/backbone/utils.py#L77.
rel_pos_resized = F.interpolate( rel_pos.reshape(1, rel_pos.shape[0], -1).permute(0, 2, 1), size=max_rel_dist, mode="linear", ) rel_pos_resized = rel_pos_resized.reshape(-1, max_rel_dist).permute(1, 0) elif interp_type == "beit": # steal from beit https://github.com/microsoft/unilm/tree/master/beit # modified by Yuxin Fang
src_size = rel_pos.shape[0] dst_size = max_rel_dist
q = 1.0903078 dis = []
cur = 1 for i in range(src_size // 2): dis.append(cur) cur += q ** (i + 1)
r_ids = [-_ for _ in reversed(dis)] x = r_ids + [0] + dis t = dst_size // 2.0 dx = np.arange(-t, t + 0.1, 1.0)
all_rel_pos_bias = [] for i in range(rel_pos.shape[1]): # a hack from https://github.com/baaivision/EVA/issues/8, # could also be used in fine-tuning but the performance haven't been tested. z = rel_pos[:, i].view(src_size).cpu().float().detach().numpy() f = interpolate.interp1d(x, z, kind='cubic', fill_value="extrapolate") all_rel_pos_bias.append( torch.Tensor(f(dx)).contiguous().view(-1, 1).to(rel_pos.device)) rel_pos_resized = torch.cat(all_rel_pos_bias, dim=-1) else: raise NotImplementedError() else: rel_pos_resized = rel_pos
# Scale the coords with short length if shapes for q and k are different. q_coords = torch.arange(q_size)[:, None] * max(k_size / q_size, 1.0) k_coords = torch.arange(k_size)[None, :] * max(q_size / k_size, 1.0) relative_coords = (q_coords - k_coords) + (k_size - 1) * max(q_size / k_size, 1.0)
return rel_pos_resized[relative_coords.long()]
def add_decomposed_rel_pos(attn, q, rel_pos_h, rel_pos_w, q_size, k_size, interp_type): """ Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`. https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py # noqa B950 Args: attn (Tensor): attention map. q (Tensor): query q in the attention layer with shape (B, q_h * q_w, C). rel_pos_h (Tensor): relative position embeddings (Lh, C) for height axis. rel_pos_w (Tensor): relative position embeddings (Lw, C) for width axis. q_size (Tuple): spatial sequence size of query q with (q_h, q_w). k_size (Tuple): spatial sequence size of key k with (k_h, k_w).
Returns: attn (Tensor): attention map with added relative positional embeddings. """ q_h, q_w = q_size k_h, k_w = k_size Rh = get_rel_pos(q_h, k_h, rel_pos_h, interp_type) Rw = get_rel_pos(q_w, k_w, rel_pos_w, interp_type)
B, _, dim = q.shape r_q = q.reshape(B, q_h, q_w, dim) rel_h = torch.einsum("bhwc,hkc->bhwk", r_q, Rh) rel_w = torch.einsum("bhwc,wkc->bhwk", r_q, Rw)
attn = ( attn.view(B, q_h, q_w, k_h, k_w) + rel_h[:, :, :, :, None] + rel_w[:, :, :, None, :] ).view(B, q_h * q_w, k_h * k_w)
return attn
def get_abs_pos(abs_pos, has_cls_token, hw): """ Calculate absolute positional embeddings. If needed, resize embeddings and remove cls_token dimension for the original embeddings. Args: abs_pos (Tensor): absolute positional embeddings with (1, num_position, C). has_cls_token (bool): If true, has 1 embedding in abs_pos for cls token. hw (Tuple): size of input image tokens.
Returns: Absolute positional embeddings after processing with shape (1, H, W, C) """ h, w = hw if has_cls_token: abs_pos = abs_pos[:, 1:] xy_num = abs_pos.shape[1] size = int(math.sqrt(xy_num)) assert size * size == xy_num
if size != h or size != w: new_abs_pos = F.interpolate( abs_pos.reshape(1, size, size, -1).permute(0, 3, 1, 2), size=(h, w), mode="bicubic", align_corners=False, )
return new_abs_pos.permute(0, 2, 3, 1) else: return abs_pos.reshape(1, h, w, -1)
class PatchEmbed(nn.Module): """ Image to Patch Embedding. """
def __init__( self, kernel_size=(16, 16), stride=(16, 16), padding=(0, 0), in_chans=3, embed_dim=768 ): """ Args: kernel_size (Tuple): kernel size of the projection layer. stride (Tuple): stride of the projection layer. padding (Tuple): padding size of the projection layer. in_chans (int): Number of input image channels. embed_dim (int): embed_dim (int): Patch embedding dimension. """ super().__init__()
self.proj = nn.Conv2d( in_chans, embed_dim, kernel_size=kernel_size, stride=stride, padding=padding )
def forward(self, x): x = self.proj(x) # B C H W -> B H W C x = x.permute(0, 2, 3, 1) return x123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reservedimport mathimport numpy as npfrom scipy import interpolateimport torchimport torch.nn as nnimport torch.nn.functional as F
__all__ = [ "window_partition", "window_unpartition", "add_decomposed_rel_pos", "get_abs_pos", "PatchEmbed", "VisionRotaryEmbeddingFast",]
def window_partition(x, window_size): """ Partition into non-overlapping windows with padding if needed. Args: x (tensor): input tokens with [B, H, W, C]. window_size (int): window size.
Returns: windows: windows after partition with [B * num_windows, window_size, window_size, C]. (Hp, Wp): padded height and width before partition """ B, H, W, C = x.shape
pad_h = (window_size - H % window_size) % window_size pad_w = (window_size - W % window_size) % window_size if pad_h > 0 or pad_w > 0: x = F.pad(x, (0, 0, 0, pad_w, 0, pad_h)) Hp, Wp = H + pad_h, W + pad_w
x = x.view(B, Hp // window_size, window_size, Wp // window_size, window_size, C) windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C) return windows, (Hp, Wp)
def window_unpartition(windows, window_size, pad_hw, hw): """ Window unpartition into original sequences and removing padding. Args: x (tensor): input tokens with [B * num_windows, window_size, window_size, C]. window_size (int): window size. pad_hw (Tuple): padded height and width (Hp, Wp). hw (Tuple): original height and width (H, W) before padding.
Returns: x: unpartitioned sequences with [B, H, W, C]. """ Hp, Wp = pad_hw H, W = hw B = windows.shape[0] // (Hp * Wp // window_size // window_size) x = windows.view(B, Hp // window_size, Wp // window_size, window_size, window_size, -1) x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, Hp, Wp, -1)
if Hp > H or Wp > W: x = x[:, :H, :W, :].contiguous() return x
def get_rel_pos(q_size, k_size, rel_pos): """ Get relative positional embeddings according to the relative positions of query and key sizes. Args: q_size (int): size of query q. k_size (int): size of key k. rel_pos (Tensor): relative position embeddings (L, C).
Returns: Extracted positional embeddings according to relative positions. """ max_rel_dist = int(2 * max(q_size, k_size) - 1) use_log_interpolation = True
# Interpolate rel pos if needed. if rel_pos.shape[0] != max_rel_dist: if not use_log_interpolation: # Interpolate rel pos. rel_pos_resized = F.interpolate( rel_pos.reshape(1, rel_pos.shape[0], -1).permute(0, 2, 1), size=max_rel_dist, mode="linear", ) rel_pos_resized = rel_pos_resized.reshape(-1, max_rel_dist).permute(1, 0) else: src_size = rel_pos.shape[0] dst_size = max_rel_dist
# q = 1.13492 q = 1.0903078 dis = []
cur = 1 for i in range(src_size // 2): dis.append(cur) cur += q ** (i + 1)
r_ids = [-_ for _ in reversed(dis)] x = r_ids + [0] + dis t = dst_size // 2.0 dx = np.arange(-t, t + 0.1, 1.0) all_rel_pos_bias = [] for i in range(rel_pos.shape[1]): z = rel_pos[:, i].view(src_size).cpu().float().numpy() f = interpolate.interp1d(x, z, kind='cubic', fill_value="extrapolate") all_rel_pos_bias.append( torch.Tensor(f(dx)).contiguous().view(-1, 1).to(rel_pos.device)) rel_pos_resized = torch.cat(all_rel_pos_bias, dim=-1) else: rel_pos_resized = rel_pos
# Scale the coords with short length if shapes for q and k are different. q_coords = torch.arange(q_size)[:, None] * max(k_size / q_size, 1.0) k_coords = torch.arange(k_size)[None, :] * max(q_size / k_size, 1.0) relative_coords = (q_coords - k_coords) + (k_size - 1) * max(q_size / k_size, 1.0)
return rel_pos_resized[relative_coords.long()]
def add_decomposed_rel_pos(attn, q, rel_pos_h, rel_pos_w, q_size, k_size): """ Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`. https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py # noqa B950 Args: attn (Tensor): attention map. q (Tensor): query q in the attention layer with shape (B, q_h * q_w, C). rel_pos_h (Tensor): relative position embeddings (Lh, C) for height axis. rel_pos_w (Tensor): relative position embeddings (Lw, C) for width axis. q_size (Tuple): spatial sequence size of query q with (q_h, q_w). k_size (Tuple): spatial sequence size of key k with (k_h, k_w).
Returns: attn (Tensor): attention map with added relative positional embeddings. """ q_h, q_w = q_size k_h, k_w = k_size Rh = get_rel_pos(q_h, k_h, rel_pos_h) Rw = get_rel_pos(q_w, k_w, rel_pos_w)
B, _, dim = q.shape r_q = q.reshape(B, q_h, q_w, dim) rel_h = torch.einsum("bhwc,hkc->bhwk", r_q, Rh) rel_w = torch.einsum("bhwc,wkc->bhwk", r_q, Rw)
attn = ( attn.view(B, q_h, q_w, k_h, k_w) + rel_h[:, :, :, :, None] + rel_w[:, :, :, None, :] ).view(B, q_h * q_w, k_h * k_w)
return attn
def get_abs_pos(abs_pos, has_cls_token, hw): """ Calculate absolute positional embeddings. If needed, resize embeddings and remove cls_token dimension for the original embeddings. Args: abs_pos (Tensor): absolute positional embeddings with (1, num_position, C). has_cls_token (bool): If true, has 1 embedding in abs_pos for cls token. hw (Tuple): size of input image tokens.
Returns: Absolute positional embeddings after processing with shape (1, H, W, C) """ h, w = hw if has_cls_token: abs_pos = abs_pos[:, 1:] xy_num = abs_pos.shape[1] size = int(math.sqrt(xy_num)) assert size * size == xy_num
if size != h or size != w: new_abs_pos = F.interpolate( abs_pos.reshape(1, size, size, -1).permute(0, 3, 1, 2), size=(h, w), mode="bicubic", align_corners=False, )
return new_abs_pos.permute(0, 2, 3, 1) else: return abs_pos.reshape(1, h, w, -1)
class PatchEmbed(nn.Module): """ Image to Patch Embedding. """
def __init__( self, kernel_size=(16, 16), stride=(16, 16), padding=(0, 0), in_chans=3, embed_dim=768 ): """ Args: kernel_size (Tuple): kernel size of the projection layer. stride (Tuple): stride of the projection layer. padding (Tuple): padding size of the projection layer. in_chans (int): Number of input image channels. embed_dim (int): embed_dim (int): Patch embedding dimension. """ super().__init__()
self.proj = nn.Conv2d( in_chans, embed_dim, kernel_size=kernel_size, stride=stride, padding=padding )
def forward(self, x): x = self.proj(x) # B C H W -> B H W C x = x.permute(0, 2, 3, 1) return x
from math import pi
import torchfrom torch import nn
from einops import rearrange, repeat
def broadcat(tensors, dim = -1): num_tensors = len(tensors) shape_lens = set(list(map(lambda t: len(t.shape), tensors))) assert len(shape_lens) == 1, 'tensors must all have the same number of dimensions' shape_len = list(shape_lens)[0] dim = (dim + shape_len) if dim < 0 else dim dims = list(zip(*map(lambda t: list(t.shape), tensors))) expandable_dims = [(i, val) for i, val in enumerate(dims) if i != dim] assert all([*map(lambda t: len(set(t[1])) <= 2, expandable_dims)]), 'invalid dimensions for broadcastable concatentation' max_dims = list(map(lambda t: (t[0], max(t[1])), expandable_dims)) expanded_dims = list(map(lambda t: (t[0], (t[1],) * num_tensors), max_dims)) expanded_dims.insert(dim, (dim, dims[dim])) expandable_shapes = list(zip(*map(lambda t: t[1], expanded_dims))) tensors = list(map(lambda t: t[0].expand(*t[1]), zip(tensors, expandable_shapes))) return torch.cat(tensors, dim = dim)
def rotate_half(x): x = rearrange(x, '... (d r) -> ... d r', r = 2) x1, x2 = x.unbind(dim = -1) x = torch.stack((-x2, x1), dim = -1) return rearrange(x, '... d r -> ... (d r)')
class VisionRotaryEmbedding(nn.Module): def __init__( self, dim, pt_seq_len, ft_seq_len=None, custom_freqs = None, freqs_for = 'lang', theta = 10000, max_freq = 10, num_freqs = 1, ): super().__init__() if custom_freqs: freqs = custom_freqs elif freqs_for == 'lang': freqs = 1. / (theta ** (torch.arange(0, dim, 2)[:(dim // 2)].float() / dim)) elif freqs_for == 'pixel': freqs = torch.linspace(1., max_freq / 2, dim // 2) * pi elif freqs_for == 'constant': freqs = torch.ones(num_freqs).float() else: raise ValueError(f'unknown modality {freqs_for}')
if ft_seq_len is None: ft_seq_len = pt_seq_len t = torch.arange(ft_seq_len) / ft_seq_len * pt_seq_len
freqs_h = torch.einsum('..., f -> ... f', t, freqs) freqs_h = repeat(freqs_h, '... n -> ... (n r)', r = 2)
freqs_w = torch.einsum('..., f -> ... f', t, freqs) freqs_w = repeat(freqs_w, '... n -> ... (n r)', r = 2)
freqs = broadcat((freqs_h[:, None, :], freqs_w[None, :, :]), dim = -1)
self.register_buffer("freqs_cos", freqs.cos()) self.register_buffer("freqs_sin", freqs.sin())
print('======== shape of rope freq', self.freqs_cos.shape, '========')
def forward(self, t, start_index = 0): rot_dim = self.freqs_cos.shape[-1] end_index = start_index + rot_dim assert rot_dim <= t.shape[-1], f'feature dimension {t.shape[-1]} is not of sufficient size to rotate in all the positions {rot_dim}' t_left, t, t_right = t[..., :start_index], t[..., start_index:end_index], t[..., end_index:] t = (t * self.freqs_cos) + (rotate_half(t) * self.freqs_sin) return torch.cat((t_left, t, t_right), dim = -1)
class VisionRotaryEmbeddingFast(nn.Module): def __init__( self, dim, pt_seq_len=16, ft_seq_len=None, custom_freqs = None, freqs_for = 'lang', theta = 10000, max_freq = 10, num_freqs = 1, ): super().__init__() if custom_freqs: freqs = custom_freqs elif freqs_for == 'lang': freqs = 1. / (theta ** (torch.arange(0, dim, 2)[:(dim // 2)].float() / dim)) elif freqs_for == 'pixel': freqs = torch.linspace(1., max_freq / 2, dim // 2) * pi elif freqs_for == 'constant': freqs = torch.ones(num_freqs).float() else: raise ValueError(f'unknown modality {freqs_for}')
if ft_seq_len is None: ft_seq_len = pt_seq_len t = torch.arange(ft_seq_len) / ft_seq_len * pt_seq_len
freqs = torch.einsum('..., f -> ... f', t, freqs) freqs = repeat(freqs, '... n -> ... (n r)', r = 2) freqs = broadcat((freqs[:, None, :], freqs[None, :, :]), dim = -1)
freqs_cos = freqs.cos().view(-1, freqs.shape[-1]) freqs_sin = freqs.sin().view(-1, freqs.shape[-1])
self.register_buffer("freqs_cos", freqs_cos) self.register_buffer("freqs_sin", freqs_sin)
print('======== shape of rope freq', self.freqs_cos.shape, '========')
def forward(self, t): return t * self.freqs_cos + rotate_half(t) * self.freqs_sin
123456789101112131415161718192021222324252627282930import logging
logger = logging.getLogger(__name__)
__all__ = ["get_vit_lr_decay_rate"]
def get_vit_lr_decay_rate(name, lr_decay_rate=1.0, num_layers=12): """ Calculate lr decay rate for different ViT blocks. Args: name (string): parameter name. lr_decay_rate (float): base lr decay rate. num_layers (int): number of ViT blocks.
Returns: lr decay rate for the given parameter. """ if name.startswith("model_vision."): name = name[len("model_vision."):]
layer_id = num_layers + 1 if name.startswith("backbone"): if ".pos_embed" in name or ".patch_embed" in name: layer_id = 0 elif ".blocks." in name and ".residual." not in name: layer_id = int(name[name.find(".blocks.") :].split(".")[2]) + 1
logger.info("get_vit_lr_decay_rate: name={} num_layers={} layer_id={} lr_decay_rate={}".format(name, num_layers, layer_id, lr_decay_rate ** (num_layers + 1 - layer_id))) return lr_decay_rate ** (num_layers + 1 - layer_id)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644import loggingimport mathimport fvcore.nn.weight_init as weight_initimport torchimport torch.nn as nnimport torch.nn.functional as Ffrom torch import Tensor, Sizefrom typing import Union, Listfrom torch.nn.parameter import Parameterimport numbers
from detectron2.layers import CNNBlockBase, Conv2d, get_normfrom detectron2.modeling.backbone.fpn import _assert_strides_are_log2_contiguous
from fairscale.nn.checkpoint import checkpoint_wrapperfrom timm.models.layers import DropPath, Mlp, trunc_normal_
from detectron2.modeling.backbone import Backbonefrom .utils_eva import ( PatchEmbed, add_decomposed_rel_pos, get_abs_pos, window_partition, window_unpartition,)
logger = logging.getLogger(__name__)
__all__ = ["ViT", "SimpleFeaturePyramid", "get_vit_lr_decay_rate"]
_shape_t = Union[int, List[int], Size]
# steal from beit https://github.com/microsoft/unilm/tree/master/beitclass LayerNormWithForceFP32(nn.Module): __constants__ = ['normalized_shape', 'eps', 'elementwise_affine'] normalized_shape: _shape_t eps: float elementwise_affine: bool
def __init__(self, normalized_shape: _shape_t, eps: float = 1e-5, elementwise_affine: bool = True) -> None: super(LayerNormWithForceFP32, self).__init__() if isinstance(normalized_shape, numbers.Integral): normalized_shape = (normalized_shape,) self.normalized_shape = tuple(normalized_shape) self.eps = eps self.elementwise_affine = elementwise_affine if self.elementwise_affine: self.weight = Parameter(torch.Tensor(*normalized_shape)) self.bias = Parameter(torch.Tensor(*normalized_shape)) else: self.register_parameter('weight', None) self.register_parameter('bias', None) self.reset_parameters()
def reset_parameters(self) -> None: if self.elementwise_affine: nn.init.ones_(self.weight) nn.init.zeros_(self.bias)
def forward(self, input: Tensor) -> Tensor: return F.layer_norm( input.float(), self.normalized_shape, self.weight.float(), self.bias.float(), self.eps).type_as(input)
def extra_repr(self) -> Tensor: return '{normalized_shape}, eps={eps}, ' \ 'elementwise_affine={elementwise_affine}'.format(**self.__dict__)
class Attention(nn.Module): """Multi-head Attention block with relative position embeddings."""
def __init__( self, dim, num_heads=8, qkv_bias=True, beit_like_qkv_bias=False, use_rel_pos=False, rel_pos_zero_init=True, input_size=None, interp_type="vitdet", ): """ Args: dim (int): Number of input channels. num_heads (int): Number of attention heads. qkv_bias (bool: If True, add a learnable bias to query, key, value. rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. input_size (int or None): Input resolution for calculating the relative positional parameter size. """ super().__init__() self.num_heads = num_heads head_dim = dim // num_heads self.scale = head_dim**-0.5
self.beit_like_qkv_bias = beit_like_qkv_bias if beit_like_qkv_bias: self.q_bias = nn.Parameter(torch.zeros(dim)) self.v_bias = nn.Parameter(torch.zeros(dim))
self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias) self.proj = nn.Linear(dim, dim)
self.use_rel_pos = use_rel_pos self.interp_type = interp_type if self.use_rel_pos: # initialize relative positional embeddings self.rel_pos_h = nn.Parameter(torch.zeros(2 * input_size[0] - 1, head_dim)) self.rel_pos_w = nn.Parameter(torch.zeros(2 * input_size[1] - 1, head_dim))
if not rel_pos_zero_init: trunc_normal_(self.rel_pos_h, std=0.02) trunc_normal_(self.rel_pos_w, std=0.02) self.qk_float = False
def forward(self, x): B, H, W, _ = x.shape # qkv with shape (3, B, nHead, H * W, C) if self.beit_like_qkv_bias: qkv_bias = torch.cat((self.q_bias, torch.zeros_like(self.v_bias, requires_grad=False), self.v_bias)) qkv = torch.nn.functional.linear(input=x, weight=self.qkv.weight, bias=qkv_bias) qkv = qkv.reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4) else: qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4) # q, k, v with shape (B * nHead, H * W, C) q, k, v = qkv.reshape(3, B * self.num_heads, H * W, -1).unbind(0)
if self.qk_float: attn = (q.float() * self.scale) @ k.float().transpose(-2, -1) if self.use_rel_pos: attn = add_decomposed_rel_pos(attn, q, self.rel_pos_h, self.rel_pos_w, (H, W), (H, W), self.interp_type) attn = attn.softmax(dim=-1).type_as(x) else: attn = (q * self.scale) @ k.transpose(-2, -1) if self.use_rel_pos: attn = add_decomposed_rel_pos(attn, q, self.rel_pos_h, self.rel_pos_w, (H, W), (H, W), self.interp_type) attn = attn.softmax(dim=-1) x = (attn @ v).view(B, self.num_heads, H, W, -1).permute(0, 2, 3, 1, 4).reshape(B, H, W, -1) x = self.proj(x)
return x
class ResBottleneckBlock(CNNBlockBase): """ The standard bottleneck residual block without the last activation layer. It contains 3 conv layers with kernels 1x1, 3x3, 1x1. """
def __init__( self, in_channels, out_channels, bottleneck_channels, norm="LN", act_layer=nn.GELU, ): """ Args: in_channels (int): Number of input channels. out_channels (int): Number of output channels. bottleneck_channels (int): number of output channels for the 3x3 "bottleneck" conv layers. norm (str or callable): normalization for all conv layers. See :func:`layers.get_norm` for supported format. act_layer (callable): activation for all conv layers. """ super().__init__(in_channels, out_channels, 1)
self.conv1 = Conv2d(in_channels, bottleneck_channels, 1, bias=False) self.norm1 = get_norm(norm, bottleneck_channels) self.act1 = act_layer()
self.conv2 = Conv2d( bottleneck_channels, bottleneck_channels, 3, padding=1, bias=False, ) self.norm2 = get_norm(norm, bottleneck_channels) self.act2 = act_layer()
self.conv3 = Conv2d(bottleneck_channels, out_channels, 1, bias=False) self.norm3 = get_norm(norm, out_channels)
for layer in [self.conv1, self.conv2, self.conv3]: weight_init.c2_msra_fill(layer) for layer in [self.norm1, self.norm2]: layer.weight.data.fill_(1.0) layer.bias.data.zero_() # zero init last norm layer. self.norm3.weight.data.zero_() self.norm3.bias.data.zero_()
def forward(self, x): out = x for layer in self.children(): out = layer(out)
out = x + out return out
class Block(nn.Module): """Transformer blocks with support of window attention and residual propagation blocks"""
def __init__( self, dim, num_heads, mlp_ratio=4.0, qkv_bias=True, drop_path=0.0, norm_layer=LayerNormWithForceFP32, act_layer=nn.GELU, use_rel_pos=False, rel_pos_zero_init=True, window_size=0, use_residual_block=False, input_size=None, beit_like_qkv_bias=False, beit_like_gamma=False, interp_type="vitdet", ): """ Args: dim (int): Number of input channels. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. drop_path (float): Stochastic depth rate. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. If it equals 0, then not use window attention. use_residual_block (bool): If True, use a residual block after the MLP block. input_size (int or None): Input resolution for calculating the relative positional parameter size. beit_like_qkv_bias (bool) beit_like_gamma (bool) """ super().__init__() self.norm1 = norm_layer(dim) self.attn = Attention( dim, num_heads=num_heads, qkv_bias=qkv_bias, use_rel_pos=use_rel_pos, rel_pos_zero_init=rel_pos_zero_init, input_size=input_size if window_size == 0 else (window_size, window_size), beit_like_qkv_bias=beit_like_qkv_bias, interp_type=interp_type, )
self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) self.mlp = Mlp(in_features=dim, hidden_features=int(dim * mlp_ratio), act_layer=act_layer)
self.window_size = window_size
self.use_residual_block = use_residual_block if use_residual_block: # Use a residual block with bottleneck channel as dim // 2 self.residual = ResBottleneckBlock( in_channels=dim, out_channels=dim, bottleneck_channels=dim // 2, norm="LN", act_layer=act_layer, )
self.beit_like_gamma = beit_like_gamma if beit_like_gamma: self.gamma_1 = nn.Parameter(torch.ones((dim)), requires_grad=True) self.gamma_2 = nn.Parameter(torch.ones((dim)), requires_grad=True)
def forward(self, x): shortcut = x x = self.norm1(x) # Window partition if self.window_size > 0: H, W = x.shape[1], x.shape[2] x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x) # Reverse window partition if self.window_size > 0: x = window_unpartition(x, self.window_size, pad_hw, (H, W))
if self.beit_like_gamma: x = shortcut + self.drop_path(self.gamma_1 * x) x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x))) else: x = shortcut + self.drop_path(x) x = x + self.drop_path(self.mlp(self.norm2(x)))
if self.use_residual_block: x = self.residual(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
return x
class ViT(Backbone): """ This module implements Vision Transformer (ViT) backbone in :paper:`vitdet`. "Exploring Plain Vision Transformer Backbones for Object Detection", https://arxiv.org/abs/2203.16527 """
def __init__( self, img_size=1024, patch_size=16, in_chans=3, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, qkv_bias=True, drop_path_rate=0.0, norm_layer=LayerNormWithForceFP32, act_layer=nn.GELU, use_abs_pos=True, use_rel_pos=False, rel_pos_zero_init=True, window_size=0, window_block_indexes=(), residual_block_indexes=(), use_act_checkpoint=False, pretrain_img_size=224, pretrain_use_cls_token=True, out_feature="last_feat", beit_like_qkv_bias=True, beit_like_gamma=False, freeze_patch_embed=False, interp_type="vitdet", frozen_stages=-1, ): """ Args: img_size (int): Input image size. patch_size (int): Patch size. in_chans (int): Number of input image channels. embed_dim (int): Patch embedding dimension. depth (int): Depth of ViT. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. drop_path_rate (float): Stochastic depth rate. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_abs_pos (bool): If True, use absolute positional embeddings. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. window_block_indexes (list): Indexes for blocks using window attention. residual_block_indexes (list): Indexes for blocks using conv propagation. use_act_checkpoint (bool): If True, use activation checkpointing. pretrain_img_size (int): input image size for pretraining models. pretrain_use_cls_token (bool): If True, pretrainig models use class token. out_feature (str): name of the feature from the last block. beit_like_qkv_bias (bool): beit_like_model that has gamma_1 and gamma_2 in blocks and qkv_bias=False beit_like_gamma (bool) freeze_patch_embed (bool) interp_type: "vitdet" for training / fine-ting, "beit" for eval (slightly improvement at a higher res) """ super().__init__() self.pretrain_use_cls_token = pretrain_use_cls_token
self.patch_embed = PatchEmbed( kernel_size=(patch_size, patch_size), stride=(patch_size, patch_size), in_chans=in_chans, embed_dim=embed_dim, )
if use_abs_pos: # Initialize absolute positional embedding with pretrain image size. num_patches = (pretrain_img_size // patch_size) * (pretrain_img_size // patch_size) num_positions = (num_patches + 1) if pretrain_use_cls_token else num_patches self.pos_embed = nn.Parameter(torch.zeros(1, num_positions, embed_dim)) else: self.pos_embed = None
# stochastic depth decay rule dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
self.blocks = nn.ModuleList() if beit_like_qkv_bias: qkv_bias = False for i in range(depth): block = Block( dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, drop_path=dpr[i], norm_layer=norm_layer, act_layer=act_layer, use_rel_pos=use_rel_pos, rel_pos_zero_init=rel_pos_zero_init, window_size=window_size if i in window_block_indexes else 0, use_residual_block=i in residual_block_indexes, input_size=(img_size // patch_size, img_size // patch_size), beit_like_qkv_bias=beit_like_qkv_bias, beit_like_gamma=beit_like_gamma, interp_type=interp_type, ) if use_act_checkpoint and i > frozen_stages - 1: block = checkpoint_wrapper(block) self.blocks.append(block)
self._out_feature_channels = {out_feature: embed_dim} self._out_feature_strides = {out_feature: patch_size} self._out_features = [out_feature]
if self.pos_embed is not None: nn.init.trunc_normal_(self.pos_embed, std=0.02)
self.freeze_patch_embed = freeze_patch_embed self.apply(self._init_weights)
self.frozen_stages = frozen_stages self._freeze_stages()
def _freeze_stages(self): if self.frozen_stages >= 0: self.patch_embed.eval() for param in self.patch_embed.parameters(): param.requires_grad = False
if self.frozen_stages >= 1 and self.pos_embed is not None: self.pos_embed.requires_grad = False
if self.frozen_stages >= 2: for i in range(0, self.frozen_stages - 1): m = self.blocks[i] m.eval() for name, param in m.named_parameters(): vit_lr_decay_rate = get_vit_lr_decay_rate(f"backbone.net.blocks.{i}.{name}", lr_decay_rate=0.9, num_layers=len(self.blocks)) logger.info(f"freeze blocks.{i}.{name} {param.size()} {vit_lr_decay_rate}") param.requires_grad = False
def _init_weights(self, m): if isinstance(m, nn.Linear): nn.init.trunc_normal_(m.weight, std=0.02) if isinstance(m, nn.Linear) and m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, LayerNormWithForceFP32): nn.init.constant_(m.bias, 0) nn.init.constant_(m.weight, 1.0)
if self.freeze_patch_embed: for n, p in self.patch_embed.named_parameters(): p.requires_grad = False
def forward(self, x): x = self.patch_embed(x) if self.pos_embed is not None: x = x + get_abs_pos( self.pos_embed, self.pretrain_use_cls_token, (x.shape[1], x.shape[2]) )
for blk in self.blocks: x = blk(x)
outputs = {self._out_features[0]: x.permute(0, 3, 1, 2)} return outputs
class SimpleFeaturePyramid(Backbone): """ This module implements SimpleFeaturePyramid in :paper:`vitdet`. It creates pyramid features built on top of the input feature map. """
def __init__( self, net, in_feature, out_channels, scale_factors, top_block=None, norm="LN", square_pad=0, ): """ Args: net (Backbone): module representing the subnetwork backbone. Must be a subclass of :class:`Backbone`. in_feature (str): names of the input feature maps coming from the net. out_channels (int): number of channels in the output feature maps. scale_factors (list[float]): list of scaling factors to upsample or downsample the input features for creating pyramid features. top_block (nn.Module or None): if provided, an extra operation will be performed on the output of the last (smallest resolution) pyramid output, and the result will extend the result list. The top_block further downsamples the feature map. It must have an attribute "num_levels", meaning the number of extra pyramid levels added by this block, and "in_feature", which is a string representing its input feature (e.g., p5). norm (str): the normalization to use. square_pad (int): If > 0, require input images to be padded to specific square size. """ super(SimpleFeaturePyramid, self).__init__() assert isinstance(net, Backbone)
self.scale_factors = scale_factors
input_shapes = net.output_shape() strides = [int(input_shapes[in_feature].stride / scale) for scale in scale_factors] _assert_strides_are_log2_contiguous(strides)
dim = input_shapes[in_feature].channels self.stages = [] use_bias = norm == "" for idx, scale in enumerate(scale_factors): out_dim = dim if scale == 4.0: layers = [ nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2), get_norm(norm, dim // 2), nn.GELU(), nn.ConvTranspose2d(dim // 2, dim // 4, kernel_size=2, stride=2), ] out_dim = dim // 4 elif scale == 2.0: layers = [nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2)] out_dim = dim // 2 elif scale == 1.0: layers = [] elif scale == 0.5: layers = [nn.MaxPool2d(kernel_size=2, stride=2)] else: raise NotImplementedError(f"scale_factor={scale} is not supported yet.")
layers.extend( [ Conv2d( out_dim, out_channels, kernel_size=1, bias=use_bias, norm=get_norm(norm, out_channels), ), Conv2d( out_channels, out_channels, kernel_size=3, padding=1, bias=use_bias, norm=get_norm(norm, out_channels), ), ] ) layers = nn.Sequential(*layers)
stage = int(math.log2(strides[idx])) self.add_module(f"simfp_{stage}", layers) self.stages.append(layers)
self.net = net self.in_feature = in_feature self.top_block = top_block # Return feature names are "p<stage>", like ["p2", "p3", ..., "p6"] self._out_feature_strides = {"p{}".format(int(math.log2(s))): s for s in strides} # top block output feature maps. if self.top_block is not None: for s in range(stage, stage + self.top_block.num_levels): self._out_feature_strides["p{}".format(s + 1)] = 2 ** (s + 1)
self._out_features = list(self._out_feature_strides.keys()) self._out_feature_channels = {k: out_channels for k in self._out_features} self._size_divisibility = strides[-1] self._square_pad = square_pad
@property def padding_constraints(self): return { "size_divisiblity": self._size_divisibility, "square_size": self._square_pad, }
def forward(self, x): """ Args: x: Tensor of shape (N,C,H,W). H, W must be a multiple of ``self.size_divisibility``.
Returns: dict[str->Tensor]: mapping from feature map name to pyramid feature map tensor in high to low resolution order. Returned feature names follow the FPN convention: "p<stage>", where stage has stride = 2 ** stage e.g., ["p2", "p3", ..., "p6"]. """ bottom_up_features = self.net(x) features = bottom_up_features[self.in_feature] results = []
for stage in self.stages: results.append(stage(features))
if self.top_block is not None: if self.top_block.in_feature in bottom_up_features: top_block_in_feature = bottom_up_features[self.top_block.in_feature] else: top_block_in_feature = results[self._out_features.index(self.top_block.in_feature)] results.extend(self.top_block(top_block_in_feature)) assert len(self._out_features) == len(results) return {f: res for f, res in zip(self._out_features, results)}
def get_vit_lr_decay_rate(name, lr_decay_rate=1.0, num_layers=12): """ Calculate lr decay rate for different ViT blocks. Args: name (string): parameter name. lr_decay_rate (float): base lr decay rate. num_layers (int): number of ViT blocks.
Returns: lr decay rate for the given parameter. """ if name.startswith("model_vision."): name = name[len("model_vision."):]
layer_id = num_layers + 1 if name.startswith("backbone"): if ".pos_embed" in name or ".patch_embed" in name: layer_id = 0 elif ".blocks." in name and ".residual." not in name: layer_id = int(name[name.find(".blocks.") :].split(".")[2]) + 1
logger.info("get_vit_lr_decay_rate: name={} num_layers={} layer_id={} lr_decay_rate={}".format(name, num_layers, layer_id, lr_decay_rate ** (num_layers + 1 - layer_id))) return lr_decay_rate ** (num_layers + 1 - layer_id)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625import logging
import math
from functools import partial
import fvcore.nn.weight_init as weight_init
import torch
import torch.nn as nn
import torch.nn.functional as F
from detectron2.layers import CNNBlockBase, Conv2d, get_norm
from detectron2.modeling.backbone.fpn import _assert_strides_are_log2_contiguous
from detectron2.modeling.backbone import Backbone
from .utils_eva02 import (
PatchEmbed,
add_decomposed_rel_pos,
get_abs_pos,
window_partition,
window_unpartition,
VisionRotaryEmbeddingFast,
)
try:
import xformers.ops as xops
except:
pass
try:
from apex.normalization import FusedLayerNorm
except:
pass
logger = logging.getLogger(__name__)
__all__ = ["ViT", "SimpleFeaturePyramid", "get_vit_lr_decay_rate"]
class SwiGLU(nn.Module):
def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.SiLU, drop=0.,
norm_layer=nn.LayerNorm, subln=False
):
super().__init__()
out_features = out_features or in_features
hidden_features = hidden_features or in_features
self.w1 = nn.Linear(in_features, hidden_features)
self.w2 = nn.Linear(in_features, hidden_features)
self.act = act_layer()
self.ffn_ln = norm_layer(hidden_features) if subln else nn.Identity()
self.w3 = nn.Linear(hidden_features, out_features)
self.drop = nn.Dropout(drop)
def forward(self, x):
x1 = self.w1(x)
x2 = self.w2(x)
hidden = self.act(x1) * x2
x = self.ffn_ln(hidden)
x = self.w3(x)
x = self.drop(x)
return x
class Attention(nn.Module):
def __init__(
self,
dim,
num_heads=8,
qkv_bias=True,
qk_scale=None,
attn_head_dim=None,
rope=None,
xattn=True,
):
super().__init__()
self.num_heads = num_heads
head_dim = dim // num_heads
if attn_head_dim is not None:
head_dim = attn_head_dim
all_head_dim = head_dim * self.num_heads
self.scale = qk_scale or head_dim ** -0.5
self.q_proj = nn.Linear(dim, all_head_dim, bias=False)
self.k_proj = nn.Linear(dim, all_head_dim, bias=False)
self.v_proj = nn.Linear(dim, all_head_dim, bias=False)
if qkv_bias:
self.q_bias = nn.Parameter(torch.zeros(all_head_dim))
self.v_bias = nn.Parameter(torch.zeros(all_head_dim))
else:
self.q_bias = None
self.v_bias = None
self.rope = rope
self.xattn = xattn
self.proj = nn.Linear(all_head_dim, dim)
def forward(self, x):
B, H, W, C = x.shape
x = x.view(B, -1, C)
N = H * W
q = F.linear(input=x, weight=self.q_proj.weight, bias=self.q_bias)
k = F.linear(input=x, weight=self.k_proj.weight, bias=None)
v = F.linear(input=x, weight=self.v_proj.weight, bias=self.v_bias)
q = q.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3) # B, num_heads, N, C
k = k.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3)
v = v.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3)
## rope
q = self.rope(q).type_as(v)
k = self.rope(k).type_as(v)
if self.xattn and not (torch.jit.is_scripting() or torch.jit.is_tracing()):
q = q.permute(0, 2, 1, 3) # B, num_heads, N, C -> B, N, num_heads, C
k = k.permute(0, 2, 1, 3)
v = v.permute(0, 2, 1, 3)
x = xops.memory_efficient_attention(q, k, v)
x = x.reshape(B, N, -1)
else:
q = q * self.scale
attn = (q @ k.transpose(-2, -1))
attn = attn.softmax(dim=-1).type_as(x)
x = (attn @ v).transpose(1, 2).reshape(B, N, -1)
x = self.proj(x)
x = x.view(B, H, W, C)
return x
class ResBottleneckBlock(CNNBlockBase):
"""
The standard bottleneck residual block without the last activation layer.
It contains 3 conv layers with kernels 1x1, 3x3, 1x1.
"""
def __init__(
self,
in_channels,
out_channels,
bottleneck_channels,
norm="LN",
act_layer=nn.GELU,
):
"""
Args:
in_channels (int): Number of input channels.
out_channels (int): Number of output channels.
bottleneck_channels (int): number of output channels for the 3x3
"bottleneck" conv layers.
norm (str or callable): normalization for all conv layers.
See :func:`layers.get_norm` for supported format.
act_layer (callable): activation for all conv layers.
"""
super().__init__(in_channels, out_channels, 1)
self.conv1 = Conv2d(in_channels, bottleneck_channels, 1, bias=False)
self.norm1 = get_norm(norm, bottleneck_channels)
self.act1 = act_layer()
self.conv2 = Conv2d(
bottleneck_channels,
bottleneck_channels,
3,
padding=1,
bias=False,
)
self.norm2 = get_norm(norm, bottleneck_channels)
self.act2 = act_layer()
self.conv3 = Conv2d(bottleneck_channels, out_channels, 1, bias=False)
self.norm3 = get_norm(norm, out_channels)
for layer in [self.conv1, self.conv2, self.conv3]:
weight_init.c2_msra_fill(layer)
for layer in [self.norm1, self.norm2]:
layer.weight.data.fill_(1.0)
layer.bias.data.zero_()
# zero init last norm layer.
self.norm3.weight.data.zero_()
self.norm3.bias.data.zero_()
def forward(self, x):
out = x
for layer in self.children():
out = layer(out)
out = x + out
return out
class Block(nn.Module):
"""Transformer blocks with support of window attention and residual propagation blocks"""
def __init__(
self,
dim,
num_heads,
mlp_ratio=4*2/3,
qkv_bias=True,
drop_path=0.0,
norm_layer=partial(nn.LayerNorm, eps=1e-6),
window_size=0,
use_residual_block=False,
rope=None,
xattn=True,
):
"""
Args:
dim (int): Number of input channels.
num_heads (int): Number of attention heads in each ViT block.
mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
qkv_bias (bool): If True, add a learnable bias to query, key, value.
drop_path (float): Stochastic depth rate.
norm_layer (nn.Module): Normalization layer.
act_layer (nn.Module): Activation layer.
use_rel_pos (bool): If True, add relative positional embeddings to the attention map.
rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
window_size (int): Window size for window attention blocks. If it equals 0, then not
use window attention.
use_residual_block (bool): If True, use a residual block after the MLP block.
input_size (int or None): Input resolution for calculating the relative positional
parameter size.
"""
super().__init__()
self.norm1 = norm_layer(dim)
self.attn = Attention(
dim,
num_heads=num_heads,
qkv_bias=qkv_bias,
rope=rope,
xattn=xattn,
)
from timm.models.layers import DropPath
self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
self.norm2 = norm_layer(dim)
self.mlp = SwiGLU(
in_features=dim,
hidden_features=int(dim * mlp_ratio),
subln=True,
norm_layer=norm_layer,
)
self.window_size = window_size
self.use_residual_block = use_residual_block
if use_residual_block:
# Use a residual block with bottleneck channel as dim // 2
self.residual = ResBottleneckBlock(
in_channels=dim,
out_channels=dim,
bottleneck_channels=dim // 2,
norm="LN",
)
def forward(self, x):
shortcut = x
x = self.norm1(x)
# Window partition
if self.window_size > 0:
H, W = x.shape[1], x.shape[2]
x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x)
# Reverse window partition
if self.window_size > 0:
x = window_unpartition(x, self.window_size, pad_hw, (H, W))
x = shortcut + self.drop_path(x)
x = x + self.drop_path(self.mlp(self.norm2(x)))
if self.use_residual_block:
x = self.residual(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
return x
class ViT(Backbone):
"""
This module implements Vision Transformer (ViT) backbone in :paper:`vitdet`.
"Exploring Plain Vision Transformer Backbones for Object Detection",
https://arxiv.org/abs/2203.16527
"""
def __init__(
self,
img_size=1024,
patch_size=16,
in_chans=3,
embed_dim=768,
depth=12,
num_heads=12,
mlp_ratio=4*2/3,
qkv_bias=True,
drop_path_rate=0.0,
norm_layer=partial(nn.LayerNorm, eps=1e-6),
act_layer=nn.GELU,
use_abs_pos=True,
use_rel_pos=False,
rope=True,
pt_hw_seq_len=16,
intp_freq=True,
window_size=0,
window_block_indexes=(),
residual_block_indexes=(),
use_act_checkpoint=False,
pretrain_img_size=224,
pretrain_use_cls_token=True,
out_feature="last_feat",
xattn=True,
frozen_stages=-1,
):
"""
Args:
img_size (int): Input image size.
patch_size (int): Patch size.
in_chans (int): Number of input image channels.
embed_dim (int): Patch embedding dimension.
depth (int): Depth of ViT.
num_heads (int): Number of attention heads in each ViT block.
mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
qkv_bias (bool): If True, add a learnable bias to query, key, value.
drop_path_rate (float): Stochastic depth rate.
norm_layer (nn.Module): Normalization layer.
act_layer (nn.Module): Activation layer.
use_abs_pos (bool): If True, use absolute positional embeddings.
use_rel_pos (bool): If True, add relative positional embeddings to the attention map.
rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
window_size (int): Window size for window attention blocks.
window_block_indexes (list): Indexes for blocks using window attention.
residual_block_indexes (list): Indexes for blocks using conv propagation.
use_act_checkpoint (bool): If True, use activation checkpointing.
pretrain_img_size (int): input image size for pretraining models.
pretrain_use_cls_token (bool): If True, pretrainig models use class token.
out_feature (str): name of the feature from the last block.
"""
super().__init__()
self.pretrain_use_cls_token = pretrain_use_cls_token
self.patch_embed = PatchEmbed(
kernel_size=(patch_size, patch_size),
stride=(patch_size, patch_size),
in_chans=in_chans,
embed_dim=embed_dim,
)
if use_abs_pos:
# Initialize absolute positional embedding with pretrain image size.
num_patches = (pretrain_img_size // patch_size) * (pretrain_img_size // patch_size)
num_positions = (num_patches + 1) if pretrain_use_cls_token else num_patches
self.pos_embed = nn.Parameter(torch.zeros(1, num_positions, embed_dim))
else:
self.pos_embed = None
half_head_dim = embed_dim // num_heads // 2
hw_seq_len = img_size // patch_size
self.rope_win = VisionRotaryEmbeddingFast(
dim=half_head_dim,
pt_seq_len=pt_hw_seq_len,
ft_seq_len=window_size if intp_freq else None,
)
self.rope_glb = VisionRotaryEmbeddingFast(
dim=half_head_dim,
pt_seq_len=pt_hw_seq_len,
ft_seq_len=hw_seq_len if intp_freq else None,
)
# stochastic depth decay rule
dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
self.blocks = nn.ModuleList()
for i in range(depth):
block = Block(
dim=embed_dim,
num_heads=num_heads,
mlp_ratio=mlp_ratio,
qkv_bias=qkv_bias,
drop_path=dpr[i],
norm_layer=norm_layer,
window_size=window_size if i in window_block_indexes else 0,
use_residual_block=i in residual_block_indexes,
rope=self.rope_win if i in window_block_indexes else self.rope_glb,
xattn=xattn
)
if use_act_checkpoint and i > frozen_stages - 1:
# TODO: use torch.utils.checkpoint
from fairscale.nn.checkpoint import checkpoint_wrapper
block = checkpoint_wrapper(block)
self.blocks.append(block)
self._out_feature_channels = {out_feature: embed_dim}
self._out_feature_strides = {out_feature: patch_size}
self._out_features = [out_feature]
if self.pos_embed is not None:
nn.init.trunc_normal_(self.pos_embed, std=0.02)
self.apply(self._init_weights)
self.frozen_stages = frozen_stages
self._freeze_stages()
def _freeze_stages(self):
if self.frozen_stages >= 0:
self.patch_embed.eval()
for param in self.patch_embed.parameters():
param.requires_grad = False
if self.frozen_stages >= 1 and self.pos_embed is not None:
self.pos_embed.requires_grad = False
if self.frozen_stages >= 2:
for i in range(0, self.frozen_stages - 1):
m = self.blocks[i]
m.eval()
for name, param in m.named_parameters():
vit_lr_decay_rate = get_vit_lr_decay_rate(f"backbone.net.blocks.{i}.{name}", lr_decay_rate=0.9, num_layers=len(self.blocks))
logger.info(f"freeze blocks.{i}.{name} {param.size()} {vit_lr_decay_rate}")
param.requires_grad = False
def _init_weights(self, m):
if isinstance(m, nn.Linear):
nn.init.trunc_normal_(m.weight, std=0.02)
if isinstance(m, nn.Linear) and m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.LayerNorm):
nn.init.constant_(m.bias, 0)
nn.init.constant_(m.weight, 1.0)
def forward(self, x):
x = self.patch_embed(x)
if self.pos_embed is not None:
x = x + get_abs_pos(
self.pos_embed, self.pretrain_use_cls_token, (x.shape[1], x.shape[2])
)
for blk in self.blocks:
x = blk(x)
outputs = {self._out_features[0]: x.permute(0, 3, 1, 2)}
return outputs
class SimpleFeaturePyramid(Backbone):
"""
This module implements SimpleFeaturePyramid in :paper:`vitdet`.
It creates pyramid features built on top of the input feature map.
"""
def __init__(
self,
net,
in_feature,
out_channels,
scale_factors,
top_block=None,
norm="LN",
square_pad=0,
):
"""
Args:
net (Backbone): module representing the subnetwork backbone.
Must be a subclass of :class:`Backbone`.
in_feature (str): names of the input feature maps coming
from the net.
out_channels (int): number of channels in the output feature maps.
scale_factors (list[float]): list of scaling factors to upsample or downsample
the input features for creating pyramid features.
top_block (nn.Module or None): if provided, an extra operation will
be performed on the output of the last (smallest resolution)
pyramid output, and the result will extend the result list. The top_block
further downsamples the feature map. It must have an attribute
"num_levels", meaning the number of extra pyramid levels added by
this block, and "in_feature", which is a string representing
its input feature (e.g., p5).
norm (str): the normalization to use.
square_pad (int): If > 0, require input images to be padded to specific square size.
"""
super(SimpleFeaturePyramid, self).__init__()
assert isinstance(net, Backbone)
self.scale_factors = scale_factors
input_shapes = net.output_shape()
strides = [int(input_shapes[in_feature].stride / scale) for scale in scale_factors]
_assert_strides_are_log2_contiguous(strides)
dim = input_shapes[in_feature].channels
self.stages = []
use_bias = norm == ""
for idx, scale in enumerate(scale_factors):
out_dim = dim
if scale == 4.0:
layers = [
nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2),
get_norm(norm, dim // 2),
nn.GELU(),
nn.ConvTranspose2d(dim // 2, dim // 4, kernel_size=2, stride=2),
]
out_dim = dim // 4
elif scale == 2.0:
layers = [nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2)]
out_dim = dim // 2
elif scale == 1.0:
layers = []
elif scale == 0.5:
layers = [nn.MaxPool2d(kernel_size=2, stride=2)]
else:
raise NotImplementedError(f"scale_factor={scale} is not supported yet.")
layers.extend(
[
Conv2d(
out_dim,
out_channels,
kernel_size=1,
bias=use_bias,
norm=get_norm(norm, out_channels),
),
Conv2d(
out_channels,
out_channels,
kernel_size=3,
padding=1,
bias=use_bias,
norm=get_norm(norm, out_channels),
),
]
)
layers = nn.Sequential(*layers)
stage = int(math.log2(strides[idx]))
self.add_module(f"simfp_{stage}", layers)
self.stages.append(layers)
self.net = net
self.in_feature = in_feature
self.top_block = top_block
# Return feature names are "p<stage>", like ["p2", "p3", ..., "p6"]
self._out_feature_strides = {"p{}".format(int(math.log2(s))): s for s in strides}
# top block output feature maps.
if self.top_block is not None:
for s in range(stage, stage + self.top_block.num_levels):
self._out_feature_strides["p{}".format(s + 1)] = 2 ** (s + 1)
self._out_features = list(self._out_feature_strides.keys())
self._out_feature_channels = {k: out_channels for k in self._out_features}
self._size_divisibility = strides[-1]
self._square_pad = square_pad
@property
def padding_constraints(self):
return {
"size_divisiblity": self._size_divisibility,
"square_size": self._square_pad,
}
def forward(self, x):
"""
Args:
x: Tensor of shape (N,C,H,W). H, W must be a multiple of ``self.size_divisibility``.
Returns:
dict[str->Tensor]:
mapping from feature map name to pyramid feature map tensor
in high to low resolution order. Returned feature names follow the FPN
convention: "p<stage>", where stage has stride = 2 ** stage e.g.,
["p2", "p3", ..., "p6"].
"""
bottom_up_features = self.net(x)
features = bottom_up_features[self.in_feature]
results = []
for stage in self.stages:
results.append(stage(features))
if self.top_block is not None:
if self.top_block.in_feature in bottom_up_features:
top_block_in_feature = bottom_up_features[self.top_block.in_feature]
else:
top_block_in_feature = results[self._out_features.index(self.top_block.in_feature)]
results.extend(self.top_block(top_block_in_feature))
assert len(self._out_features) == len(results)
return {f: res for f, res in zip(self._out_features, results)}
def get_vit_lr_decay_rate(name, lr_decay_rate=1.0, num_layers=12):
"""
Calculate lr decay rate for different ViT blocks.
Args:
name (string): parameter name.
lr_decay_rate (float): base lr decay rate.
num_layers (int): number of ViT blocks.
Returns:
lr decay rate for the given parameter.
"""
if name.startswith("model_vision."):
name = name[len("model_vision."):]
layer_id = num_layers + 1
if name.startswith("backbone"):
if ".pos_embed" in name or ".patch_embed" in name:
layer_id = 0
elif ".blocks." in name and ".residual." not in name:
layer_id = int(name[name.find(".blocks.") :].split(".")[2]) + 1
logger.info("get_vit_lr_decay_rate: name={} num_layers={} layer_id={} lr_decay_rate={}".format(name, num_layers, layer_id, lr_decay_rate ** (num_layers + 1 - layer_id)))
return lr_decay_rate ** (num_layers + 1 - layer_id)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931import loggingimport mathfrom functools import partial
import fvcore.nn.weight_init as weight_initimport torchimport torch.nn as nnimport torch.nn.functional as F
from detectron2.layers import CNNBlockBase, Conv2d, get_normfrom detectron2.modeling.backbone.fpn import _assert_strides_are_log2_contiguous
from detectron2.modeling.backbone import Backbonefrom .utils_eva02 import ( PatchEmbed, add_decomposed_rel_pos, get_abs_pos, window_partition, window_unpartition, VisionRotaryEmbeddingFast,)
try: import xformers.ops as xopsexcept: pass
try: from apex.normalization import FusedLayerNormexcept: pass
logger = logging.getLogger(__name__)
__all__ = ["ViT", "SimpleFeaturePyramid", "get_vit_lr_decay_rate"]
class DropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks)."""
def __init__(self, drop_prob=None): super(DropPath, self).__init__() self.drop_prob = drop_prob
def forward(self, x): return drop_path(x, self.drop_prob, self.training)
def extra_repr(self) -> str: return "p={}".format(self.drop_prob)
class Mlp(nn.Module): def __init__( self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, norm_layer=nn.LayerNorm, drop=0.0, subln=False, ): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer()
self.ffn_ln = norm_layer(hidden_features) if subln else nn.Identity()
self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop)
def forward(self, x): x = self.fc1(x) x = self.act(x) # x = self.drop(x) # commit this for the orignal BERT implement x = self.ffn_ln(x)
x = self.fc2(x) x = self.drop(x) return x
class SwiGLU(nn.Module): def __init__( self, in_features, hidden_features=None, out_features=None, act_layer=nn.SiLU, drop=0.0, norm_layer=nn.LayerNorm, subln=False, ): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features
self.w1 = nn.Linear(in_features, hidden_features) self.w2 = nn.Linear(in_features, hidden_features)
self.act = act_layer() self.ffn_ln = norm_layer(hidden_features) if subln else nn.Identity() self.w3 = nn.Linear(hidden_features, out_features)
self.drop = nn.Dropout(drop)
def forward(self, x): x1 = self.w1(x) x2 = self.w2(x) hidden = self.act(x1) * x2 x = self.ffn_ln(hidden) x = self.w3(x) x = self.drop(x) return x
class Attention(nn.Module): def __init__( self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0, window_size=0, attn_head_dim=None, xattn=False, rope=None, subln=False, norm_layer=nn.LayerNorm, ): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads if attn_head_dim is not None: head_dim = attn_head_dim all_head_dim = head_dim * self.num_heads self.scale = qk_scale or head_dim**-0.5
self.subln = subln if self.subln: self.q_proj = nn.Linear(dim, all_head_dim, bias=False) self.k_proj = nn.Linear(dim, all_head_dim, bias=False) self.v_proj = nn.Linear(dim, all_head_dim, bias=False) else: self.qkv = nn.Linear(dim, all_head_dim * 3, bias=False)
if qkv_bias: self.q_bias = nn.Parameter(torch.zeros(all_head_dim)) self.v_bias = nn.Parameter(torch.zeros(all_head_dim)) else: self.q_bias = None self.v_bias = None
if window_size and False: self.window_size = window_size self.num_relative_distance = (2 * window_size[0] - 1) * (2 * window_size[1] - 1) + 3 self.relative_position_bias_table = nn.Parameter( torch.zeros(self.num_relative_distance, num_heads) ) # 2*Wh-1 * 2*Ww-1, nH # cls to token & token 2 cls & cls to cls
# get pair-wise relative position index for each token inside the window coords_h = torch.arange(window_size[0]) coords_w = torch.arange(window_size[1]) coords = torch.stack(torch.meshgrid([coords_h, coords_w])) # 2, Wh, Ww coords_flatten = torch.flatten(coords, 1) # 2, Wh*Ww relative_coords = ( coords_flatten[:, :, None] - coords_flatten[:, None, :] ) # 2, Wh*Ww, Wh*Ww relative_coords = relative_coords.permute(1, 2, 0).contiguous() # Wh*Ww, Wh*Ww, 2 relative_coords[:, :, 0] += window_size[0] - 1 # shift to start from 0 relative_coords[:, :, 1] += window_size[1] - 1 relative_coords[:, :, 0] *= 2 * window_size[1] - 1 relative_position_index = torch.zeros( size=(window_size[0] * window_size[1] + 1,) * 2, dtype=relative_coords.dtype ) relative_position_index[1:, 1:] = relative_coords.sum(-1) # Wh*Ww, Wh*Ww relative_position_index[0, 0:] = self.num_relative_distance - 3 relative_position_index[0:, 0] = self.num_relative_distance - 2 relative_position_index[0, 0] = self.num_relative_distance - 1
self.register_buffer("relative_position_index", relative_position_index) else: self.window_size = None self.relative_position_bias_table = None self.relative_position_index = None
self.attn_drop = nn.Dropout(attn_drop) self.inner_attn_ln = norm_layer(all_head_dim) if subln else nn.Identity() # self.proj = nn.Linear(all_head_dim, all_head_dim) self.proj = nn.Linear(all_head_dim, dim) self.proj_drop = nn.Dropout(proj_drop) self.xattn = xattn self.xattn_drop = attn_drop
self.rope = rope
def forward(self, x, rel_pos_bias=None, attn_mask=None): # B, N, C = x.shape
B, H, W, C = x.shape x = x.view(B, -1, C) N = H * W
if self.subln: q = F.linear(input=x, weight=self.q_proj.weight, bias=self.q_bias) k = F.linear(input=x, weight=self.k_proj.weight, bias=None) v = F.linear(input=x, weight=self.v_proj.weight, bias=self.v_bias)
q = q.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3) # B, num_heads, N, C k = k.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3) v = v.reshape(B, N, self.num_heads, -1).permute(0, 2, 1, 3) else:
qkv_bias = None if self.q_bias is not None: qkv_bias = torch.cat( (self.q_bias, torch.zeros_like(self.v_bias, requires_grad=False), self.v_bias) )
qkv = F.linear(input=x, weight=self.qkv.weight, bias=qkv_bias) qkv = qkv.reshape(B, N, 3, self.num_heads, -1).permute( 2, 0, 3, 1, 4 ) # 3, B, num_heads, N, C q, k, v = qkv[0], qkv[1], qkv[2]
if self.rope: # slightly fast impl # q_t = q[:, :, 1:, :] # ro_q_t = self.rope(q_t) # q = torch.cat((q[:, :, :1, :], ro_q_t), -2).type_as(v)
# k_t = k[:, :, 1:, :] # ro_k_t = self.rope(k_t) # k = torch.cat((k[:, :, :1, :], ro_k_t), -2).type_as(v)
## rope q = self.rope(q).type_as(v) k = self.rope(k).type_as(v)
if self.xattn and not (torch.jit.is_scripting() or torch.jit.is_tracing()): q = q.permute(0, 2, 1, 3) # B, num_heads, N, C -> B, N, num_heads, C k = k.permute(0, 2, 1, 3) v = v.permute(0, 2, 1, 3)
x = xops.memory_efficient_attention( q, k, v, p=self.xattn_drop, scale=self.scale, ) x = x.reshape(B, N, -1) x = self.inner_attn_ln(x) x = self.proj(x) x = self.proj_drop(x) else: q = q * self.scale attn = q @ k.transpose(-2, -1)
if self.relative_position_bias_table is not None: relative_position_bias = self.relative_position_bias_table[ self.relative_position_index.view(-1) ].view( self.window_size[0] * self.window_size[1] + 1, self.window_size[0] * self.window_size[1] + 1, -1, ) # Wh*Ww,Wh*Ww,nH relative_position_bias = relative_position_bias.permute( 2, 0, 1 ).contiguous() # nH, Wh*Ww, Wh*Ww attn = attn + relative_position_bias.unsqueeze(0).type_as(attn)
if rel_pos_bias is not None: attn = attn + rel_pos_bias.type_as(attn)
if attn_mask is not None: attn_mask = attn_mask.bool() attn = attn.masked_fill(~attn_mask[:, None, None, :], float("-inf"))
attn = attn.softmax(dim=-1) attn = self.attn_drop(attn)
x = (attn @ v).transpose(1, 2).reshape(B, N, -1) x = self.inner_attn_ln(x) x = self.proj(x) x = self.proj_drop(x)
x = x.view(B, H, W, C)
return x
class ResBottleneckBlock(CNNBlockBase): """ The standard bottleneck residual block without the last activation layer. It contains 3 conv layers with kernels 1x1, 3x3, 1x1. """
def __init__( self, in_channels, out_channels, bottleneck_channels, norm="LN", act_layer=nn.GELU, ): """ Args: in_channels (int): Number of input channels. out_channels (int): Number of output channels. bottleneck_channels (int): number of output channels for the 3x3 "bottleneck" conv layers. norm (str or callable): normalization for all conv layers. See :func:`layers.get_norm` for supported format. act_layer (callable): activation for all conv layers. """ super().__init__(in_channels, out_channels, 1)
self.conv1 = Conv2d(in_channels, bottleneck_channels, 1, bias=False) self.norm1 = get_norm(norm, bottleneck_channels) self.act1 = act_layer()
self.conv2 = Conv2d( bottleneck_channels, bottleneck_channels, 3, padding=1, bias=False, ) self.norm2 = get_norm(norm, bottleneck_channels) self.act2 = act_layer()
self.conv3 = Conv2d(bottleneck_channels, out_channels, 1, bias=False) self.norm3 = get_norm(norm, out_channels)
for layer in [self.conv1, self.conv2, self.conv3]: weight_init.c2_msra_fill(layer) for layer in [self.norm1, self.norm2]: layer.weight.data.fill_(1.0) layer.bias.data.zero_() # zero init last norm layer. self.norm3.weight.data.zero_() self.norm3.bias.data.zero_()
def forward(self, x): out = x for layer in self.children(): out = layer(out)
out = x + out return out
class Block(nn.Module): """Transformer blocks with support of window attention and residual propagation blocks"""
def __init__( self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, init_values=None, act_layer=nn.GELU, norm_layer=partial(nn.LayerNorm, eps=1e-6), window_size=0, use_residual_block=False, attn_head_dim=None, rope=None, xattn=False, postnorm=False, subln=False, naiveswiglu=False, ): """ Args: dim (int): Number of input channels. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. drop_path (float): Stochastic depth rate. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. If it equals 0, then not use window attention. use_residual_block (bool): If True, use a residual block after the MLP block. input_size (int or None): Input resolution for calculating the relative positional parameter size. """ super().__init__() self.norm1 = norm_layer(dim) self.attn = Attention( dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop, window_size=window_size, attn_head_dim=attn_head_dim, rope=rope, xattn=xattn, subln=subln, norm_layer=norm_layer, )
from timm.models.layers import DropPath
self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio)
if naiveswiglu: self.mlp = SwiGLU( in_features=dim, hidden_features=mlp_hidden_dim, subln=subln, norm_layer=norm_layer, ) else: self.mlp = Mlp( in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, subln=subln, drop=drop, )
if init_values is not None and init_values > 0: self.gamma_1 = nn.Parameter(init_values * torch.ones((dim)), requires_grad=True) self.gamma_2 = nn.Parameter(init_values * torch.ones((dim)), requires_grad=True) else: self.gamma_1, self.gamma_2 = None, None
self.postnorm = postnorm
self.window_size = window_size
self.use_residual_block = use_residual_block if use_residual_block: # Use a residual block with bottleneck channel as dim // 2 self.residual = ResBottleneckBlock( in_channels=dim, out_channels=dim, bottleneck_channels=dim // 2, norm="LN", )
def forward(self, x, rel_pos_bias=None, attn_mask=None): if self.gamma_1 is None: if self.postnorm: shortcut = x
# Window partition if self.window_size > 0: H, W = x.shape[1], x.shape[2] x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)
# Reverse window partition if self.window_size > 0: x = window_unpartition(x, self.window_size, pad_hw, (H, W))
x = self.norm1(x) x = shortcut + self.drop_path(x)
# x = x + self.drop_path(self.norm1(self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask))) x = x + self.drop_path(self.norm2(self.mlp(x))) else: shortcut = x x = self.norm1(x)
# Window partition if self.window_size > 0: H, W = x.shape[1], x.shape[2] x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)
# Reverse window partition if self.window_size > 0: x = window_unpartition(x, self.window_size, pad_hw, (H, W))
x = shortcut + self.drop_path(x)
# x = x + self.drop_path(self.attn(self.norm1(x), rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)) x = x + self.drop_path(self.mlp(self.norm2(x))) else: if self.postnorm: shortcut = x
# Window partition if self.window_size > 0: H, W = x.shape[1], x.shape[2] x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)
# Reverse window partition if self.window_size > 0: x = window_unpartition(x, self.window_size, pad_hw, (H, W))
x = self.norm1(x) x = shortcut + self.drop_path(self.gamma_1 * x)
# x = x + self.drop_path(self.gamma_1 * self.norm1(self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask))) x = x + self.drop_path(self.gamma_2 * self.norm2(self.mlp(x))) else: shortcut = x x = self.norm1(x)
# Window partition if self.window_size > 0: H, W = x.shape[1], x.shape[2] x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x, rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)
# Reverse window partition if self.window_size > 0: x = window_unpartition(x, self.window_size, pad_hw, (H, W))
x = shortcut + self.drop_path(self.gamma_1 * x)
# x = x + self.drop_path(self.gamma_1 * self.attn(self.norm1(x), rel_pos_bias=rel_pos_bias, attn_mask=attn_mask)) x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x)))
if self.use_residual_block: x = self.residual(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
return x
class ViT(Backbone): """ This module implements Vision Transformer (ViT) backbone in :paper:`vitdet`. "Exploring Plain Vision Transformer Backbones for Object Detection", https://arxiv.org/abs/2203.16527 """
def __init__( self, img_size=1024, patch_size=16, in_chans=3, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.0, norm_layer=partial(nn.LayerNorm, eps=1e-6), init_values=None, use_abs_pos=True, use_rel_pos=False, rope=False, postnorm=False, pt_hw_seq_len=16, intp_freq=False, naiveswiglu=False, subln=False, window_size=0, window_block_indexes=(), residual_block_indexes=(), use_act_checkpoint=False, pretrain_img_size=224, pretrain_use_cls_token=True, out_feature="last_feat", xattn=False, frozen_stages=-1, ): """ Args: img_size (int): Input image size. patch_size (int): Patch size. in_chans (int): Number of input image channels. embed_dim (int): Patch embedding dimension. depth (int): Depth of ViT. num_heads (int): Number of attention heads in each ViT block. mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. qkv_bias (bool): If True, add a learnable bias to query, key, value. drop_path_rate (float): Stochastic depth rate. norm_layer (nn.Module): Normalization layer. act_layer (nn.Module): Activation layer. use_abs_pos (bool): If True, use absolute positional embeddings. use_rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. window_block_indexes (list): Indexes for blocks using window attention. residual_block_indexes (list): Indexes for blocks using conv propagation. use_act_checkpoint (bool): If True, use activation checkpointing. pretrain_img_size (int): input image size for pretraining models. pretrain_use_cls_token (bool): If True, pretrainig models use class token. out_feature (str): name of the feature from the last block. """ super().__init__() self.pretrain_use_cls_token = pretrain_use_cls_token
self.patch_embed = PatchEmbed( kernel_size=(patch_size, patch_size), stride=(patch_size, patch_size), in_chans=in_chans, embed_dim=embed_dim, )
if use_abs_pos: # Initialize absolute positional embedding with pretrain image size. num_patches = (pretrain_img_size // patch_size) * (pretrain_img_size // patch_size) num_positions = (num_patches + 1) if pretrain_use_cls_token else num_patches self.pos_embed = nn.Parameter(torch.zeros(1, num_positions, embed_dim)) else: self.pos_embed = None
if rope: half_head_dim = embed_dim // num_heads // 2 hw_seq_len = img_size // patch_size self.rope_win = VisionRotaryEmbeddingFast( dim=half_head_dim, pt_seq_len=pt_hw_seq_len, ft_seq_len=window_size if intp_freq else None, ) self.rope_glb = VisionRotaryEmbeddingFast( dim=half_head_dim, pt_seq_len=pt_hw_seq_len, ft_seq_len=hw_seq_len if intp_freq else None, ) else: self.rope_win = None self.rope_glb = None
self.naiveswiglu = naiveswiglu
# stochastic depth decay rule dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)]
self.blocks = nn.ModuleList() for i in range(depth): block = Block( dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale, drop=drop_rate, attn_drop=attn_drop_rate, drop_path=dpr[i], norm_layer=norm_layer, init_values=init_values, window_size=window_size if i in window_block_indexes else 0, postnorm=postnorm, subln=subln, naiveswiglu=naiveswiglu, use_residual_block=i in residual_block_indexes, rope=self.rope_win if i in window_block_indexes else self.rope_glb, xattn=xattn, ) if use_act_checkpoint and i > frozen_stages - 1: # TODO: use torch.utils.checkpoint from fairscale.nn.checkpoint import checkpoint_wrapper
block = checkpoint_wrapper(block) self.blocks.append(block)
self._out_feature_channels = {out_feature: embed_dim} self._out_feature_strides = {out_feature: patch_size} self._out_features = [out_feature]
if self.pos_embed is not None: nn.init.trunc_normal_(self.pos_embed, std=0.02)
self.apply(self._init_weights)
self.frozen_stages = frozen_stages self._freeze_stages()
def _freeze_stages(self): if self.frozen_stages >= 0: self.patch_embed.eval() for param in self.patch_embed.parameters(): param.requires_grad = False
if self.frozen_stages >= 1 and self.pos_embed is not None: self.pos_embed.requires_grad = False
if self.frozen_stages >= 2: for i in range(0, self.frozen_stages - 1): m = self.blocks[i] m.eval() for name, param in m.named_parameters(): vit_lr_decay_rate = get_vit_lr_decay_rate(f"backbone.net.blocks.{i}.{name}", lr_decay_rate=0.9, num_layers=len(self.blocks)) logger.info(f"freeze blocks.{i}.{name} {param.size()} {vit_lr_decay_rate}") param.requires_grad = False
def _init_weights(self, m): if isinstance(m, nn.Linear): nn.init.trunc_normal_(m.weight, std=0.02) if isinstance(m, nn.Linear) and m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, nn.LayerNorm): nn.init.constant_(m.bias, 0) nn.init.constant_(m.weight, 1.0)
def forward(self, x): x = self.patch_embed(x) if self.pos_embed is not None: x = x + get_abs_pos( self.pos_embed, self.pretrain_use_cls_token, (x.shape[1], x.shape[2]) )
for blk in self.blocks: x = blk(x)
outputs = {self._out_features[0]: x.permute(0, 3, 1, 2)} return outputs
class SimpleFeaturePyramid(Backbone): """ This module implements SimpleFeaturePyramid in :paper:`vitdet`. It creates pyramid features built on top of the input feature map. """
def __init__( self, net, in_feature, out_channels, scale_factors, top_block=None, norm="LN", square_pad=0, ): """ Args: net (Backbone): module representing the subnetwork backbone. Must be a subclass of :class:`Backbone`. in_feature (str): names of the input feature maps coming from the net. out_channels (int): number of channels in the output feature maps. scale_factors (list[float]): list of scaling factors to upsample or downsample the input features for creating pyramid features. top_block (nn.Module or None): if provided, an extra operation will be performed on the output of the last (smallest resolution) pyramid output, and the result will extend the result list. The top_block further downsamples the feature map. It must have an attribute "num_levels", meaning the number of extra pyramid levels added by this block, and "in_feature", which is a string representing its input feature (e.g., p5). norm (str): the normalization to use. square_pad (int): If > 0, require input images to be padded to specific square size. """ super(SimpleFeaturePyramid, self).__init__() assert isinstance(net, Backbone)
self.scale_factors = scale_factors
input_shapes = net.output_shape() strides = [int(input_shapes[in_feature].stride / scale) for scale in scale_factors] _assert_strides_are_log2_contiguous(strides)
dim = input_shapes[in_feature].channels self.stages = [] use_bias = norm == "" for idx, scale in enumerate(scale_factors): out_dim = dim if scale == 4.0: layers = [ nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2), get_norm(norm, dim // 2), nn.GELU(), nn.ConvTranspose2d(dim // 2, dim // 4, kernel_size=2, stride=2), ] out_dim = dim // 4 elif scale == 2.0: layers = [nn.ConvTranspose2d(dim, dim // 2, kernel_size=2, stride=2)] out_dim = dim // 2 elif scale == 1.0: layers = [] elif scale == 0.5: layers = [nn.MaxPool2d(kernel_size=2, stride=2)] else: raise NotImplementedError(f"scale_factor={scale} is not supported yet.")
layers.extend( [ Conv2d( out_dim, out_channels, kernel_size=1, bias=use_bias, norm=get_norm(norm, out_channels), ), Conv2d( out_channels, out_channels, kernel_size=3, padding=1, bias=use_bias, norm=get_norm(norm, out_channels), ), ] ) layers = nn.Sequential(*layers)
stage = int(math.log2(strides[idx])) self.add_module(f"simfp_{stage}", layers) self.stages.append(layers)
self.net = net self.in_feature = in_feature self.top_block = top_block # Return feature names are "p<stage>", like ["p2", "p3", ..., "p6"] self._out_feature_strides = {"p{}".format(int(math.log2(s))): s for s in strides} # top block output feature maps. if self.top_block is not None: for s in range(stage, stage + self.top_block.num_levels): self._out_feature_strides["p{}".format(s + 1)] = 2 ** (s + 1)
self._out_features = list(self._out_feature_strides.keys()) self._out_feature_channels = {k: out_channels for k in self._out_features} self._size_divisibility = strides[-1] self._square_pad = square_pad
@property def padding_constraints(self): return { "size_divisiblity": self._size_divisibility, "square_size": self._square_pad, }
def forward(self, x): """ Args: x: Tensor of shape (N,C,H,W). H, W must be a multiple of ``self.size_divisibility``.
Returns: dict[str->Tensor]: mapping from feature map name to pyramid feature map tensor in high to low resolution order. Returned feature names follow the FPN convention: "p<stage>", where stage has stride = 2 ** stage e.g., ["p2", "p3", ..., "p6"]. """ bottom_up_features = self.net(x) features = bottom_up_features[self.in_feature] results = []
for stage in self.stages: results.append(stage(features)) # with torch.cuda.amp.autocast(enabled=False): # results.append(stage(features.float())) if torch.any(torch.isnan(results[-1])): v = results[-1] print("stage", len(results), v, v.size(), v.max(), v.min(), "all finite:", torch.all(torch.isfinite(v)), "any nan:", torch.any(torch.isnan(v))) v = features print(self.in_feature, v, v.size(), v.max(), v.min(), "all finite:", torch.all(torch.isfinite(v)), "any nan:", torch.any(torch.isnan(v))) print("stage parameters", stage, sum([_.sum() for _ in stage.parameters()])) for name, param in stage.named_parameters(): print(name, param.size(), param.sum(), param.max(), param.min(), "all finite:", torch.all(torch.isfinite(param)), "any nan:", torch.any(torch.isnan(param))) for name, buf in stage.named_buffers(): print(name, buf.size(), buf.sum(), buf.max(), buf.min(), "all finite:", torch.all(torch.isfinite(buf)), "any nan:", torch.any(torch.isnan(buf)))
with torch.cuda.amp.autocast(enabled=False): results.pop() results.append(stage(features.float())) # results[-1] = stage(features.float())
if self.top_block is not None: if self.top_block.in_feature in bottom_up_features: top_block_in_feature = bottom_up_features[self.top_block.in_feature] else: top_block_in_feature = results[self._out_features.index(self.top_block.in_feature)] results.extend(self.top_block(top_block_in_feature)) # with torch.cuda.amp.autocast(enabled=False): # results.extend(self.top_block(top_block_in_feature.float())) if torch.any(torch.isnan(results[-1])): v = results[-1] print(len(results), v, v.size(), v.max(), v.min(), "all finite:", torch.all(torch.isfinite(v)), "any nan:", torch.any(torch.isnan(v))) v = top_block_in_feature print(self.top_block.in_feature, v, v.size(), v.max(), v.min(), "all finite:", torch.all(torch.isfinite(v)), "any nan:", torch.any(torch.isnan(v))) print("top_block parameters", self.top_block, sum([_.sum() for _ in self.top_block.parameters()])) assert len(self._out_features) == len(results) return {f: res for f, res in zip(self._out_features, results)}
def get_vit_lr_decay_rate(name, lr_decay_rate=1.0, num_layers=12): """ Calculate lr decay rate for different ViT blocks. Args: name (string): parameter name. lr_decay_rate (float): base lr decay rate. num_layers (int): number of ViT blocks.
Returns: lr decay rate for the given parameter. """ if name.startswith("model_vision."): name = name[len("model_vision.") :]
layer_id = num_layers + 1 if name.startswith("backbone"): if ".pos_embed" in name or ".patch_embed" in name: layer_id = 0 elif ".blocks." in name and ".residual." not in name: layer_id = int(name[name.find(".blocks.") :].split(".")[2]) + 1
logger.info( "get_vit_lr_decay_rate: name={} num_layers={} layer_id={} lr_decay_rate={}".format( name, num_layers, layer_id, lr_decay_rate ** (num_layers + 1 - layer_id) ) ) return lr_decay_rate ** (num_layers + 1 - layer_id)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107import torchfrom torch import nnfrom torch.cuda.amp import autocast
from transformers import ( AutoConfig, AutoModelForSeq2SeqLM, AutoTokenizer, BertConfig, BertModel, RobertaConfig, RobertaModel,)
class Bert(nn.Module): def __init__( self, pretrained_model_name_or_path, dtype="float32", **kwargs, ): super().__init__(**kwargs)
self.dtype = getattr(torch, dtype)
self.config = BertConfig.from_pretrained( pretrained_model_name_or_path=pretrained_model_name_or_path ) self.bert_model = BertModel.from_pretrained( pretrained_model_name_or_path=pretrained_model_name_or_path, add_pooling_layer=False, ) self.tokenizer = AutoTokenizer.from_pretrained( pretrained_model_name_or_path=pretrained_model_name_or_path )
self.bert_model.eval() for name, param in self.bert_model.named_parameters(): param.requires_grad = False param.data = param.data.to(self.dtype)
self.register_buffer("unused_tensor", torch.zeros(1), False)
self.text_list_to_feature = {}
@property def device(self): return self.unused_tensor.device
@autocast(enabled=False) @torch.no_grad() def forward_text(self, text_list, cache=False):
if cache and tuple(text_list) in self.text_list_to_feature: return self.text_list_to_feature[tuple(text_list)]
tokenized = self.tokenizer.batch_encode_plus( text_list, max_length=256, padding="max_length" if True else "longest", return_special_tokens_mask=True, return_tensors="pt", truncation=True, ).to(self.device)
input_ids = tokenized.input_ids # (bs, seq_len) attention_mask = tokenized.attention_mask # (bs, seq_len)
max_batch_size = 500 if len(input_ids) > max_batch_size: chunck_num = len(input_ids) // max_batch_size + 1 outputss = [ self.bert_model( input_ids=input_ids[ chunck_id * max_batch_size : (chunck_id + 1) * max_batch_size ], attention_mask=attention_mask[ chunck_id * max_batch_size : (chunck_id + 1) * max_batch_size ], ) for chunck_id in range(chunck_num) ]
last_hidden_state = torch.cat( [outputs.last_hidden_state for outputs in outputss], dim=0 ) else: outputs = self.bert_model( input_ids=input_ids, attention_mask=attention_mask, )
last_hidden_state = outputs.last_hidden_state
end_token_idx = input_ids.argmin(dim=-1) - 1
ret = { "end_token_idx": end_token_idx, "attention_mask": attention_mask, "last_hidden_state": last_hidden_state, }
if cache: self.text_list_to_feature[tuple(text_list)] = ret
return ret123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224import loggingfrom collections import OrderedDictfrom typing import List, Union
import torchfrom torch import nn
from clip.simple_tokenizer import SimpleTokenizer as _Tokenizer
__all__ = ["tokenize"]
count = 0
class LayerNorm(nn.LayerNorm): """Subclass torch's LayerNorm to handle fp16."""
def forward(self, x: torch.Tensor): orig_type = x.dtype ret = super().forward(x.type(torch.float32)) return ret.type(orig_type)
class QuickGELU(nn.Module): def forward(self, x: torch.Tensor): return x * torch.sigmoid(1.702 * x)
class ResidualAttentionBlock(nn.Module): def __init__(self, d_model: int, n_head: int, attn_mask: torch.Tensor = None): super().__init__()
self.attn = nn.MultiheadAttention(d_model, n_head) self.ln_1 = LayerNorm(d_model) self.mlp = nn.Sequential( OrderedDict( [ ("c_fc", nn.Linear(d_model, d_model * 4)), ("gelu", QuickGELU()), ("c_proj", nn.Linear(d_model * 4, d_model)), ] ) ) self.ln_2 = LayerNorm(d_model) self.attn_mask = attn_mask
def attention(self, x: torch.Tensor): self.attn_mask = ( self.attn_mask.to(dtype=x.dtype, device=x.device) if self.attn_mask is not None else None ) return self.attn(x, x, x, need_weights=False, attn_mask=self.attn_mask)[0]
def forward(self, x: torch.Tensor): x = x + self.attention(self.ln_1(x)) x = x + self.mlp(self.ln_2(x)) return x
class Transformer(nn.Module): def __init__(self, width: int, layers: int, heads: int, attn_mask: torch.Tensor = None): super().__init__() self.width = width self.layers = layers self.resblocks = nn.Sequential( *[ResidualAttentionBlock(width, heads, attn_mask) for _ in range(layers)] )
def forward(self, x: torch.Tensor): return self.resblocks(x)
class CLIPTEXT(nn.Module): def __init__( self, embed_dim=512, context_length=77, vocab_size=49408, transformer_width=512, transformer_heads=8, transformer_layers=12, ): super().__init__()
self._tokenizer = _Tokenizer() self.context_length = context_length
self.transformer = Transformer( width=transformer_width, layers=transformer_layers, heads=transformer_heads, attn_mask=self.build_attention_mask(), )
self.vocab_size = vocab_size self.token_embedding = nn.Embedding(vocab_size, transformer_width) self.positional_embedding = nn.Parameter( torch.empty(self.context_length, transformer_width) ) self.ln_final = LayerNorm(transformer_width)
self.text_projection = nn.Parameter(torch.empty(transformer_width, embed_dim))
self.initialize_parameters()
def initialize_parameters(self): nn.init.normal_(self.token_embedding.weight, std=0.02) nn.init.normal_(self.positional_embedding, std=0.01)
proj_std = (self.transformer.width**-0.5) * ((2 * self.transformer.layers) ** -0.5) attn_std = self.transformer.width**-0.5 fc_std = (2 * self.transformer.width) ** -0.5 for block in self.transformer.resblocks: nn.init.normal_(block.attn.in_proj_weight, std=attn_std) nn.init.normal_(block.attn.out_proj.weight, std=proj_std) nn.init.normal_(block.mlp.c_fc.weight, std=fc_std) nn.init.normal_(block.mlp.c_proj.weight, std=proj_std)
if self.text_projection is not None: nn.init.normal_(self.text_projection, std=self.transformer.width**-0.5)
def build_attention_mask(self): mask = torch.empty(self.context_length, self.context_length) mask.fill_(float("-inf")) mask.triu_(1) # zero out the lower diagonal return mask
@property def device(self): return self.text_projection.device
@property def dtype(self): return self.text_projection.dtype
def tokenize(self, texts: Union[str, List[str]], context_length: int = 77) -> torch.LongTensor: """ """ if isinstance(texts, str): texts = [texts]
sot_token = self._tokenizer.encoder["<|startoftext|>"] eot_token = self._tokenizer.encoder["<|endoftext|>"] all_tokens = [[sot_token] + self._tokenizer.encode(text) + [eot_token] for text in texts] result = torch.zeros(len(all_tokens), context_length, dtype=torch.long)
for i, tokens in enumerate(all_tokens): if len(tokens) > context_length: st = torch.randint(len(tokens) - context_length + 1, (1,))[0].item() tokens = tokens[st : st + context_length] result[i, : len(tokens)] = torch.tensor(tokens)
return result
def encode_text(self, text): x = self.token_embedding(text).type(self.dtype) # [batch_size, n_ctx, d_model] x = x + self.positional_embedding.type(self.dtype) x = x.permute(1, 0, 2) # NLD -> LND x = self.transformer(x) x = x.permute(1, 0, 2) # LND -> NLD x = self.ln_final(x).type(self.dtype) x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] @ self.text_projection return x
def forward(self, captions): """ captions: list of strings """ text = self.tokenize(captions).to(self.device) # B x L x D features = self.encode_text(text) # B x D return features
def build_clip_text_encoder(model_path, pretrain=True): logger = logging.getLogger(__name__) if pretrain: logger.info("Loading pretrained CLIP " + model_path) import clip
print(model_path) pretrained_model, _ = clip.load(model_path, device="cpu") state_dict = pretrained_model.state_dict() to_delete_keys = ["logit_scale", "input_resolution", "context_length", "vocab_size"] + [ k for k in state_dict.keys() if k.startswith("visual.") ] for k in to_delete_keys: if k in state_dict: del state_dict[k]
embed_dim = state_dict["text_projection"].shape[1] context_length = state_dict["positional_embedding"].shape[0] vocab_size = state_dict["token_embedding.weight"].shape[0] transformer_width = state_dict["ln_final.weight"].shape[0] transformer_heads = transformer_width // 64 transformer_layers = len( set(k.split(".")[2] for k in state_dict if k.startswith(f"transformer.resblocks")) )
text_encoder = CLIPTEXT( embed_dim, context_length, vocab_size, transformer_width, transformer_heads, transformer_layers, ) text_encoder.load_state_dict(state_dict)
else: logger.info("Building CLIPTEXT") text_encoder = CLIPTEXT(embed_dim=embed_dim) return text_encoder
def get_clip_embeddings(text_model, vocabulary, prompt="a "): if isinstance(text_model, str): text_encoder = build_clip_text_encoder(text_model, pretrain=True) text_encoder.eval() else: text_encoder = text_model text_encoder.eval() texts = [prompt + x for x in vocabulary] emb = text_encoder(texts).detach().contiguous() return emb123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148import torchimport torch.nn as nnfrom torch.cuda.amp import autocast
from .eva02_clip import create_model_and_transforms, get_tokenizer
class EVA02CLIP(nn.Module): def __init__( self, clip_model="EVA02-CLIP-B-16", cache_dir="EVA02_CLIP_B_psz16_s8B.pt", dtype="float32", max_batch_size=2560, ): super().__init__() self.net, _, _ = create_model_and_transforms( clip_model, pretrained=cache_dir, force_custom_clip=True ) self.tokenizer = get_tokenizer(clip_model)
if dtype == "bfloat16": self.dtype = torch.bfloat16 elif dtype == "float16": self.dtype = torch.float16 else: self.dtype = torch.float32
del self.net.visual self.net.eval() for name, param in self.net.named_parameters(): param.requires_grad = False param.data = param.data.to(self.dtype)
self.register_buffer("unused_tensor", torch.zeros(1), False)
self.text_list_to_feature = {}
self.max_batch_size = max_batch_size
@property def device(self): return self.unused_tensor.device
def infer_image(self, features): x = features["image"][0] x = self.net.encode_image(x) return x
@autocast(enabled=False) @torch.no_grad() def encode_text(self, text_list, cache=False): if cache and tuple(text_list) in self.text_list_to_feature: return self.text_list_to_feature[tuple(text_list)]
text_token = self.tokenizer(text_list, context_length=77).to(self.device)
max_batch_size = self.max_batch_size if self.device.type == "cpu" or torch.cuda.mem_get_info(self.device)[0] / 1024**3 < 5: max_batch_size = min(256, max_batch_size) if len(text_token) > max_batch_size: chunck_num = len(text_token) // max_batch_size + 1 encoder_outputs = torch.cat( [ self.net.encode_text( text_token[chunck_id * max_batch_size : (chunck_id + 1) * max_batch_size] ) for chunck_id in range(chunck_num) ], dim=0, ) else: encoder_outputs = self.net.encode_text(text_token)
ret = { "last_hidden_state_eot": encoder_outputs, }
if cache: self.text_list_to_feature[tuple(text_list)] = ret
return ret
@autocast(enabled=False) @torch.no_grad() def forward_text(self, text_list, cache=False): if cache and tuple(text_list) in self.text_list_to_feature: return self.text_list_to_feature[tuple(text_list)]
text_token = self.tokenizer(text_list, context_length=77).to(self.device)
max_batch_size = self.max_batch_size if self.device.type == "cpu" or torch.cuda.mem_get_info(self.device)[0] / 1024**3 < 5: max_batch_size = min(256, max_batch_size) if len(text_token) > max_batch_size: chunck_num = len(text_token) // max_batch_size + 1 encoder_outputs = [ self.custom_encode_text( text_token[chunck_id * max_batch_size : (chunck_id + 1) * max_batch_size], self.net.text, ) for chunck_id in range(chunck_num) ] encoder_outputs_x = torch.cat([x for (x, _) in encoder_outputs], dim=0) encoder_outputs_xx = torch.cat([xx for (_, xx) in encoder_outputs], dim=0) else: encoder_outputs_x, encoder_outputs_xx = self.custom_encode_text( text_token, self.net.text )
end_token_idx = text_token.argmax(dim=-1) attention_mask = end_token_idx.new_zeros(encoder_outputs_xx.size()[:2]) for i in range(attention_mask.size(0)): attention_mask[i, : end_token_idx[i] + 1] = 1
ret = { "end_token_idx": end_token_idx, "attention_mask": attention_mask, "last_hidden_state": encoder_outputs_xx, "last_hidden_state_eot": encoder_outputs_x, }
if cache: self.text_list_to_feature[tuple(text_list)] = ret
return ret
@autocast(enabled=False) @torch.no_grad() def custom_encode_text(self, text, m, normalize: bool = False): cast_dtype = m.transformer.get_cast_dtype()
x = m.token_embedding(text).to(cast_dtype) # [batch_size, n_ctx, d_model]
x = x + m.positional_embedding.to(cast_dtype) x = x.permute(1, 0, 2) # NLD -> LND x = m.transformer(x, attn_mask=m.attn_mask) x = x.permute(1, 0, 2) # LND -> NLD x = m.ln_final(x) # [batch_size, n_ctx, transformer.width]
xx = x @ m.text_projection
x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] @ m.text_projection
return ( F.normalize(x, dim=-1) if normalize else x, F.normalize(xx, dim=-1) if normalize else xx, )12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879# Contrastive Language-Image Pre-Training with EVA (EVA-CLIP)
**Table of Contents**
- [Contrastive Language-Image Pre-Training with EVA (EVA-CLIP)](#contrastive-language-image-pre-training-with-eva-eva-clip) - [Model Card](#model-card) - [Usage](#usage) - [Acknowledgement](#acknowledgement)
## Model Card
<div align="center">
| model name | #param. | precision | data | batch size | IN-1K zero-shot top-1 | weight ||:-----------:|:------:|:------:|:------:|:------:|:------:|:------:|| `eva_clip_psz14` | 1.3B | `fp16` | [LAION-400M](https://laion.ai/laion-400-open-dataset/) | 41K | 78.5 | [🤗 HF link](https://huggingface.co/BAAI/EVA/blob/main/eva_clip_psz14.pt) (`2GB`) |
</div>
> The ImageNet-1K zero-shot classification performance is higher than our paper (`78.5` *v.s.* `78.2`) because of longer training.
We choose to train a 1.3B CLIP model, not because it is easy, but because it is hard. Please refer to [this note](https://docs.google.com/document/d/1FXosAZ3wMrzThgnWR6KSkXIz4IMItq3umDGos38pJps/edit) for a glance of the challenges in training very large CLIP.
To our knowledge, EVA-CLIP is **the largest performant open-sourced CLIP model** evaluated via zero-shot classification performance.We will updates the results in our paper soon.For more details of EVA-CLIP, please refer to Section 2.3.5 of [our paper](https://arxiv.org/pdf/2211.07636.pdf).
We hope open-sourcing EVA-CLIP can facilitate future research in multi-modal learning, representation leaning, AIGC, *etc*.
## Usage
The usege of EVA-CLIP is similar to [OpenAI CLIP](https://github.com/openai/CLIP) and [Open CLIP](https://github.com/mlfoundations/open_clip).Here we provide a showcase in zero-shot image classification.
First, [install PyTorch 1.7.1](https://pytorch.org/get-started/locally/) (or later) and torchvision, as well as small additional dependencies, and then install this repo as a Python package. On a CUDA GPU machine, the following will do the trick:
```bash$ conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0$ pip install ftfy regex tqdm```
The training code of our 1.3B EVA-CLIP will be available at [FlagAI](https://github.com/FlagAI-Open/FlagAI). Please stay tuned.
An example:```pythonimport torchfrom eva_clip import build_eva_model_and_transformsfrom clip import tokenizefrom PIL import Image
eva_clip_path = "/path/to/eva_clip_psz14.pt" # https://huggingface.co/BAAI/EVA/blob/main/eva_clip_psz14.ptmodel_name = "EVA_CLIP_g_14"image_path = "CLIP.png"caption = ["a diagram", "a dog", "a cat"]
device = "cuda" if torch.cuda.is_available() else "cpu"model, preprocess = build_eva_model_and_transforms(model_name, pretrained=eva_clip_path)model = model.to(device)
image = preprocess(Image.open(image_path)).unsqueeze(0).to(device)text = tokenize(caption).to(device)
with torch.no_grad(): image_features = model.encode_image(image) text_features = model.encode_text(text) image_features /= image_features.norm(dim=-1, keepdim=True) text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs) # prints: [1.0000e+00, 2.0857e-10, 4.8534e-12]```
## AcknowledgementEVA-CLIP is bulit with [OpenAI CLIP](https://github.com/openai/CLIP), [Open CLIP](https://github.com/mlfoundations/open_clip) and [CLIP Benchmark](https://github.com/LAION-AI/CLIP_benchmark). Thanks for their awesome work!1234567# from .clip import *# from .eva_clip import *# from .model import *# from .simple_tokenizer import *# from .vit_model import *
from .eva_clip import build_eva_model_and_transforms123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232import hashlibimport osimport urllibimport warningsfrom typing import Any, Union, Listfrom pkg_resources import packaging
import torchfrom PIL import Imagefrom torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalizefrom tqdm import tqdm
from .model import build_modelfrom .simple_tokenizer import SimpleTokenizer as _Tokenizer
try: from torchvision.transforms import InterpolationMode BICUBIC = InterpolationMode.BICUBICexcept ImportError: BICUBIC = Image.BICUBIC
if packaging.version.parse(torch.__version__) < packaging.version.parse("1.7.1"): warnings.warn("PyTorch version 1.7.1 or higher is recommended")
__all__ = ["available_models", "load", "tokenize"]_tokenizer = _Tokenizer()
_MODELS = { "RN50": "https://openaipublic.azureedge.net/clip/models/afeb0e10f9e5a86da6080e35cf09123aca3b358a0c3e3b6c78a7b63bc04b6762/RN50.pt", "RN101": "https://openaipublic.azureedge.net/clip/models/8fa8567bab74a42d41c5915025a8e4538c3bdbe8804a470a72f30b0d94fab599/RN101.pt", "RN50x4": "https://openaipublic.azureedge.net/clip/models/7e526bd135e493cef0776de27d5f42653e6b4c8bf9e0f653bb11773263205fdd/RN50x4.pt", "RN50x16": "https://openaipublic.azureedge.net/clip/models/52378b407f34354e150460fe41077663dd5b39c54cd0bfd2b27167a4a06ec9aa/RN50x16.pt", "RN50x64": "https://openaipublic.azureedge.net/clip/models/be1cfb55d75a9666199fb2206c106743da0f6468c9d327f3e0d0a543a9919d9c/RN50x64.pt", "ViT-B/32": "https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt", "ViT-B/16": "https://openaipublic.azureedge.net/clip/models/5806e77cd80f8b59890b7e101eabd078d9fb84e6937f9e85e4ecb61988df416f/ViT-B-16.pt", "ViT-L/14": "https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt", "ViT-L/14@336px": "https://openaipublic.azureedge.net/clip/models/3035c92b350959924f9f00213499208652fc7ea050643e8b385c2dac08641f02/ViT-L-14-336px.pt",}
def _download(url: str, root: str): os.makedirs(root, exist_ok=True) filename = os.path.basename(url)
expected_sha256 = url.split("/")[-2] download_target = os.path.join(root, filename)
if os.path.exists(download_target) and not os.path.isfile(download_target): raise RuntimeError(f"{download_target} exists and is not a regular file")
if os.path.isfile(download_target): if hashlib.sha256(open(download_target, "rb").read()).hexdigest() == expected_sha256: return download_target else: warnings.warn(f"{download_target} exists, but the SHA256 checksum does not match; re-downloading the file")
with urllib.request.urlopen(url) as source, open(download_target, "wb") as output: with tqdm(total=int(source.info().get("Content-Length")), ncols=80, unit='iB', unit_scale=True, unit_divisor=1024) as loop: while True: buffer = source.read(8192) if not buffer: break
output.write(buffer) loop.update(len(buffer))
if hashlib.sha256(open(download_target, "rb").read()).hexdigest() != expected_sha256: raise RuntimeError(f"Model has been downloaded but the SHA256 checksum does not not match")
return download_target
def _convert_image_to_rgb(image): return image.convert("RGB")
def _transform(n_px): return Compose([ Resize(n_px, interpolation=BICUBIC), CenterCrop(n_px), _convert_image_to_rgb, ToTensor(), Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)), ])
def available_models() -> List[str]: """Returns the names of available CLIP models""" return list(_MODELS.keys())
def load(name: str, device: Union[str, torch.device] = "cuda" if torch.cuda.is_available() else "cpu", jit: bool = False, download_root: str = None): """Load a CLIP model
Parameters ---------- name : str A model name listed by `clip.available_models()`, or the path to a model checkpoint containing the state_dict
device : Union[str, torch.device] The device to put the loaded model
jit : bool Whether to load the optimized JIT model or more hackable non-JIT model (default).
download_root: str path to download the model files; by default, it uses "~/.cache/clip"
Returns ------- model : torch.nn.Module The CLIP model
preprocess : Callable[[PIL.Image], torch.Tensor] A torchvision transform that converts a PIL image into a tensor that the returned model can take as its input """ if name in _MODELS: model_path = _download(_MODELS[name], download_root or os.path.expanduser("~/.cache/clip")) elif os.path.isfile(name): model_path = name else: raise RuntimeError(f"Model {name} not found; available models = {available_models()}")
try: # loading JIT archive model = torch.jit.load(model_path, map_location=device if jit else "cpu").eval() state_dict = None except RuntimeError: # loading saved state dict if jit: warnings.warn(f"File {model_path} is not a JIT archive. Loading as a state dict instead") jit = False state_dict = torch.load(model_path, map_location="cpu")
if not jit: model = build_model(state_dict or model.state_dict()).to(device) if str(device) == "cpu": model.float() return model, _transform(model.visual.input_resolution)
# patch the device names device_holder = torch.jit.trace(lambda: torch.ones([]).to(torch.device(device)), example_inputs=[]) device_node = [n for n in device_holder.graph.findAllNodes("prim::Constant") if "Device" in repr(n)][-1]
def patch_device(module): try: graphs = [module.graph] if hasattr(module, "graph") else [] except RuntimeError: graphs = []
if hasattr(module, "forward1"): graphs.append(module.forward1.graph)
for graph in graphs: for node in graph.findAllNodes("prim::Constant"): if "value" in node.attributeNames() and str(node["value"]).startswith("cuda"): node.copyAttributes(device_node)
model.apply(patch_device) patch_device(model.encode_image) patch_device(model.encode_text)
# patch dtype to float32 on CPU if str(device) == "cpu": float_holder = torch.jit.trace(lambda: torch.ones([]).float(), example_inputs=[]) float_input = list(float_holder.graph.findNode("aten::to").inputs())[1] float_node = float_input.node()
def patch_float(module): try: graphs = [module.graph] if hasattr(module, "graph") else [] except RuntimeError: graphs = []
if hasattr(module, "forward1"): graphs.append(module.forward1.graph)
for graph in graphs: for node in graph.findAllNodes("aten::to"): inputs = list(node.inputs()) for i in [1, 2]: # dtype can be the second or third argument to aten::to() if inputs[i].node()["value"] == 5: inputs[i].node().copyAttributes(float_node)
model.apply(patch_float) patch_float(model.encode_image) patch_float(model.encode_text)
model.float()
return model, _transform(model.input_resolution.item())
def tokenize(texts: Union[str, List[str]], context_length: int = 77, truncate: bool = False) -> torch.LongTensor: """ Returns the tokenized representation of given input string(s)
Parameters ---------- texts : Union[str, List[str]] An input string or a list of input strings to tokenize
context_length : int The context length to use; all CLIP models use 77 as the context length
truncate: bool Whether to truncate the text in case its encoding is longer than the context length
Returns ------- A two-dimensional tensor containing the resulting tokens, shape = [number of input strings, context_length] """ if isinstance(texts, str): texts = [texts]
sot_token = _tokenizer.encoder["<|startoftext|>"] eot_token = _tokenizer.encoder["<|endoftext|>"] all_tokens = [[sot_token] + _tokenizer.encode(text) + [eot_token] for text in texts] result = torch.zeros(len(all_tokens), context_length, dtype=torch.long)
for i, tokens in enumerate(all_tokens): if len(tokens) > context_length: if truncate: tokens = tokens[:context_length] tokens[-1] = eot_token else: raise RuntimeError(f"Input {texts[i]} is too long for context length {context_length}") result[i, :len(tokens)] = torch.tensor(tokens)
return result123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173import jsonimport loggingimport osimport pathlibimport refrom copy import deepcopyfrom pathlib import Pathfrom tkinter import Efrom typing import Optional, Tuple, Any, Union, List
import torchfrom torchvision.transforms import Normalize, Compose, InterpolationMode, ToTensor, Resize, CenterCrop
from .eva_model import EVA_CLIP, convert_weights_to_fp16
OPENAI_DATASET_MEAN = (0.48145466, 0.4578275, 0.40821073)OPENAI_DATASET_STD = (0.26862954, 0.26130258, 0.27577711)
_MODEL_CONFIG_PATHS = [Path(__file__).parent / f"model_configs/"]_MODEL_CONFIGS = {} # directory (model_name: config) of model architecture configs
def _natural_key(string_): return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_.lower())]
def _rescan_model_configs(): global _MODEL_CONFIGS
config_ext = ('.json',) config_files = [] for config_path in _MODEL_CONFIG_PATHS: if config_path.is_file() and config_path.suffix in config_ext: config_files.append(config_path) elif config_path.is_dir(): for ext in config_ext: config_files.extend(config_path.glob(f'*{ext}'))
for cf in config_files: with open(cf, 'r') as f: model_cfg = json.load(f) if all(a in model_cfg for a in ('embed_dim', 'vision_cfg', 'text_cfg')): _MODEL_CONFIGS[cf.stem] = model_cfg
_MODEL_CONFIGS = {k: v for k, v in sorted(_MODEL_CONFIGS.items(), key=lambda x: _natural_key(x[0]))}
_rescan_model_configs() # initial populate of model config registry
def list_models(): """ enumerate available model architectures based on config files """ return list(_MODEL_CONFIGS.keys())
def add_model_config(path): """ add model config path or file and update registry """ if not isinstance(path, Path): path = Path(path) _MODEL_CONFIG_PATHS.append(path) _rescan_model_configs()
def get_model_config(model_name): if model_name in _MODEL_CONFIGS: return deepcopy(_MODEL_CONFIGS[model_name]) else: return None
def load_state_dict(checkpoint_path: str, map_location: str='cpu', model_key='model|module|state_dict'): checkpoint = torch.load(checkpoint_path, map_location=map_location)
for mk in model_key.split('|'): if isinstance(checkpoint, dict) and mk in checkpoint: state_dict = checkpoint[mk] break else: state_dict = checkpoint if next(iter(state_dict.items()))[0].startswith('module'): state_dict = {k[7:]: v for k, v in state_dict.items()} return state_dict
def load_checkpoint(model, checkpoint_path, model_key="model|module|state_dict", strict=True): state_dict = load_state_dict(checkpoint_path, model_key=model_key) incompatible_keys = model.load_state_dict(state_dict, strict=strict) print(incompatible_keys) return incompatible_keys
def create_model( model_name: str, pretrained: str = '', precision: str = 'fp32', device: torch.device = torch.device('cpu'), force_quick_gelu: bool = False,): model_name = model_name.replace('/', '-') # for callers using old naming with / in ViT names
if model_name in _MODEL_CONFIGS: logging.info(f'Loading {model_name} model config.') model_cfg = deepcopy(_MODEL_CONFIGS[model_name]) else: logging.error(f'Model config for {model_name} not found; available models {list_models()}.') raise RuntimeError(f'Model config for {model_name} not found.')
if force_quick_gelu: # override for use of QuickGELU on non-OpenAI transformer models model_cfg["quick_gelu"] = True
model = EVA_CLIP(**model_cfg)
if pretrained: load_checkpoint(model, pretrained) model.to(device=device) if precision == "fp16": assert device.type != 'cpu' convert_weights_to_fp16(model)
# set image / mean metadata from pretrained_cfg if available, or use default model.visual.image_mean = OPENAI_DATASET_MEAN model.visual.image_std = OPENAI_DATASET_STD
return model
def _convert_to_rgb(image): return image.convert('RGB')
def image_transform( image_size: int, mean: Optional[Tuple[float, ...]] = None, std: Optional[Tuple[float, ...]] = None,): mean = mean or OPENAI_DATASET_MEAN if not isinstance(mean, (list, tuple)): mean = (mean,) * 3
std = std or OPENAI_DATASET_STD if not isinstance(std, (list, tuple)): std = (std,) * 3 if isinstance(image_size, (list, tuple)) and image_size[0] == image_size[1]: # for square size, pass size as int so that Resize() uses aspect preserving shortest edge image_size = image_size[0]
normalize = Normalize(mean=mean, std=std) transforms = [ Resize(image_size, interpolation=InterpolationMode.BICUBIC), CenterCrop(image_size), ] transforms.extend([ _convert_to_rgb, ToTensor(), normalize, ]) return Compose(transforms)
def build_eva_model_and_transforms( model_name: str, pretrained: str = '', precision: str = 'fp32', device: torch.device = torch.device('cpu'), force_quick_gelu: bool = False, image_mean: Optional[Tuple[float, ...]] = None, image_std: Optional[Tuple[float, ...]] = None,): model = create_model( model_name, pretrained, precision, device, force_quick_gelu=force_quick_gelu)
image_mean = image_mean or getattr(model.visual, 'image_mean', None) image_std = image_std or getattr(model.visual, 'image_std', None) preprocess_val = image_transform(model.visual.image_size, mean=image_mean, std=image_std)
return model, preprocess_val123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368""" CLIP Model
Adapted from https://github.com/mlfoundations/open_clip
"""import mathfrom dataclasses import dataclassfrom typing import Tuple, Union, Callable, Optionalfrom functools import partialimport numpy as npfrom collections import OrderedDict
import torchimport torch.nn.functional as Ffrom torch import nn
from .vit_model import VisionTransformer
try: from apex.normalization import FusedLayerNormexcept: pass
class LayerNorm(nn.LayerNorm): """Subclass torch's LayerNorm to handle fp16."""
def forward(self, x: torch.Tensor): orig_type = x.dtype x = F.layer_norm(x, self.normalized_shape, self.weight, self.bias, self.eps) return x.to(orig_type)
class QuickGELU(nn.Module): # NOTE This is slower than nn.GELU or nn.SiLU and uses more GPU memory def forward(self, x: torch.Tensor): return x * torch.sigmoid(1.702 * x)
class Attention(nn.Module): def __init__( self, dim, num_heads=8, qkv_bias=True, scaled_cosine=False, scale_heads=False, logit_scale_max=math.log(1. / 0.01), attn_drop=0., proj_drop=0. ): super().__init__() self.scaled_cosine = scaled_cosine self.scale_heads = scale_heads assert dim % num_heads == 0, 'dim should be divisible by num_heads' self.num_heads = num_heads self.head_dim = dim // num_heads self.scale = self.head_dim ** -0.5 self.logit_scale_max = logit_scale_max
# keeping in_proj in this form (instead of nn.Linear) to match weight scheme of original self.in_proj_weight = nn.Parameter(torch.randn((dim * 3, dim)) * self.scale) if qkv_bias: self.in_proj_bias = nn.Parameter(torch.zeros(dim * 3)) else: self.in_proj_bias = None
if self.scaled_cosine: self.logit_scale = nn.Parameter(torch.log(10 * torch.ones((num_heads, 1, 1)))) else: self.logit_scale = None self.attn_drop = nn.Dropout(attn_drop) if self.scale_heads: self.head_scale = nn.Parameter(torch.ones((num_heads, 1, 1))) else: self.head_scale = None self.out_proj = nn.Linear(dim, dim) self.out_drop = nn.Dropout(proj_drop)
def forward(self, x, attn_mask: Optional[torch.Tensor] = None): L, N, C = x.shape q, k, v = F.linear(x, self.in_proj_weight, self.in_proj_bias).chunk(3, dim=-1) q = q.contiguous().view(L, N * self.num_heads, -1).transpose(0, 1) k = k.contiguous().view(L, N * self.num_heads, -1).transpose(0, 1) v = v.contiguous().view(L, N * self.num_heads, -1).transpose(0, 1)
if self.logit_scale is not None: attn = torch.bmm(F.normalize(q, dim=-1), F.normalize(k, dim=-1).transpose(-1, -2)) logit_scale = torch.clamp(self.logit_scale, max=self.logit_scale_max).exp() attn = attn.view(N, self.num_heads, L, L) * logit_scale attn = attn.view(-1, L, L) else: q = q * self.scale attn = torch.bmm(q, k.transpose(-1, -2))
if attn_mask is not None: if attn_mask.dtype == torch.bool: new_attn_mask = torch.zeros_like(attn_mask, dtype=q.dtype) new_attn_mask.masked_fill_(attn_mask, float("-inf")) attn_mask = new_attn_mask attn += attn_mask
attn = attn.softmax(dim=-1) attn = self.attn_drop(attn)
x = torch.bmm(attn, v) if self.head_scale is not None: x = x.view(N, self.num_heads, L, C) * self.head_scale x = x.view(-1, L, C) x = x.transpose(0, 1).reshape(L, N, C) x = self.out_proj(x) x = self.out_drop(x) return x
class ResidualAttentionBlock(nn.Module): def __init__( self, d_model: int, n_head: int, mlp_ratio: float = 4.0, act_layer: Callable = nn.GELU, scale_cosine_attn: bool = False, scale_heads: bool = False, scale_attn: bool = False, scale_fc: bool = False, ): super().__init__()
self.ln_1 = LayerNorm(d_model) # FIXME torchscript issues need to be resolved for custom attention # if scale_cosine_attn or scale_heads: # self.attn = Attention( # d_model, n_head, # scaled_cosine=scale_cosine_attn, # scale_heads=scale_heads, # ) self.attn = nn.MultiheadAttention(d_model, n_head) self.ln_attn = LayerNorm(d_model) if scale_attn else nn.Identity()
self.ln_2 = LayerNorm(d_model) mlp_width = int(d_model * mlp_ratio) self.mlp = nn.Sequential(OrderedDict([ ("c_fc", nn.Linear(d_model, mlp_width)), ('ln', LayerNorm(mlp_width) if scale_fc else nn.Identity()), ("gelu", act_layer()), ("c_proj", nn.Linear(mlp_width, d_model)) ]))
def attention(self, x: torch.Tensor, attn_mask: Optional[torch.Tensor] = None): return self.attn(x, x, x, need_weights=False, attn_mask=attn_mask)[0] # FIXME torchscript issues need resolving for custom attention option to work # if self.use_torch_attn: # return self.attn(x, x, x, need_weights=False, attn_mask=attn_mask)[0] # else: # return self.attn(x, attn_mask=attn_mask)
def cross_attention(self, x: torch.Tensor, context: torch.Tensor, attn_mask: Optional[torch.Tensor] = None): return self.attn(x, context, context, need_weights=False, attn_mask=attn_mask)[0]
def forward(self, x: torch.Tensor, attn_mask: Optional[torch.Tensor] = None): x = x + self.ln_attn(self.attention(self.ln_1(x), attn_mask=attn_mask)) x = x + self.mlp(self.ln_2(x)) return x
class Transformer(nn.Module): def __init__(self, width: int, layers: int, heads: int, mlp_ratio: float = 4.0, act_layer: Callable = nn.GELU): super().__init__() self.width = width self.layers = layers
self.resblocks = nn.ModuleList([ ResidualAttentionBlock(width, heads, mlp_ratio, act_layer=act_layer) for _ in range(layers) ])
def forward(self, x: torch.Tensor, attn_mask: Optional[torch.Tensor] = None): for r in self.resblocks: x = r(x, attn_mask=attn_mask) return x
class TextTransformer(nn.Module): def __init__( self, vocab_size: int, width: int, layers: int, heads: int, context_length: int, embed_dim: int, act_layer: Callable = nn.GELU, ): super().__init__() self.transformer = Transformer( width=width, layers=layers, heads=heads, act_layer=act_layer, ) self.context_length = context_length self.vocab_size = vocab_size self.token_embedding = nn.Embedding(vocab_size, width) self.positional_embedding = nn.Parameter(torch.empty(context_length, width)) self.ln_final = LayerNorm(width)
self.text_projection = nn.Parameter(torch.empty(width, embed_dim)) self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07)) self.register_buffer('attn_mask', self.build_attention_mask(), persistent=False)
self.init_parameters()
def init_parameters(self): nn.init.normal_(self.token_embedding.weight, std=0.02) nn.init.normal_(self.positional_embedding, std=0.01) nn.init.constant_(self.logit_scale, np.log(1 / 0.07))
proj_std = (self.transformer.width ** -0.5) * ((2 * self.transformer.layers) ** -0.5) attn_std = self.transformer.width ** -0.5 fc_std = (2 * self.transformer.width) ** -0.5 for block in self.transformer.resblocks: nn.init.normal_(block.attn.in_proj_weight, std=attn_std) nn.init.normal_(block.attn.out_proj.weight, std=proj_std) nn.init.normal_(block.mlp.c_fc.weight, std=fc_std) nn.init.normal_(block.mlp.c_proj.weight, std=proj_std)
if self.text_projection is not None: nn.init.normal_(self.text_projection, std=self.transformer.width ** -0.5)
def build_attention_mask(self): # lazily create causal attention mask, with full attention between the vision tokens # pytorch uses additive attention mask; fill with -inf mask = torch.empty(self.context_length, self.context_length) mask.fill_(float("-inf")) mask.triu_(1) # zero out the lower diagonal return mask
def forward_features(self, text: torch.Tensor): x = self.token_embedding(text) # [batch_size, n_ctx, d_model]
x = x + self.positional_embedding x = x.permute(1, 0, 2) # NLD -> LND x = self.transformer(x, attn_mask=self.attn_mask) x = x.permute(1, 0, 2) # LND -> NLD x = self.ln_final(x)
# x.shape = [batch_size, n_ctx, transformer.width] # take features from the eot embedding (eot_token is the highest number in each sequence) x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] return x
def forward(self, x: torch.Tensor): x = self.forward_features(x) if self.text_projection is not None: x = x @ self.text_projection return x
@dataclassclass CLIPVisionCfg: layers: Union[Tuple[int, int, int, int], int] = 12 width: int = 768 head_width: int = 64 mlp_ratio: float = 4.0 patch_size: int = 16 image_size: Union[Tuple[int, int], int] = 224 layer_scale_init_value: float = None drop_path_rate: float = 0. fusedLN: bool = False xattn: bool = False
@dataclassclass CLIPTextCfg: context_length: int = 77 vocab_size: int = 49408 width: int = 512 heads: int = 8 layers: int = 12
class EVA_CLIP(nn.Module): def __init__( self, embed_dim: int, vision_cfg: CLIPVisionCfg, text_cfg: CLIPTextCfg, quick_gelu: bool = False, ): super().__init__() if isinstance(vision_cfg, dict): vision_cfg = CLIPVisionCfg(**vision_cfg) if isinstance(text_cfg, dict): text_cfg = CLIPTextCfg(**text_cfg)
# OpenAI models are pretrained w/ QuickGELU but native nn.GELU is both faster and more # memory efficient in recent PyTorch releases (>= 1.10). act_layer = QuickGELU if quick_gelu else nn.GELU
vision_heads = vision_cfg.width // vision_cfg.head_width self.visual = VisionTransformer( img_size=vision_cfg.image_size, patch_size=vision_cfg.patch_size, num_classes=embed_dim, use_mean_pooling=False, init_values=vision_cfg.layer_scale_init_value, embed_dim=vision_cfg.width, depth=vision_cfg.layers, num_heads=vision_heads, mlp_ratio=vision_cfg.mlp_ratio, qkv_bias=True, drop_path_rate=vision_cfg.drop_path_rate, norm_layer= partial(FusedLayerNorm, eps=1e-6) if vision_cfg.fusedLN else partial(nn.LayerNorm, eps=1e-6), xattn=vision_cfg.xattn )
self.text = TextTransformer( vocab_size=text_cfg.vocab_size, width=text_cfg.width, layers=text_cfg.layers, heads=text_cfg.heads, context_length=text_cfg.context_length, embed_dim=embed_dim, act_layer=act_layer )
def encode_image(self, image): return self.visual(image)
def encode_text(self, text): return self.text(text)
def forward(self, image, text): if image is None: return self.encode_text(text) elif text is None: return self.encode_image(image) image_features = self.encode_image(image) image_features = F.normalize(image_features, dim=-1)
text_features = self.encode_text(text) text_features = F.normalize(text_features, dim=-1)
return image_features, text_features, self.text.logit_scale.exp()
def convert_weights_to_fp16(model: nn.Module): """Convert applicable model parameters to fp16"""
def _convert_weights_to_fp16(l): if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Linear)): l.weight.data = l.weight.data.half() if l.bias is not None: l.bias.data = l.bias.data.half()
if isinstance(l, (nn.MultiheadAttention, Attention)): for attr in [*[f"{s}_proj_weight" for s in ["in", "q", "k", "v"]], "in_proj_bias", "bias_k", "bias_v"]: tensor = getattr(l, attr) if tensor is not None: tensor.data = tensor.data.half()
for name in ["text_projection", "proj"]: if hasattr(l, name): attr = getattr(l, name) if attr is not None: attr.data = attr.data.half()
model.apply(_convert_weights_to_fp16)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471from collections import OrderedDictfrom typing import Tuple, Union
import numpy as npimport torchimport mathimport torch.nn.functional as Ffrom torch import nn
class Bottleneck(nn.Module): expansion = 4
def __init__(self, inplanes, planes, stride=1): super().__init__()
# all conv layers have stride 1. an avgpool is performed after the second convolution when stride > 1 self.conv1 = nn.Conv2d(inplanes, planes, 1, bias=False) self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, 3, padding=1, bias=False) self.bn2 = nn.BatchNorm2d(planes)
self.avgpool = nn.AvgPool2d(stride) if stride > 1 else nn.Identity()
self.conv3 = nn.Conv2d(planes, planes * self.expansion, 1, bias=False) self.bn3 = nn.BatchNorm2d(planes * self.expansion)
self.relu = nn.ReLU(inplace=True) self.downsample = None self.stride = stride
if stride > 1 or inplanes != planes * Bottleneck.expansion: # downsampling layer is prepended with an avgpool, and the subsequent convolution has stride 1 self.downsample = nn.Sequential(OrderedDict([ ("-1", nn.AvgPool2d(stride)), ("0", nn.Conv2d(inplanes, planes * self.expansion, 1, stride=1, bias=False)), ("1", nn.BatchNorm2d(planes * self.expansion)) ]))
def forward(self, x: torch.Tensor): identity = x
out = self.relu(self.bn1(self.conv1(x))) out = self.relu(self.bn2(self.conv2(out))) out = self.avgpool(out) out = self.bn3(self.conv3(out))
if self.downsample is not None: identity = self.downsample(x)
out += identity out = self.relu(out) return out
class AttentionPool2d(nn.Module): def __init__(self, spacial_dim: int, embed_dim: int, num_heads: int, output_dim: int = None): super().__init__() self.positional_embedding = nn.Parameter(torch.randn(spacial_dim ** 2 + 1, embed_dim) / embed_dim ** 0.5) self.k_proj = nn.Linear(embed_dim, embed_dim) self.q_proj = nn.Linear(embed_dim, embed_dim) self.v_proj = nn.Linear(embed_dim, embed_dim) self.c_proj = nn.Linear(embed_dim, output_dim or embed_dim) self.num_heads = num_heads
def forward(self, x, return_all_tokens=False): x = x.reshape(x.shape[0], x.shape[1], x.shape[2] * x.shape[3]).permute(2, 0, 1) # NCHW -> (HW)NC x = torch.cat([x.mean(dim=0, keepdim=True), x], dim=0) # (HW+1)NC x = x + self.positional_embedding[:, None, :].to(x.dtype) # (HW+1)NC x, _ = F.multi_head_attention_forward( query=x, key=x, value=x, embed_dim_to_check=x.shape[-1], num_heads=self.num_heads, q_proj_weight=self.q_proj.weight, k_proj_weight=self.k_proj.weight, v_proj_weight=self.v_proj.weight, in_proj_weight=None, in_proj_bias=torch.cat([self.q_proj.bias, self.k_proj.bias, self.v_proj.bias]), bias_k=None, bias_v=None, add_zero_attn=False, dropout_p=0, out_proj_weight=self.c_proj.weight, out_proj_bias=self.c_proj.bias, use_separate_proj_weight=True, training=self.training, need_weights=False ) if return_all_tokens: return x else: return x[0]
class ModifiedResNet(nn.Module): """ A ResNet class that is similar to torchvision's but contains the following changes: - There are now 3 "stem" convolutions as opposed to 1, with an average pool instead of a max pool. - Performs anti-aliasing strided convolutions, where an avgpool is prepended to convolutions with stride > 1 - The final pooling layer is a QKV attention instead of an average pool """
def __init__(self, layers, output_dim, heads, input_resolution=224, width=64): super().__init__() self.output_dim = output_dim self.input_resolution = input_resolution
# the 3-layer stem self.conv1 = nn.Conv2d(3, width // 2, kernel_size=3, stride=2, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(width // 2) self.conv2 = nn.Conv2d(width // 2, width // 2, kernel_size=3, padding=1, bias=False) self.bn2 = nn.BatchNorm2d(width // 2) self.conv3 = nn.Conv2d(width // 2, width, kernel_size=3, padding=1, bias=False) self.bn3 = nn.BatchNorm2d(width) self.avgpool = nn.AvgPool2d(2) self.relu = nn.ReLU(inplace=True)
# residual layers self._inplanes = width # this is a *mutable* variable used during construction self.layer1 = self._make_layer(width, layers[0]) self.layer2 = self._make_layer(width * 2, layers[1], stride=2) self.layer3 = self._make_layer(width * 4, layers[2], stride=2) self.layer4 = self._make_layer(width * 8, layers[3], stride=2)
embed_dim = width * 32 # the ResNet feature dimension self.attnpool = AttentionPool2d(input_resolution // 32, embed_dim, heads, output_dim)
def _make_layer(self, planes, blocks, stride=1): layers = [Bottleneck(self._inplanes, planes, stride)]
self._inplanes = planes * Bottleneck.expansion for _ in range(1, blocks): layers.append(Bottleneck(self._inplanes, planes))
return nn.Sequential(*layers)
def forward(self, x, return_side_out=False, return_all_tokens=False): def stem(x): for conv, bn in [(self.conv1, self.bn1), (self.conv2, self.bn2), (self.conv3, self.bn3)]: x = self.relu(bn(conv(x))) x = self.avgpool(x) return x out = [] x = x.type(self.conv1.weight.dtype) x = stem(x) x = self.layer1(x) if return_side_out: out.append(x) x = self.layer2(x) if return_side_out: out.append(x) x = self.layer3(x) if return_side_out: out.append(x) x = self.layer4(x) if return_side_out: out.append(x) x = self.attnpool(x, return_all_tokens) out.append(x) if len(out) == 1: return x else: return out
class LayerNorm(nn.LayerNorm): """Subclass torch's LayerNorm to handle fp16."""
def forward(self, x: torch.Tensor): orig_type = x.dtype ret = super().forward(x.type(torch.float32)) return ret.type(orig_type)
class QuickGELU(nn.Module): def forward(self, x: torch.Tensor): return x * torch.sigmoid(1.702 * x)
class ResidualAttentionBlock(nn.Module): def __init__(self, d_model: int, n_head: int, attn_mask: torch.Tensor = None): super().__init__()
self.attn = nn.MultiheadAttention(d_model, n_head) self.ln_1 = LayerNorm(d_model) self.mlp = nn.Sequential(OrderedDict([ ("c_fc", nn.Linear(d_model, d_model * 4)), ("gelu", QuickGELU()), ("c_proj", nn.Linear(d_model * 4, d_model)) ])) self.ln_2 = LayerNorm(d_model) self.attn_mask = attn_mask
def attention(self, x: torch.Tensor): self.attn_mask = self.attn_mask.to(dtype=x.dtype, device=x.device) if self.attn_mask is not None else None return self.attn(x, x, x, need_weights=False, attn_mask=self.attn_mask)[0]
def forward(self, x: torch.Tensor): x = x + self.attention(self.ln_1(x)) x = x + self.mlp(self.ln_2(x)) return x
class Transformer(nn.Module): def __init__(self, width: int, layers: int, heads: int, attn_mask: torch.Tensor = None): super().__init__() self.width = width self.layers = layers self.resblocks = nn.Sequential(*[ResidualAttentionBlock(width, heads, attn_mask) for _ in range(layers)])
def forward(self, x: torch.Tensor): return self.resblocks(x)
class VisionTransformer(nn.Module): def __init__(self, input_resolution: int, patch_size: int, width: int, layers: int, heads: int, output_dim: int): super().__init__() self.input_resolution = input_resolution self.output_dim = output_dim self.conv1 = nn.Conv2d(in_channels=3, out_channels=width, kernel_size=patch_size, stride=patch_size, bias=False)
scale = width ** -0.5 self.class_embedding = nn.Parameter(scale * torch.randn(width)) self.positional_embedding = nn.Parameter(scale * torch.randn((input_resolution // patch_size) ** 2 + 1, width)) self.ln_pre = LayerNorm(width) self.patch_shape = (input_resolution // patch_size, ) * 2
self.patch_size = patch_size
self.transformer = Transformer(width, layers, heads)
self.ln_post = LayerNorm(width) self.proj = nn.Parameter(scale * torch.randn(width, output_dim))
def interpolate_pos_encoding(self, x, w, h): class_pos_embed = self.positional_embedding[0] patch_pos_embed = self.positional_embedding[1:] dim = x.shape[-1] # we add a small number to avoid floating point error in the interpolation # see discussion at https://github.com/facebookresearch/dino/issues/8 # w0, h0 = w + 0.1, h + 0.1 n, m = self.patch_shape patch_pos_embed = nn.functional.interpolate( patch_pos_embed.reshape(1, n, m, dim).permute(0, 3, 1, 2), scale_factor=(w / n, h / m), mode='bicubic', ) assert int(w) == patch_pos_embed.shape[-2] and int(h) == patch_pos_embed.shape[-1] patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(-1, dim) return torch.cat((class_pos_embed.unsqueeze(0), patch_pos_embed), dim=0)
def forward(self, x: torch.Tensor): x = self.conv1(x) # shape = [*, width, grid, grid] bsz, _, w, h = x.size() x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2] x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width] x = torch.cat([self.class_embedding.to(x.dtype) + torch.zeros(x.shape[0], 1, x.shape[-1], dtype=x.dtype, device=x.device), x], dim=1) # shape = [*, grid ** 2 + 1, width] if w != self.patch_shape[0] or h != self.patch_shape[1]: x = x + self.interpolate_pos_encoding(x, w, h) else: x = x + self.positional_embedding.to(x.dtype) x = self.ln_pre(x)
x = x.permute(1, 0, 2) # NLD -> LND x = self.transformer(x) x = x.permute(1, 0, 2) # LND -> NLD
x = x[:, 1:, :] ### w/o cls token x = self.ln_post(x) ### norm if self.proj is not None: x = x @ self.proj ### proj to low dim return x
class CLIP(nn.Module): def __init__(self, embed_dim: int, # vision image_resolution: int, vision_layers: Union[Tuple[int, int, int, int], int], vision_width: int, vision_patch_size: int, # text context_length: int, vocab_size: int, transformer_width: int, transformer_heads: int, transformer_layers: int ): super().__init__()
self.context_length = context_length
if isinstance(vision_layers, (tuple, list)): vision_heads = vision_width * 32 // 64 self.visual = ModifiedResNet( layers=vision_layers, output_dim=embed_dim, heads=vision_heads, input_resolution=image_resolution, width=vision_width ) else: vision_heads = vision_width // 64 self.visual = VisionTransformer( input_resolution=image_resolution, patch_size=vision_patch_size, width=vision_width, layers=vision_layers, heads=vision_heads, output_dim=embed_dim )
self.transformer = Transformer( width=transformer_width, layers=transformer_layers, heads=transformer_heads, attn_mask=self.build_attention_mask() )
self.vocab_size = vocab_size self.token_embedding = nn.Embedding(vocab_size, transformer_width) self.positional_embedding = nn.Parameter(torch.empty(self.context_length, transformer_width)) self.ln_final = LayerNorm(transformer_width)
self.text_projection = nn.Parameter(torch.empty(transformer_width, embed_dim)) self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
self.initialize_parameters()
def initialize_parameters(self): nn.init.normal_(self.token_embedding.weight, std=0.02) nn.init.normal_(self.positional_embedding, std=0.01)
if isinstance(self.visual, ModifiedResNet): if self.visual.attnpool is not None: std = self.visual.attnpool.c_proj.in_features ** -0.5 nn.init.normal_(self.visual.attnpool.q_proj.weight, std=std) nn.init.normal_(self.visual.attnpool.k_proj.weight, std=std) nn.init.normal_(self.visual.attnpool.v_proj.weight, std=std) nn.init.normal_(self.visual.attnpool.c_proj.weight, std=std)
for resnet_block in [self.visual.layer1, self.visual.layer2, self.visual.layer3, self.visual.layer4]: for name, param in resnet_block.named_parameters(): if name.endswith("bn3.weight"): nn.init.zeros_(param)
proj_std = (self.transformer.width ** -0.5) * ((2 * self.transformer.layers) ** -0.5) attn_std = self.transformer.width ** -0.5 fc_std = (2 * self.transformer.width) ** -0.5 for block in self.transformer.resblocks: nn.init.normal_(block.attn.in_proj_weight, std=attn_std) nn.init.normal_(block.attn.out_proj.weight, std=proj_std) nn.init.normal_(block.mlp.c_fc.weight, std=fc_std) nn.init.normal_(block.mlp.c_proj.weight, std=proj_std)
if self.text_projection is not None: nn.init.normal_(self.text_projection, std=self.transformer.width ** -0.5)
def build_attention_mask(self): # lazily create causal attention mask, with full attention between the vision tokens # pytorch uses additive attention mask; fill with -inf mask = torch.empty(self.context_length, self.context_length) mask.fill_(float("-inf")) mask.triu_(1) # zero out the lower diagonal return mask
@property def dtype(self): return self.visual.conv1.weight.dtype
def encode_image(self, image): return self.visual(image.type(self.dtype))
def encode_text(self, text): x = self.token_embedding(text).type(self.dtype) # [batch_size, n_ctx, d_model]
x = x + self.positional_embedding.type(self.dtype) x = x.permute(1, 0, 2) # NLD -> LND x = self.transformer(x) x = x.permute(1, 0, 2) # LND -> NLD x = self.ln_final(x).type(self.dtype)
# x.shape = [batch_size, n_ctx, transformer.width] # take features from the eot embedding (eot_token is the highest number in each sequence) x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] @ self.text_projection
return x
def forward(self, image, text): image_features = self.encode_image(image) text_features = self.encode_text(text)
# normalized features image_features = image_features / image_features.norm(dim=-1, keepdim=True) text_features = text_features / text_features.norm(dim=-1, keepdim=True)
# cosine similarity as logits logit_scale = self.logit_scale.exp() logits_per_image = logit_scale * image_features @ text_features.t() logits_per_text = logits_per_image.t()
# shape = [global_batch_size, global_batch_size] return logits_per_image, logits_per_text
def convert_weights(model: nn.Module): """Convert applicable model parameters to fp16"""
def _convert_weights_to_fp16(l): if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Linear)): l.weight.data = l.weight.data.half() if l.bias is not None: l.bias.data = l.bias.data.half()
if isinstance(l, nn.MultiheadAttention): for attr in [*[f"{s}_proj_weight" for s in ["in", "q", "k", "v"]], "in_proj_bias", "bias_k", "bias_v"]: tensor = getattr(l, attr) if tensor is not None: tensor.data = tensor.data.half()
for name in ["text_projection", "proj"]: if hasattr(l, name): attr = getattr(l, name) if attr is not None: attr.data = attr.data.half()
model.apply(_convert_weights_to_fp16)
def build_model(state_dict: dict): vit = "visual.proj" in state_dict
if vit: vision_width = state_dict["visual.conv1.weight"].shape[0] vision_layers = len([k for k in state_dict.keys() if k.startswith("visual.") and k.endswith(".attn.in_proj_weight")]) vision_patch_size = state_dict["visual.conv1.weight"].shape[-1] grid_size = round((state_dict["visual.positional_embedding"].shape[0] - 1) ** 0.5) image_resolution = vision_patch_size * grid_size else: counts: list = [len(set(k.split(".")[2] for k in state_dict if k.startswith(f"visual.layer{b}"))) for b in [1, 2, 3, 4]] vision_layers = tuple(counts) vision_width = state_dict["visual.layer1.0.conv1.weight"].shape[0] output_width = round((state_dict["visual.attnpool.positional_embedding"].shape[0] - 1) ** 0.5) vision_patch_size = None assert output_width ** 2 + 1 == state_dict["visual.attnpool.positional_embedding"].shape[0] image_resolution = output_width * 32
embed_dim = state_dict["text_projection"].shape[1] context_length = state_dict["positional_embedding"].shape[0] vocab_size = state_dict["token_embedding.weight"].shape[0] transformer_width = state_dict["ln_final.weight"].shape[0] transformer_heads = transformer_width // 64 transformer_layers = len(set(k.split(".")[2] for k in state_dict if k.startswith(f"transformer.resblocks")))
model = CLIP( embed_dim, image_resolution, vision_layers, vision_width, vision_patch_size, context_length, vocab_size, transformer_width, transformer_heads, transformer_layers )
for key in ["input_resolution", "context_length", "vocab_size"]: if key in state_dict: del state_dict[key]
convert_weights(model) model.load_state_dict(state_dict) return model.eval()12345678910111213141516171819{ "embed_dim": 1024, "vision_cfg": { "image_size": 224, "layers": 40, "width": 1408, "head_width": 88, "mlp_ratio": 4.3637, "patch_size": 14, "drop_path_rate": 0.0 }, "text_cfg": { "context_length": 77, "vocab_size": 49408, "width": 768, "heads": 12, "layers": 12 }}approach/ovod/APE/ape/data/datasets/__init__.pyAdded+19
approach/ovod/APE/ape/data/datasets/coco.pyAdded+383
approach/ovod/APE/ape/data/datasets/d_cube.pyAdded+275
approach/ovod/APE/ape/data/datasets/flickr30k.pyAdded+68
approach/ovod/APE/ape/data/datasets/gqa.pyAdded+60
approach/ovod/APE/ape/data/datasets/grit.pyAdded+60
approach/ovod/APE/ape/data/datasets/inst_categories.pyAdded+488
approach/ovod/APE/ape/data/datasets/lvis_coco.pyAdded+284
approach/ovod/APE/ape/data/datasets/lvis_coco_panoptic.pyAdded+192
approach/ovod/APE/ape/data/datasets/lvis_v1_coco_category_image_count.pyAdded+20
approach/ovod/APE/ape/data/datasets/objects365.pyAdded+799
approach/ovod/APE/ape/data/datasets/odinw_categories.pyAdded+377
approach/ovod/APE/ape/data/datasets/odinw_instance.pyAdded+824
approach/ovod/APE/ape/data/datasets/odinw_prompts.pyAdded+75
approach/ovod/APE/ape/data/datasets/oid.pyAdded+1573
approach/ovod/APE/ape/data/datasets/openimages_v6_category_image_count.pyAdded+2
approach/ovod/APE/ape/data/datasets/pascal_voc_external.pyAdded+1217
approach/ovod/APE/ape/data/datasets/phrasecut.pyAdded+60
approach/ovod/APE/ape/data/datasets/refcoco.pyAdded+337
approach/ovod/APE/ape/data/datasets/register_bdd100k_panoseg.pyAdded+277
approach/ovod/APE/ape/data/datasets/register_bdd100k_semseg.pyAdded+98
approach/ovod/APE/ape/data/datasets/register_pascal_context.pyAdded+587
approach/ovod/APE/ape/data/datasets/register_voc_seg.pyAdded+64
approach/ovod/APE/ape/data/datasets/sa1b.pyAdded+44
approach/ovod/APE/ape/data/datasets/seginw_categories.pyAdded+89
approach/ovod/APE/ape/data/datasets/seginw_instance.pyAdded+142
approach/ovod/APE/ape/data/datasets/visualgenome.pyAdded+220
approach/ovod/APE/ape/data/datasets/visualgenome_categories.pyAdded
approach/ovod/APE/ape/data/samplers/__init__.pyAdded+5
approach/ovod/APE/ape/data/samplers/distributed_sampler_multi_dataset.pyAdded+137
approach/ovod/APE/ape/data/transforms/__init__.pyAdded+5
approach/ovod/APE/ape/data/transforms/augmentation_aa.pyAdded+39
approach/ovod/APE/ape/data/transforms/augmentation_lsj.pyAdded+38
approach/ovod/APE/ape/modeling/backbone/__init__.pyAdded
approach/ovod/APE/ape/modeling/backbone/utils_eva.pyAdded+222
approach/ovod/APE/ape/modeling/backbone/utils_eva02.pyAdded+347
approach/ovod/APE/ape/modeling/backbone/vit.pyAdded+30
approach/ovod/APE/ape/modeling/backbone/vit_eva.pyAdded+644
approach/ovod/APE/ape/modeling/backbone/vit_eva02.pyAdded+625
approach/ovod/APE/ape/modeling/backbone/vit_eva_clip.pyAdded+931
approach/ovod/APE/ape/modeling/text/bert_wrapper.pyAdded+107
approach/ovod/APE/ape/modeling/text/clip_wrapper.pyAdded+224
approach/ovod/APE/ape/modeling/text/clip_wrapper_eva02.pyAdded+148
approach/ovod/APE/ape/modeling/text/eva01_clip/README.mdAdded+79
approach/ovod/APE/ape/modeling/text/eva01_clip/__init__.pyAdded+7
approach/ovod/APE/ape/modeling/text/eva01_clip/clip.pyAdded+232
approach/ovod/APE/ape/modeling/text/eva01_clip/eva_clip.pyAdded+173
approach/ovod/APE/ape/modeling/text/eva01_clip/eva_model.pyAdded+368
approach/ovod/APE/ape/modeling/text/eva01_clip/model.pyAdded+471
approach/ovod/APE/ape/modeling/text/eva01_clip/model_configs/EVA_CLIP_g_14.jsonAdded+19