def __init__(self, cfg, output_dir): self.cfg = cfg self.output_dir = output_dir self.DETECTOR = Registry() self.DETECTOR.register("gradient-edge", dm_gradient_edge_detector) self.DETECTOR.register("entropy", dm_entropy_detector) self.DETECTOR.register("dev", dev_detector)
def get_faceTrackNoIR_path(): """Get the path to FaceTrackNoIR installation.""" fake_path = devmode.get_facetracknoir_path() if fake_path: return fake_path try: key = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\FaceTrackNoIR_is1' reg_val = Registry.ReadValueUserAndMachine(key, 'InstallLocation', True) Logger.info('FaceTrackNoIR: Install location: {}'.format(reg_val)) path = os.path.join(reg_val, 'FaceTrackNoIR.exe') if not os.path.isfile(path): Logger.info( 'FaceTrackNoIR: Found install location but no expected exe file found: {}' .format(path)) raise FaceTrackNoIRNotInstalled() return path except Registry.Error: raise FaceTrackNoIRNotInstalled()
def get_opentrack_path(): """Get the path to Opentrack installation.""" fake_path = devmode.get_opentrack_path() if fake_path: return fake_path try: key = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{63F53541-A29E-4B53-825A-9B6F876A2BD6}_is1' reg_val = Registry.ReadValueUserAndMachine(key, 'InstallLocation', True) Logger.info('Opentrack: Install location: {}'.format(reg_val)) path = os.path.join(reg_val, 'opentrack.exe') if not os.path.isfile(path): Logger.info( 'Opentrack: Found install location but no expected exe file found: {}' .format(path)) raise OpentrackNotInstalled() return path except Registry.Error: raise OpentrackNotInstalled()
def get_installation_path(): """Return the folder where Arma is installed. 1) Check local directory 2) Search the registry entry 3) Browse steam libraries in search for Arma Raises ArmaNotInstalled if the required registry keys cannot be found.""" if Arma.installation_path_cached: return Arma.installation_path_cached if devmode.get_arma_path(): Arma.installation_path_cached = devmode.get_arma_path() return Arma.installation_path_cached # 1) Check local directory path = paths.get_external_executable_dir() if os.path.isfile(os.path.join(path, 'Arma3.exe')): Logger.info('Arma: Arma3.exe found in launcher directory: {}'.format(path)) Arma.installation_path_cached = path return Arma.installation_path_cached Logger.error('Arma: Could not find Arma3.exe in launcher directory') # 2) Search the registry entry try: path = Registry.ReadValueUserAndMachine(Arma._arma_registry_path, 'main', check_both_architectures=True) if os.path.isfile(os.path.join(path, 'Arma3.exe')): Logger.info('Arma: Arma3.exe found through registry: {}'.format(path)) Arma.installation_path_cached = path return Arma.installation_path_cached else: Logger.error('Arma: Could not find Arma3.exe at the location pointed by the registry: {}'.format(path)) except Registry.Error: Logger.error('Arma: Could not find registry entry for installation path') # 3) Browse steam libraries in search for Arma steam_libraries = steam.find_steam_libraries() for library in steam_libraries: path = os.path.join(library, 'steamapps', 'common', 'Arma 3') if os.path.isfile(os.path.join(path, 'Arma3.exe')): Logger.info('Arma: Arma3.exe found in Steam libraries: {}'.format(path)) Arma.installation_path_cached = path return Arma.installation_path_cached # All failed :( raise ArmaNotInstalled()
def get_install_location(): """Return the path to where teamspeak executables are installed.""" if devmode.get_ts_install_location(): return devmode.get_ts_install_location() try: key = 'SOFTWARE\\TeamSpeak 3 Client' reg_val = Registry.ReadValueMachineAndUser(key, '', True) return reg_val except Registry.Error: raise TeamspeakNotInstalled('Could not get the TS install location')
def get_steam_exe_path(): """Return the path to the steam executable. Raises SteamNotInstalled if steam is not installed.""" if devmode.get_steam_executable(): return devmode.get_steam_executable() try: # Optionally, there is also SteamPath return Registry.ReadValueUserAndMachine( _steam_registry_path, 'SteamExe', check_both_architectures=True) # SteamPath except Registry.Error: raise SteamNotInstalled()
def _get_config_location(): """Return the value meaning where the user configuration is stored. 0 - C:/Users/<username>/AppData/Roaming/TS3Client 1 - Installation folder (get_install_location()/config). The actual directory may not exist until the user actually launches Teamspeak! """ if devmode.get_ts_config_location(): return devmode.get_ts_config_location() try: key = 'SOFTWARE\\TeamSpeak 3 Client' reg_val = Registry.ReadValueMachineAndUser(key, 'ConfigLocation', True) return reg_val except Registry.Error: raise TeamspeakNotInstalled( 'Could not get the TS config location information')
class DMDetector: def __init__(self, cfg, output_dir): self.cfg = cfg self.output_dir = output_dir self.DETECTOR = Registry() self.DETECTOR.register("gradient-edge", dm_gradient_edge_detector) self.DETECTOR.register("entropy", dm_entropy_detector) self.DETECTOR.register("dev", dev_detector) def detect(self, dm_image: DMImage): return self.DETECTOR[self.cfg.METHOD](dm_image=dm_image, output_dir=self.output_dir, **self.cfg.ARG)
def get_TrackIR_path(): """Get the path to FaceTrackNoIR installation.""" fake_path = devmode.get_trackir_path() if fake_path: return fake_path try: key = 'Software\\NaturalPoint\\NaturalPoint\\NPClient Location' reg_val = Registry.ReadValueUserAndMachine(key, 'Path', True) Logger.info('TrackIR: Install location: {}'.format(reg_val)) path = os.path.join(reg_val, 'TrackIR5.exe') if not os.path.isfile(path): Logger.info( 'TrackIR: Found install location but no expected exe file found: {}' .format(path)) raise TrackIRNotInstalled() return path except Registry.Error: raise TrackIRNotInstalled()
# coding:utf-8 # @Time : 2019/10/27 # @Author : xuyouze # @File Name : registry.py from utils.registry import Registry Model = Registry()
import copy from utils.registry import Registry BACKBONE_REGISTRY = Registry("backbone") LOSS_REGISTRY = Registry("loss") META_ARCH_REGISTRY = Registry("meta_arch") def build(cfg, registry, args=None): """ Build the module with cfg. Args: cfg (dict): the config of the modules registry(Registry): A registry the module belongs to. Returns: The built module. """ args = copy.deepcopy(cfg) name = args.pop("name") ret = registry.get(name)(**args) return ret def build_backbone(cfg): return build(cfg, BACKBONE_REGISTRY) def build_loss(cfg): return build(cfg, LOSS_REGISTRY)
else: data = pickle.load(f) if "blobs" in data: weights = data["blobs"] else: weights = data return weights _C2_STAGE_NAMES = { "R-50": ["1.2", "2.3", "3.5", "4.2"], "R-101": ["1.2", "2.3", "3.22", "4.2"], "R-152": ["1.2", "2.7", "3.35", "4.2"], } C2_FORMAT_LOADER = Registry() @C2_FORMAT_LOADER.register("R-50-C4") @C2_FORMAT_LOADER.register("R-50-C5") @C2_FORMAT_LOADER.register("R-101-C4") @C2_FORMAT_LOADER.register("R-101-C5") @C2_FORMAT_LOADER.register("R-50-FPN") @C2_FORMAT_LOADER.register("R-50-FPN-RETINANET") @C2_FORMAT_LOADER.register("R-101-FPN") @C2_FORMAT_LOADER.register("R-101-FPN-RETINANET") @C2_FORMAT_LOADER.register("R-152-FPN") def load_resnet_c2_format(cfg, f): state_dict = _load_c2_pickled_weights(f) conv_body = cfg.MODEL.BACKBONE.CONV_BODY arch = conv_body.replace("-C4", "").replace("-C5", "").replace("-FPN", "")
out_channels, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = FrozenBatchNorm2d(out_channels) def forward(self, x): x = self.conv1(x) x = self.bn1(x) x = F.relu_(x) x = F.max_pool2d(x, kernel_size=3, stride=2, padding=1) return x _TRANSFORMATION_MODULES = Registry({ "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm, "DeformConvBottleneckWithGroupNorm": DeformConvBottleneckWithGroupNorm }) _STEM_MODULES = Registry({"StemWithFixedBatchNorm": StemWithFixedBatchNorm}) _STAGE_SPECS = Registry({ "Deform-R-50-C5": DeformResNet50StagesTo5, "R-50-C4": ResNet50StagesTo4, "R-50-C5": ResNet50StagesTo5, "R-50-FPN": ResNet50FPNStagesTo5, "R-101-FPN": ResNet101FPNStagesTo5 })
"""Define the registry for the net models.""" from utils.registry import Registry MODEL_EXAMPLE = Registry()
from utils.registry import Registry HEAD = Registry('head')
from utils.registry import Registry """ Feature Extractor. """ # Backbone BACKBONES = Registry() # FPN FPN_BODY = Registry() """ ROI Head. """ # Box Head ROI_CLS_HEADS = Registry() ROI_CLS_OUTPUTS = Registry() ROI_BOX_HEADS = Registry() ROI_BOX_OUTPUTS = Registry() # OPLD Head ROI_OPLD_HEADS = Registry() ROI_OPLD_OUTPUTS = Registry()
from utils.registry import Registry LOSS = Registry()
""" Copyright 2020 Kartik Sharma Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from utils.registry import Registry FUNNEL = Registry("Funnels")
from utils.registry import Registry BACKBONES = Registry() ROI_ACTION_FEATURE_EXTRACTORS = Registry() ROI_ACTION_PREDICTORS = Registry() INTERACTION_AGGREGATION_STRUCTURES = Registry()
from utils.registry import Registry DETECTOR = Registry('detector')
from utils.registry import Registry MODELS_REGISTRY = Registry("MODELS")
# coding:utf-8 # @Time : 2019/10/27 # @Author : xuyouze # @File Name : registry.py from utils.registry import Registry Network = Registry()
w = d[i] if len(w.shape) == 4: #HWCN -> NCHW w = np.transpose(w, [3, 2, 0, 1]) elif len(w.shape) == 2: w = w.T d[i] = torch.from_numpy(w) def _load_tf_pickled_weights(file_path): with open(file_path, "rb") as f: data = pickle.load(f) return data EXTERNAL_LOADER = Registry() @EXTERNAL_LOADER.register("lifting_rot") def load_lifting_net(path='/home/mscv/hand3d/weights/lifting-proposed.pickle'): path = cfg.WEIGHTS weights = _load_tf_pickled_weights(path) keys = _rename_weights(weights.keys(), basic_pairs + lifting_pairs) key_map = {k: v for k, v in zip(weights.keys(), keys)} for i, j in zip(weights, keys): print(i, j) print(len(set(keys))) new_weights = OrderedDict() for k, w in weights.items():
# coding:utf-8 # @Time : 2019/10/27 # @Author : xuyouze # @File Name : registry.py from utils.registry import Registry Dataset = Registry()
from utils.registry import Registry import torchvision.transforms as transforms TRANSFORMS = Registry() @TRANSFORMS.register("random_resized_crop") def random_resized_crop(cfg, **kwargs): size = kwargs[ "input_size"] if kwargs["input_size"] != None else cfg.INPUT_SIZE return transforms.RandomResizedCrop( size=size, scale=cfg.TRANSFORMS.PROCESS_DETAIL.RANDOM_RESIZED_CROP.SCALE, ratio=cfg.TRANSFORMS.PROCESS_DETAIL.RANDOM_RESIZED_CROP.RATIO, ) @TRANSFORMS.register("random_crop") def random_crop(cfg, **kwargs): size = kwargs[ "input_size"] if kwargs["input_size"] != None else cfg.INPUT_SIZE return transforms.RandomCrop( size, padding=cfg.TRANSFORMS.PROCESS_DETAIL.RANDOM_CROP.PADDING) @TRANSFORMS.register("random_horizontal_flip") def random_horizontal_flip(cfg, **kwargs): return transforms.RandomHorizontalFlip(p=0.5) @TRANSFORMS.register("shorter_resize_for_crop")
from utils.registry import Registry DATASET_REGISTRY = Registry("dataset") def build_dataset(cfg, args=None): """ Build the module with cfg. Args: cfg (dict): the config of the modules registry(Registry): A registry the module belongs to. Returns: The built module. """ args = cfg name = args.pop("name") dataset = DATASET_REGISTRY.get(name)(args) return dataset
from utils.registry import Registry BACKBONES = Registry() BOX_HEADS = Registry() BOX_PREDICTORS = Registry()
def test_registry(): CATS = Registry("cat") assert CATS.name == "cat" assert CATS.module_dict == {} assert len(CATS) == 0 @CATS.register_module() class BritishShorthair: pass assert len(CATS) == 1 assert CATS.get("BritishShorthair") is BritishShorthair class Munchkin: pass CATS.register_module(module=Munchkin) assert len(CATS) == 2 assert CATS.get("Munchkin") is Munchkin assert "Munchkin" in CATS with pytest.raises(KeyError): CATS.register_module(module=Munchkin) CATS.register_module(module=Munchkin, force=True) assert len(CATS) == 2 # force=False with pytest.raises(KeyError): @CATS.register_module() class BritishShorthair: pass @CATS.register_module(force=True) class BritishShorthair: pass assert len(CATS) == 2 assert CATS.get("PersianCat") is None assert "PersianCat" not in CATS @CATS.register_module(name="Siamese") class SiameseCat: pass assert CATS.get("Siamese").__name__ == "SiameseCat" class SphynxCat: pass CATS.register_module(name="Sphynx", module=SphynxCat) assert CATS.get("Sphynx") is SphynxCat # name type with pytest.raises(TypeError): CATS.register_module(name=7474741) # the registered module should be a class with pytest.raises(TypeError): CATS.register_module(0) # can only decorate a class with pytest.raises(TypeError): @CATS.register_module() def some_method(): pass
from utils.registry import Registry """ Feature Extractor. """ # Backbone BACKBONES = Registry() # FPN FPN_BODY = Registry() # SEMSEG ROI_SEMSEG_HEADS = Registry() ROI_SEMSEG_OUTPUTS = Registry() """ ROI Head. """ # Box Head ROI_CLS_HEADS = Registry() ROI_CLS_OUTPUTS = Registry() ROI_BOX_HEADS = Registry() ROI_BOX_OUTPUTS = Registry() # Cascade Head ROI_CASCADE_HEADS = Registry() ROI_CASCADE_OUTPUTS = Registry() # Mask Head ROI_MASK_HEADS = Registry() ROI_MASK_OUTPUTS = Registry() MASKIOU_HEADS = Registry() MASKIOU_OUTPUTS = Registry()
def test_build_from_cfg(): BACKBONES = Registry("backbone") @BACKBONES.register_module() class ResNet: def __init__(self, depth, stages=4): self.depth = depth self.stages = stages @BACKBONES.register_module() class ResNeXt: def __init__(self, depth, stages=4): self.depth = depth self.stages = stages cfg = dict(type="ResNet", depth=50) model = build_from_cfg(cfg, BACKBONES) assert isinstance(model, ResNet) assert model.depth == 50 and model.stages == 4 cfg = dict(type="ResNet", depth=50) model = build_from_cfg(cfg, BACKBONES, default_args={"stages": 3}) assert isinstance(model, ResNet) assert model.depth == 50 and model.stages == 3 cfg = dict(type="ResNeXt", depth=50, stages=3) model = build_from_cfg(cfg, BACKBONES) assert isinstance(model, ResNeXt) assert model.depth == 50 and model.stages == 3 cfg = dict(type=ResNet, depth=50) model = build_from_cfg(cfg, BACKBONES) assert isinstance(model, ResNet) assert model.depth == 50 and model.stages == 4 # type defined using default_args cfg = dict(depth=50) model = build_from_cfg(cfg, BACKBONES, default_args=dict(type="ResNet")) assert isinstance(model, ResNet) assert model.depth == 50 and model.stages == 4 cfg = dict(depth=50) model = build_from_cfg(cfg, BACKBONES, default_args=dict(type=ResNet)) assert isinstance(model, ResNet) assert model.depth == 50 and model.stages == 4 # not a registry with pytest.raises(TypeError): cfg = dict(type="VGG") model = build_from_cfg(cfg, "BACKBONES") # non-registered class with pytest.raises(KeyError): cfg = dict(type="VGG") model = build_from_cfg(cfg, BACKBONES) # default_args must be a dict or None with pytest.raises(TypeError): cfg = dict(type="ResNet", depth=50) model = build_from_cfg(cfg, BACKBONES, default_args=1) # cfg['type'] should be a str or class with pytest.raises(TypeError): cfg = dict(type=1000) model = build_from_cfg(cfg, BACKBONES) # cfg should contain the key "type" with pytest.raises(KeyError, match='must contain the key "type"'): cfg = dict(depth=50, stages=4) model = build_from_cfg(cfg, BACKBONES) # cfg or default_args should contain the key "type" with pytest.raises(KeyError, match='must contain the key "type"'): cfg = dict(depth=50) model = build_from_cfg(cfg, BACKBONES, default_args=dict(stages=4)) # incorrect registry type with pytest.raises(TypeError): cfg = dict(type="ResNet", depth=50) model = build_from_cfg(cfg, "BACKBONES") # incorrect default_args type with pytest.raises(TypeError): cfg = dict(type="ResNet", depth=50) model = build_from_cfg(cfg, BACKBONES, default_args=0) # incorrect arguments with pytest.raises(TypeError): cfg = dict(type="ResNet", non_existing_arg=50) model = build_from_cfg(cfg, BACKBONES)