コード例 #1
0
ファイル: test_cfg.py プロジェクト: jpbirdy/Detectron
    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 = core_config.load_cfg(yaml.dump(a))
        assert a.is_immutable()
        assert a2.is_immutable()
コード例 #2
0
    def __init__(self):
        super(Model, self).__init__()
        self.name = 'Mask RCNN'

        # Configuration and weights options
        # By default, we use ResNet50 backbone architecture, you can switch to
        # ResNet101 to increase quality if your GPU memory is higher than 8GB.
        # To do so, you will need to download both .yaml and .pkl ResNet101 files
        # then replace the below 'cfg_file' with the following:
        # self.cfg_file = 'models/mrcnn/e2e_mask_rcnn_X-101-64x4d-FPN_2x.yaml'
        self.cfg_file = 'models/mrcnn/e2e_mask_rcnn_R-50-FPN_2x.yaml'
        self.weights = 'models/mrcnn/model_final.pkl'
        self.default_cfg = copy.deepcopy(AttrDict(cfg)) # cfg from detectron.core.config
        self.mrcnn_cfg = AttrDict()
        self.dummy_coco_dataset = dummy_datasets.get_coco_dataset()

        # Inference options
        self.show_box = True
        self.show_class = True
        self.thresh = 0.7
        self.alpha = 0.4
        self.show_border = True
        self.border_thick = 1
        self.bbox_thick = 1
        self.font_scale = 0.35
        self.binary_masks = False

        # Define exposed options
        self.options = (
            'show_box', 'show_class', 'thresh', 'alpha', 'show_border',
            'border_thick', 'bbox_thick', 'font_scale', 'binary_masks',
            )
        # Define inputs/outputs
        self.inputs = {'input': 3}
        self.outputs = {'output': 3}
コード例 #3
0
ファイル: test_cfg.py プロジェクト: jpbirdy/Detectron
 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(mode='w') 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)
コード例 #4
0
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
コード例 #5
0
def get_ava_dataset_action():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'bend/bow (at the waist)', 'crawl', 'crouch/kneel',
        'dance', 'fall down', 'get up', 'jump/leap', 'lie/sleep',
        'martial art', 'run/jog', 'sit', 'stand', 'swim', 'walk',
        'answer phone', 'brush teeth', 'carry/hold (an object)',
        'catch (an object)', 'chop', 'climb (e.g., a mountain)', 'clink glass',
        'close (e.g., a door, a box)', 'cook', 'cut', 'dig',
        'dress/put on clothing', 'drink', 'drive (e.g., a car, a truck)',
        'eat', 'enter', 'exit', 'extract', 'fishing', 'hit (an object)',
        'kick (an object)', 'lift/pick up', 'listen (e.g., to music)',
        'open (e.g., a window, a car door)', 'paint', 'play board game',
        'play musical instrument', 'play with pets', 'point to (an object)',
        'press', 'pull (an object)', 'push (an object)', 'put down', 'read',
        'ride (e.g., a bike, a car, a horse)', 'row boat', 'sail boat',
        'shoot', 'shovel', 'smoke', 'stir', 'take a photo',
        'text on/look at a cellphone', 'throw', 'touch (an object)',
        'turn (e.g., a screwdriver)', 'watch (e.g., TV)', 'work on a computer',
        'write', 'fight/hit (a person)',
        'give/serve (an object) to (a person)', 'grab (a person)', 'hand clap',
        'hand shake', 'hand wave', 'hug (a person)', 'kick (a person)',
        'kiss (a person)', 'lift (a person)', 'listen to (a person)',
        'play with kids', 'push (another person)',
        'sing to (e.g., self, a person, a group)',
        'take (an object) from (a person)',
        'talk to (e.g., self, a person, a group)', 'watch (a person)'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #6
