def build(cfg, registry, default_args=None): if isinstance(cfg, list): modules = [ build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg ] return nn.Sequential(*modules) else: return build_from_cfg(cfg, registry, default_args)
def __init__(self, transforms): assert isinstance(transforms, Sequence) self.transforms = [] for transform in transforms: if isinstance(transform, dict): transform = build_from_cfg(transform, PIPELINES) self.transforms.append(transform) # callable() 函数用于检查一个对象是否是可调用的 elif callable(transform): self.transforms.append(transform) else: raise TypeError( 'transform must be callable or a dict, but got {}'.format( type(transform)))