classRegistry:"""A registry to map strings to classes or functions.
Registered object could be built from registry. Meanwhile, registered
functions could be called from registry.
Args:
name (str): Registry name.
build_func (callable, optional): A function to construct instance
from Registry. :func:`build_from_cfg` is used if neither ``parent``
or ``build_func`` is specified. If ``parent`` is specified and
``build_func`` is not given, ``build_func`` will be inherited
from ``parent``. Defaults to None.
parent (:obj:`Registry`, optional): Parent registry. The class
registered in children registry could be built from parent.
Defaults to None.
scope (str, optional): The scope of registry. It is the key to search
for children registry. If not specified, scope will be the name of
the package where class is defined, e.g. mmdet, mmcls, mmseg.
Defaults to None.
Examples:
>>> # define a registry
>>> MODELS = Registry('models')
>>> # registry the `ResNet` to `MODELS`
>>> @MODELS.register_module()
>>> class ResNet:
>>> pass
>>> # build model from `MODELS`
>>> resnet = MODELS.build(dict(type='ResNet'))
>>> @MODELS.register_module()
>>> def resnet50():
>>> pass
>>> resnet = MODELS.build(dict(type='resnet50'))
>>> # hierarchical registry
>>> DETECTORS = Registry('detectors', parent=MODELS, scope='det')
>>> @DETECTORS.register_module()
>>> class FasterRCNN:
>>> pass
>>> fasterrcnn = DETECTORS.build(dict(type='FasterRCNN'))
More advanced usages can be found at
https://mmengine.readthedocs.io/en/latest/tutorials/registry.html.
"""def__init__(self,
name:str,
build_func: Optional[Callable]=None,
parent: Optional['Registry']=None,
scope: Optional[str]=None):from.build_functions import build_from_cfg
self._name = name
self._module_dict: Dict[str, Type]=dict()
self._children: Dict[str,'Registry']=dict()if scope isnotNone:assertisinstance(scope,str)
self._scope = scope
else:
self._scope = self.infer_scope()# See https://mypy.readthedocs.io/en/stable/common_issues.html## variables-vs-type-aliases for the use
self.parent: Optional['Registry']if parent isnotNone:assertisinstance(parent, Registry)
parent._add_child(self)
self.parent = parent
else:
self.parent =None# self.build_func will be set with the following priority:# 1. build_func# 2. parent.build_func# 3. build_from_cfg
self.build_func: Callable
if build_func isNone:if self.parent isnotNone:
self.build_func = self.parent.build_func
else:
self.build_func = build_from_cfg
else:
self.build_func = build_func
import torch.nn as nn
# 使用注册器管理模块@ACTIVATION.register_module()classSigmoid(nn.Module):def__init__(self):super().__init__()defforward(self, x):print('call Sigmoid.forward')return x
@ACTIVATION.register_module()classReLU(nn.Module):def__init__(self, inplace=False):super().__init__()defforward(self, x):print('call ReLU.forward')return x
@ACTIVATION.register_module()classSoftmax(nn.Module):def__init__(self):super().__init__()defforward(self, x):print('call Softmax.forward')return x
一般前端工程师只会使用npm run serve 在开发环境下验证,那么如何把npm run build 打出的包部署到服务器上进行上线呢?这篇文章就详细阐述这一流程。
1. 购买或试用阿里云服务器 作为新用户可以试用一个月阿里云服务器,阿里云官方网址如下&a…
real-world image and video super-resolution 文章目录real-world image and video super-resolution1. Toward Real-World Single Image Super-Resolution:A New Benchmark and A New Model(2019)1.1 real-world数据集制作1.2 LP-KPN网络结构1.3 拉普拉…