Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, dim, use_bias, use_naive=False):
super(ThickBlock3d, self).__init__()
F = self.build_conv_block(dim // 2, True)
G = self.build_conv_block(dim // 2, True)
if use_naive:
self.rev_block = ReversibleBlock(F, G, 'additive',
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, 'additive')
def __init__(self, dim, padding_type, norm_layer, use_naive, use_bias, coupling):
super(ReversibleResnetBlock, self).__init__()
F = self.build_conv_block(dim // 2, padding_type, norm_layer, use_bias)
G = self.build_conv_block(dim // 2, padding_type, norm_layer, use_bias)
if use_naive:
self.rev_block = ReversibleBlock(F, G, coupling,
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, coupling)
def __init__(self, inplanes, planes, stride=1, downsample=None, noactivation=False):
super(RevBasicBlock, self).__init__()
if downsample is None and stride == 1:
gm = BasicBlockSub(inplanes // 2, planes // 2, stride, noactivation)
fm = BasicBlockSub(inplanes // 2, planes // 2, stride, noactivation)
self.revblock = ReversibleBlock(gm, fm)
else:
self.basicblock_sub = BasicBlockSub(inplanes, planes, stride, noactivation)
self.downsample = downsample
self.stride = stride
def __init__(self, dim, padding_type, norm_layer, use_naive, use_bias, coupling):
super(ReversibleResnetBlock, self).__init__()
F = self.build_conv_block(dim // 2, padding_type, norm_layer, use_bias)
G = self.build_conv_block(dim // 2, padding_type, norm_layer, use_bias)
if use_naive:
self.rev_block = ReversibleBlock(F, G, coupling,
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, coupling)
def __init__(self, dim, use_bias, use_naive=False):
super(ThickBlock3d, self).__init__()
F = self.build_conv_block(dim // 2, True)
G = self.build_conv_block(dim // 2, True)
if use_naive:
self.rev_block = ReversibleBlock(F, G, 'additive',
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, 'additive')
def __init__(self, dim, use_bias, norm_layer, use_naive):
super(RevBlock3d, self).__init__()
self.F = self.build_conv_block(dim // 2, True, norm_layer)
self.G = self.build_conv_block(dim // 2, True, norm_layer)
if use_naive:
self.rev_block = ReversibleBlock(F, G, 'additive',
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, 'additive')
def __init__(self, dim, use_bias, norm_layer, use_naive):
super(RevBlock3d, self).__init__()
self.F = self.build_conv_block(dim // 2, True, norm_layer)
self.G = self.build_conv_block(dim // 2, True, norm_layer)
if use_naive:
self.rev_block = ReversibleBlock(F, G, 'additive',
keep_input=True, implementation_fwd=2, implementation_bwd=2)
else:
self.rev_block = ReversibleBlock(F, G, 'additive')
----------
keep_input : :obj:`bool`, optional
Set to retain the input information on forward, by default it can be discarded since it will be
reconstructed upon the backward pass.
keep_input_inverse : :obj:`bool`, optional
Set to retain the input information on inverse, by default it can be discarded since it will be
reconstructed upon the backward pass.
Raises
------
NotImplementedError
If an unknown coupling or implementation is given.
"""
super(ReversibleBlock, self).__init__()
self.keep_input = keep_input
self.keep_input_inverse = keep_input_inverse
if coupling == 'additive':
self.rev_block = AdditiveBlock(Fm, Gm,
implementation_fwd=implementation_fwd, implementation_bwd=implementation_bwd)
elif coupling == 'affine':
self.rev_block = AffineBlock(Fm, Gm, adapter=adapter,
implementation_fwd=implementation_fwd, implementation_bwd=implementation_bwd)
else:
raise NotImplementedError('Unknown coupling method: %s' % coupling)
def configure(self):
"""Initialization specific configuration settings"""
for m in self.modules():
if isinstance(m, ReversibleBlock):
m.implementation = self.implementation
elif isinstance(m, nn.BatchNorm2d):
if self.batch_norm_fix:
m.momentum = 0.99
m.eps = 0.001
else:
m.momentum = 0.1
m.eps = 1e-05
coupling: str
Type of coupling ['additive', 'affine']. Default = 'additive'
keep_input : bool
Retain the input information, by default it can be discarded since it will be
reconstructed upon the backward pass.
implementation_fwd : int
Switch between different Operation implementations for forward training. Default = 1
implementation_bwd : int
Switch between different Operation implementations for backward training. Default = 1
"""
super(ReversibleBlock, self).__init__()
if coupling == 'additive':
self.rev_block = AdditiveBlock(Fm, Gm, keep_input, implementation_fwd, implementation_bwd)
elif coupling == 'affine':
self.rev_block = AffineBlock(Fm, Gm, keep_input, implementation_fwd, implementation_bwd)
else:
raise NotImplementedError('Unknown coupling method: %s' % coupling)