0
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
コード例 #7
0
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', '11111', '11121', '11122', '11123', '11131', '1'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #8
0
def get_classification_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = ['__background__']
    for i in range(61):
        classes.append(str(i))
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #9
0
ファイル: config.py プロジェクト: yiningzeng/Detectron
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:
        yaml_cfg = AttrDict(load_cfg(f))
    print("merge_cfg_from_file--------------")
    print(yaml_cfg)
    print(__C)
    print("ending---------------------------")
    _merge_a_into_b(yaml_cfg, __C)
コード例 #10
0
ファイル: vis_dataset.py プロジェクト: CFLai1990/ObjDetection
def get_vis_dict():
    """The dataset that includes all the 'classes' field."""
    ds_dict = AttrDict()
    classes = [
        '__ignore__', '_background_', 'rectangle', 'axis', 'legend', 'sector',
        'circle'
    ]
    ds_dict.classes = {i: name for i, name in enumerate(classes)}
    return ds_dict
コード例 #11
0
ファイル: category_name.py プロジェクト: HITROS/omtb_ml
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'base', 'blue_block', 'green_block', 'orange_block',
        'red_block', 'yellow_block'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #12
0
ファイル: dummy_datasets.py プロジェクト: invite-you/CBNet
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'aircraft carrier', 'container', 'oil tanker',
        'maritime vessels'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
def get_wider_dataset():
    """A dummy WIDER dataset that includes only the 'classes' field."""
    ds = AttrDict()
    # classes = [
    #     '__background__', 'pedestrian', 'cyclist'
    # ]
    classes = ['__background__', 'person', 'cyclist']
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #14
0
def get_mobilityaids_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'person', 'crutches', 'walking_frame', 'wheelchair',
        'push_wheelchair'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #15
0
def get_voc_dataset():
    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
コード例 #16
0
def get_mot_dataset():
    """A dummy MOT dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'ped', 'person_on_vhl', 'car', 'bicycle', 'mbike',
        'non_mot_vhcl', 'static_person', 'distractor', 'occluder',
        'occluder_on_grnd', 'occluder_full', 'reflection', 'crowd'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #17
0
def get_deepfashion3_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__',
        'Upper',
        'Lower',
        'Full',
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #18
0
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'bookshelf', 'cabinet', 'cafe_table',
        'cardboard_box', 'car_wheel', 'cinder_block', 'coke_can',
        'construction_barrel', 'construction_cone',
        'drc_practice_blue_cylinder', 'drc_practice_hinged_door'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #19
0
def get_nucoco_dataset():
    """A dummy nuCOCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'person', 'bicycle', 'car', 'motorcycle', 'bus',
        'truck'
    ]
    # classes = [
    #     '__background__', 'car', 'truck', 'person', 'motorcycle',
    #     'bus', 'bicycle'
    # ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #20
0
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', '002_master_chef_can', '003_cracker_box',
        '004_sugar_box', '005_tomato_soup_can', '006_mustard_bottle',
        '007_tuna_fish_can', '008_pudding_box', '009_gelatin_box',
        '010_potted_meat_can', '011_banana', '019_pitcher_base',
        '021_bleach_cleanser', '024_bowl', '025_mug', '035_power_drill',
        '036_wood_block', '037_scissors', '040_large_marker',
        '051_large_clamp', '052_extra_large_clamp', '061_foam_brick'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #21
0
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()

    classes = [
        '__background__', 'PN', 'FB', 'FO', 'XO', 'HD', 'FP', 'PI', 'AA',
        'NP2', 'NP'
    ]

    # classes = [
    #     '__background__', 'NP2', 'NP', 'HD', 'FB', 'PN', 'FP', 'PI', 'FO', 'XO'
    # ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #22
0
ファイル: model.py プロジェクト: tws0002/nuke-ML-server
    def __init__(self):
        super(Model, self).__init__()
        self.name = 'DensePose'

        # Configuration and weights options
        # By default, we use ResNet50 backbone architecture, you can switch to
        # ResNet101 to increase quality if your GPU memory is higher than 6GB.
        # To do so, you will need to download both .yaml and .pkl ResNet101 files
        # then replace 'ResNet50' by 'ResNet101' for 'cfg_file' and 'weights' below.
        self.cfg_file = 'models/densepose/DensePose_ResNet50_FPN_s1x-e2e.yaml'
        self.weights = 'models/densepose/DensePose_ResNet50_FPN_s1x-e2e.pkl'
        self.default_cfg = copy.deepcopy(
            AttrDict(cfg))  # cfg from detectron.core.config
        self.densepose_cfg = AttrDict()
        self.dummy_coco_dataset = dummy_datasets.get_coco_dataset()

        # Inference options
        self.show_human_index = False
        self.show_uv = False
        self.show_grid = True
        self.show_border = False
        self.border_thick = 1
        self.alpha = 0.4

        # Define exposed options
        self.options = (
            'show_human_index',
            'show_uv',
            'show_grid',
            'show_border',
            'border_thick',
            'alpha',
        )
        # Define inputs/outputs
        self.inputs = {'input': 3}
        self.outputs = {'output': 3}
コード例 #23
0
def get_deepfashion50_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'Anorak', 'Blazer', 'Blouse', 'Bomber',
        'Button-Down', 'Cardigan', 'Flannel', 'Halter', 'Henley', 'Hoodie',
        'Jacket', 'Jersey', 'Parka', 'Peacoat', 'Poncho', 'Sweater', 'Tank',
        'Tee', 'Top', 'Turtleneck', 'Capris', 'Chinos', 'Culottes', 'Cutoffs',
        'Gauchos', 'Jeans', 'Jeggings', 'Jodhpurs', 'Joggers', 'Leggings',
        'Sarong', 'Shorts', 'Skirt', 'Sweatpants', 'Sweatshorts', 'Trunks',
        'Caftan', 'Cape', 'Coat', 'Coverup', 'Dress', 'Jumpsuit', 'Kaftan',
        'Kimono', 'Nightdress', 'Onesie', 'Robe', 'Romper', 'Shirtdress',
        'Sundress'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #24
0
def get_cityscapes_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 
        'person',
        'rider',
        'car',
        'truck',
        'bus',
        'train',
        'motorcycle',
        'bicycle',
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #25
0
def get_cloth_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 'huibian', 'qianjie', 'bianzhadong', 'quewei',
        'diaojing', 'cusha', 'xianyin', 'quejing', 'diaogong', 'zhixi',
        'pobian', 'lengduan', 'cashang', 'bianquejing', 'maoban', 'wuzi',
        'mingqianxian', 'houduan', 'bianzhenyan', 'gongsha', 'zhengneyin',
        'cadong', 'jiandong', 'jiama', 'jingtiaohua', 'maodong', 'zhiru',
        'youzi', 'camao', 'zhadong', 'tiaohua', 'diaowei', 'houbaoduan',
        'xiuyin', 'bianquewei', 'erduo', 'jiedong', 'maoli', 'podong',
        'huangzi', 'jinsha', 'zhashu', 'zhasha', 'bianbaiyin', 'jingcusha',
        'weicusha'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #26
0
ファイル: test_cfg.py プロジェクト: jpbirdy/Detectron
    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 = core_config.load_cfg(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)
コード例 #27
0
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
コード例 #28
0
def get_visda_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = [
        '__background__', 
        'aeroplane',
        'bicycle',
        'bus',
        'car',
        'horse',
        'knife',
        'motorcycle',
        'person',
        'plant',
        'skateboard',
        'train',
        'truck'
    ]
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds
コード例 #29
0
from ast import literal_eval
from future.utils import iteritems
import copy
import io
import logging
import numpy as np
import os
import os.path as osp
import six

from detectron.utils.collections import AttrDict
from detectron.utils.io import cache_url

logger = logging.getLogger(__name__)

__C = AttrDict()
# Consumers can get config by:
#   from detectron.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 = ''
コード例 #30
0
def get_coco_dataset():
    """A dummy COCO dataset that includes only the 'classes' field."""
    ds = AttrDict()
    classes = ['__background__', 'text', 'title', 'list', 'table', 'figure']
    ds.classes = {i: name for i, name in enumerate(classes)}
    return ds