def get_coco_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() ''' classes = [ '__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] ''' classes = ['__background__', 'yinlie', 'shixiao'] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_wad_dataset(): """A dummy WAD dataset that includes only the 'classes' field.""" ds = AttrDict() ds.classes = {i: name for i, name in enumerate(classes)} ds.coco_to_this = {1: 36, 2: 35, 3: 33, 4: 34, 6: 39, 8: 38} return ds
def get_steal_oil_class3_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'tower', 'brickspile'] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_coco_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() ds.classes = {i: name for i, name in enumerate(classes)} ds.wad_classes = {1: 36, 2: 35, 3: 33, 4: 34, 6: 39, 8: 38} ds.confident_threshold = 0.5 return ds
def get_cifar100_dataset(): """A dummy cifar100 dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ u'__background__', u'rocket', u'camel', u'crocodile', u'motorcycle', u'keyboard', u'chair', u'seal', u'sunflower', u'cup', u'rose', u'orange', u'porcupine', u'plate', u'lawn_mower', u'bear', u'caterpillar', u'snake', u'sweet_pepper', u'dinosaur', u'poppy', u'willow_tree', u'aquarium_fish', u'turtle', u'bicycle', u'house', u'spider', u'lion', u'lobster', u'sea', u'cattle', u'girl', u'orchid', u'clock', u'fox', u'skyscraper', u'trout', u'pear', u'kangaroo', u'cockroach', u'shrew', u'boy', u'wolf', u'hamster', u'raccoon', u'castle', u'road', u'apple', u'table', u'cloud', u'streetcar', u'crab', u'dolphin', u'squirrel', u'oak_tree', u'bus', u'chimpanzee', u'tiger', u'train', u'rabbit', u'baby', u'otter', u'television', u'tank', u'palm_tree', u'plain', u'pine_tree', u'worm', u'bed', u'bee', u'wardrobe', u'lizard', u'can', u'maple_tree', u'tractor', u'pickup_truck', u'bridge', u'shark', u'beetle', u'telephone', u'woman', u'beaver', u'mouse', u'ray', u'mountain', u'mushroom', u'bowl', u'couch', u'lamp', u'forest', u'elephant', u'butterfly', u'snail', u'leopard', u'possum', u'whale', u'man', u'flatfish', u'tulip', u'bottle', u'skunk' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_objectness_dataset(): """A dummy objectness dataset that includes only the 'classes' field. This dataset has only two categories: background and object.""" ds = AttrDict() classes = ['__background__', 'object'] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_steal_oil_class14_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'suv', 'forklift', 'digger', 'car', 'bus','tanker', 'person','minitruck','minibus','truckbig','trucksmall','tricycle','bicycle' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_common_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'person', 'animal', 'rider', 'motorcycle', 'bicycle', 'autorickshaw', 'car', 'truck', 'bus', 'caravan', 'trailer', 'train', 'vehicle fallback' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_drive_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'car', 'pedestrian', 'mover', 'traffic light', 'shaft', 'traffic sign' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_kitti_dataset(): ds = AttrDict() classes = [ '__background__', 'person', 'rider', 'car', 'truck', 'bus', 'carvanan', 'trailer', 'train', 'motorcycle', 'bicycle' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_apollo_dataset(): ds = AttrDict() classes = [ '__background__', 'ignore', 'pedestrian', 'motorcyclist', 'car', 'bus', 'truck', 'tricyclelist', 'van', 'cyclist', 'trafficcone', 'barrowlist' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_ade_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() PATH = os.path.dirname(__file__) classes = get_classes(os.path.join(PATH, "instanceInfo100_train.txt")) ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_rsna_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'opticapy' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_kitti_dataset(): """A dummy kitti dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'cyclist', 'pedestrian', 'car', 'tram', 'truck', 'van', 'misc' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def merge_cfg_from_file(cfg_filename): """Load a yaml config file and merge it into the global config.""" with open(cfg_filename, 'r') as f: if hasattr(yaml, "FullLoader"): yaml_cfg = AttrDict(yaml.load(f, Loader=yaml.FullLoader)) else: yaml_cfg = AttrDict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
def get_steal_oil_class8_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'autotruck', 'forklift', 'digger', 'car', 'bus', 'tanker', 'person' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_illbuild_class11_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'autotruck', 'crane', 'forklift', 'mixerTruck', 'person', 'colorPlate', 'pit', 'bricksPile', 'mound', 'car' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_voc_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'ignored_regions', 'pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', ' tricycle', 'awning-tricycle', 'bus', 'motor', ' others' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_miotcd_dataset(): """A dummy MIOTCD dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'articulated_truck', 'bicycle', 'bus', 'car', 'motorcycle', 'motorized_vehicle', 'non-motorized_vehicle', 'pedestrian', 'pickup_truck', 'single_unit_truck light', 'work_van' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_voc2007_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_vg_dataset(): ds = AttrDict() obj_cls_file = '/private/home/tinayujiang/data/VisualGenome1.2_in_COCO_format/data_from_peter_anderson/1600-400-20/objects_vocab.txt' with open(obj_cls_file) as f: data = f.readlines() classes = ['__background__'] classes.extend([i.strip() for i in data]) ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_apollo_laneseg_dataset(): ds = AttrDict() classes = [ '__background__', 's_w_d', 's_y_d', 'ds_w_dn', 'ds_y_dn', 'sb_w_do', 'sb_y_do', 'b_w_g', 'b_y_g', 'db_w_g', 'db_y_g', 'db_w_s', 's_w_s', 'ds_w_s', 's_w_c', 's_y_c', 's_w_p', 's_n_p', 'c_wy_z', 'a_w_u', 'a_w_t', 'a_w_tl', 'a_w_tr', 'a_w_tlr', 'a_w_l', 'a_w_r', 'a_w_lr', 'a_n_lu', 'a_w_tu', 'a_w_m', 'a_y_t', 'b_n_sr', 'd_wy_za', 'r_wy_np', 'vom_wy_n', 'om_n_n' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_steal_oil_class10_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'autotruck', 'forklift', 'digger', 'car', 'bus', 'tanker', 'person', 'minitruck', 'minibus' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds # [{"supercategory": "none", "id": 1, "name": "autotruck"}, {"supercategory": "none", "id": 2, "name": "forklift"}, {"supercategory": "none", "id": 3, "name": "digger"}, {"supercategory": "none", "id": 4, "name": "car"}, {"supercategory": "none", "id": 5, "name": "bus"}, {"supercategory": "none", "id": 6, "name": "tanker"}, {"supercategory": "none", "id": 7, "name": "person"}]
def get_custom_dummy_dataset(annFile): """A dummy classes generator from coco json file.""" ds = AttrDict() coco = COCO(annFile) category_ids = coco.getCatIds() categories = [c['name'] for c in coco.loadCats(category_ids)] category_to_id_map = dict(zip(categories, category_ids)) classes = ['__background__'] + categories print(classes) ds.classes = {i: name for i, name in enumerate(classes)} return ds
def get_abu_musa_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'Underground Shelter', 'Communication Tower', 'Dense Structures', 'Vehicle', 'Cargo container', 'Ship', 'Swimming pool', 'Sports field', 'Storage Tank', 'Standalone Building', 'Defensive Earthworks' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def test_renamed_key_from_file(self): # You should see logger messages like: # "Key EXAMPLE.RENAMED.KEY was renamed to EXAMPLE.KEY; # please update your config" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.EXAMPLE = AttrDict() cfg2.EXAMPLE.RENAMED = AttrDict() cfg2.EXAMPLE.RENAMED.KEY = 'foobar' yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.EXAMPLE.RENAMED.KEY # noqa with self.assertRaises(KeyError): core.config.merge_cfg_from_file(f.name)
def get_mapillary_dataset(): ds = AttrDict() classes = [ '__background__', 'Bird', 'Ground Animal', 'Crosswalk - Plain', 'Person', 'Bicyclist', 'Motorcyclist', 'Other Rider', 'Lane Marking - Crosswalk', 'Banner', 'Bench', 'Bike Rack', 'Billboard', 'Catch Basin', 'CCTV Camera', 'Fire Hydrant', 'Junction Box', 'Mailbox', 'Manhole', 'Phone Booth', 'Street Light', 'Pole', 'Traffic Sign Frame', 'Utility Pole', 'Traffic Light', 'Traffic Sign (Back)', 'Traffic Sign (Front)', 'Trash Can', 'Bicycle', 'Boat', 'Bus', 'Car', 'Caravan', 'Motorcycle', 'Other Vehicle', 'Trailer', 'Truck', 'Wheeled Slow' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def merge_dicts(dict_a, dict_b): from ast import literal_eval for key, value in dict_a.items(): if key not in dict_b: raise KeyError('Invalid key in config file: {}'.format(key)) if type(value) is dict: dict_a[key] = value = AttrDict(value) if isinstance(value, str): try: value = literal_eval(value) except BaseException: pass # the types must match, too old_type = type(dict_b[key]) if old_type is not type(value) and value is not None: raise ValueError( 'Type mismatch ({} vs. {}) for config key: {}'.format( type(dict_b[key]), type(value), key)) # recursively merge dicts if isinstance(value, AttrDict): try: merge_dicts(dict_a[key], dict_b[key]) except BaseException: raise Exception('Error under config key: {}'.format(key)) else: dict_b[key] = value
def _decode_cfg_value(v): """Decodes a raw config value (e.g., from a yaml config files or command line argument) into a Python object. """ # Configs parsed from raw yaml will contain dictionary keys that need to be # converted to AttrDict objects if isinstance(v, dict): return AttrDict(v) # All remaining processing is only applied to strings if not isinstance(v, six.string_types): return v # Try to interpret `v` as a: # string, number, tuple, list, dict, boolean, or None try: v = literal_eval(v) # The following two excepts allow v to pass through when it represents a # string. # # Longer explanation: # The type of v is always a string (before calling literal_eval), but # sometimes it *represents* a string and other times a data structure, like # a list. In the case that v represents a string, what we got back from the # yaml parser is 'foo' *without quotes* (so, not '"foo"'). literal_eval is # ok with '"foo"', but will raise a ValueError if given 'foo'. In other # cases, like paths (v = 'foo/bar' and not v = '"foo/bar"'), literal_eval # will raise a SyntaxError. except ValueError: pass except SyntaxError: pass return v
def get_quality_dataset(): ds = AttrDict() classes = [ '偏左', '偏右', '偏上', '偏下', '左肩胛骨在肺野内', '右肩胛骨在肺野内', '异物', '标记在软组织或锁骨上', '栅切割伪影', '心影后脊柱不清', '双肺纹理模糊' ] cls2id = {name: i for i, name in enumerate(classes)} # chi2eng = {'肺实变': 'consolidation', '纤维化表现': 'fibrosis', '肋骨异常': 'rib_abnormity', '胸腔积液': 'effusion', # '胸膜增厚': 'pleural_thickening', '主动脉异常': 'aorta_abnormity', '膈面异常': 'diaphragm_abnormity', # '膈下游离气体': 'subphrenic_air', '结节': 'nodule', '肿块': 'mass', '异物': 'foreign_matters', # '气胸': 'pneumothorax', '肺气肿': 'emphysema', '骨折': 'rib_fracture'} # # cls2chi = {cls: chi for cls, chi in enumerate(classes)} # cls2eng = {cls: chi2eng[chi] for cls, chi in enumerate(classes)} th_cls = [ 0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, # threshold for each cls 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ] # ds.classes = {i: name for i, name in enumerate(classes)} ds.classes = classes ds.th_cls = th_cls ds.cls2id = cls2id return ds
def get_coco_dataset(): """A dummy COCO dataset that includes only the 'classes' field.""" ds = AttrDict() classes = [ '__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] ds.classes = {i: name for i, name in enumerate(classes)} return ds
def test_merge_cfg_from_cfg(self): # Test: merge from deepcopy s = 'dummy0' cfg2 = copy.deepcopy(cfg) cfg2.MODEL.TYPE = s core.config.merge_cfg_from_cfg(cfg2) assert cfg.MODEL.TYPE == s # Test: merge from yaml s = 'dummy1' cfg2 = yaml.load(yaml.dump(cfg)) cfg2.MODEL.TYPE = s core.config.merge_cfg_from_cfg(cfg2) assert cfg.MODEL.TYPE == s # Test: merge with a valid key s = 'dummy2' cfg2 = AttrDict() cfg2.MODEL = AttrDict() cfg2.MODEL.TYPE = s core.config.merge_cfg_from_cfg(cfg2) assert cfg.MODEL.TYPE == s # Test: merge with an invalid key s = 'dummy3' cfg2 = AttrDict() cfg2.FOO = AttrDict() cfg2.FOO.BAR = s with self.assertRaises(KeyError): core.config.merge_cfg_from_cfg(cfg2) # Test: merge with converted type cfg2 = AttrDict() cfg2.TRAIN = AttrDict() cfg2.TRAIN.SCALES = [1] core.config.merge_cfg_from_cfg(cfg2) assert type(cfg.TRAIN.SCALES) is tuple assert cfg.TRAIN.SCALES[0] == 1 # Test: merge with invalid type cfg2 = AttrDict() cfg2.TRAIN = AttrDict() cfg2.TRAIN.SCALES = 1 with self.assertRaises(ValueError): core.config.merge_cfg_from_cfg(cfg2)
from ast import literal_eval from past.builtins import basestring from utils.collections import AttrDict import copy import logging import numpy as np import os import os.path as osp import yaml from utils.io import cache_url logger = logging.getLogger(__name__) __C = AttrDict() # Consumers can get config by: # from core.config import cfg cfg = __C # Random note: avoid using '.ON' as a config key since yaml converts it to True; # prefer 'ENABLED' instead # ---------------------------------------------------------------------------- # # Training options # ---------------------------------------------------------------------------- # __C.TRAIN = AttrDict() # Initialize network with weights from this .pkl file __C.TRAIN.WEIGHTS = b''
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import copy import os import os.path as osp import numpy as np from utils.collections import AttrDict import logging logger = logging.getLogger(__name__) __C = AttrDict() # Consumers can get config by: # from core.config import cfg cfg = __C # ---------------------------------------------------------------------------- # # Training options # ---------------------------------------------------------------------------- # __C.TRAIN = AttrDict() # Initialize network with weights from this pickle file __C.TRAIN.WEIGHTS = b'' # Dataset to use __C.TRAIN.DATASET = b''
def test_immutability(self): # Top level immutable a = AttrDict() a.foo = 0 a.immutable(True) with self.assertRaises(AttributeError): a.foo = 1 a.bar = 1 assert a.is_immutable() assert a.foo == 0 a.immutable(False) assert not a.is_immutable() a.foo = 1 assert a.foo == 1 # Recursively immutable a.level1 = AttrDict() a.level1.foo = 0 a.level1.level2 = AttrDict() a.level1.level2.foo = 0 a.immutable(True) assert a.is_immutable() with self.assertRaises(AttributeError): a.level1.level2.foo = 1 a.level1.bar = 1 assert a.level1.level2.foo == 0 # Serialize immutability state a.immutable(True) a2 = yaml.load(yaml.dump(a)) assert a.is_immutable() assert a2.is_immutable()
import os import os.path as osp import copy from ast import literal_eval import numpy as np from packaging import version import torch import torch.nn as nn from torch.nn import init import yaml import nn as mynn from utils.collections import AttrDict __C = AttrDict() # Consumers can get config by: # from fast_rcnn_config import cfg cfg = __C # Random note: avoid using '.ON' as a config key since yaml converts it to True; # prefer 'ENABLED' instead # ---------------------------------------------------------------------------- # # Training options # ---------------------------------------------------------------------------- # __C.TRAIN = AttrDict() # Datasets to train on # Available dataset list: datasets.dataset_catalog.DATASETS.keys()