MCPcopy
hub / github.com/Fafa-DL/Awesome-Backbones / build_padding_layer

Function build_padding_layer

configs/basic/build_layer.py:166–191  ·  view source on GitHub ↗

Build padding layer. Args: cfg (None or dict): The padding layer config, which should contain: - type (str): Layer type. - layer args: Args needed to instantiate a padding layer. Returns: nn.Module: Created padding layer.

(cfg, *args, **kwargs)

Source from the content-addressed store, hash-verified

164 return eval(cfg_.pop('type'))(**cfg_)
165
166def build_padding_layer(cfg, *args, **kwargs):
167 """Build padding layer.
168
169 Args:
170 cfg (None or dict): The padding layer config, which should contain:
171 - type (str): Layer type.
172 - layer args: Args needed to instantiate a padding layer.
173
174 Returns:
175 nn.Module: Created padding layer.
176 """
177 if not isinstance(cfg, dict):
178 raise TypeError('cfg must be a dict')
179 if 'type' not in cfg:
180 raise KeyError('the cfg dict must contain the key "type"')
181
182 cfg_ = cfg.copy()
183 padding_type = cfg_.pop('type')
184 if padding_type not in PADDING_LAYERS:
185 raise KeyError(f'Unrecognized padding type {padding_type}.')
186 else:
187 padding_layer = eval(padding_type)
188
189 layer = padding_layer(*args, **kwargs, **cfg_)
190
191 return layer
192
193
194def build_dropout(cfg):

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected