前言
registry的主要作用是作为模型字典来保存生成的不同网络结构模型,其有两处定义分别为utils里面定义的Registry.py和在modeling里面定义的Registry.py。前者是定义数据类型,后者是这个字典类型的一个集合,为保存不同的网络结构提供了不同的模型字典。具体代码详解如下:
# 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():
...