forked from facebookresearch/maskrcnn-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add registry for model builder functions (facebookresearch#153)
* adding registry to hook custom building blocks * adding customizable rpn head * support customizable c2 weight loading
- Loading branch information
Showing
8 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
from maskrcnn_benchmark.utils.registry import Registry | ||
|
||
BACKBONES = Registry() | ||
ROI_BOX_FEATURE_EXTRACTORS = Registry() | ||
RPN_HEADS = Registry() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
|
||
def _register_generic(module_dict, module_name, module): | ||
assert module_name not in module_dict | ||
module_dict[module_name] = module | ||
|
||
|
||
class Registry(dict): | ||
''' | ||
A helper class for managing registering modules, it extends a dictionary | ||
and provides a register functions. | ||
Eg. creeting a registry: | ||
some_registry = Registry({"default": default_module}) | ||
There're two ways of registering new modules: | ||
1): normal way is just calling register function: | ||
def foo(): | ||
... | ||
some_registry.register("foo_module", foo) | ||
2): used as decorator when declaring the module: | ||
@some_registry.register("foo_module") | ||
@some_registry.register("foo_modeul_nickname") | ||
def foo(): | ||
... | ||
Access of module is just like using a dictionary, eg: | ||
f = some_registry["foo_modeul"] | ||
''' | ||
def __init__(self, *args, **kwargs): | ||
super(Registry, self).__init__(*args, **kwargs) | ||
|
||
def register(self, module_name, module=None): | ||
# used as function call | ||
if module is not None: | ||
_register_generic(self, module_name, module) | ||
return | ||
|
||
# used as decorator | ||
def register_fn(fn): | ||
_register_generic(self, module_name, fn) | ||
return fn | ||
|
||
return register_fn |