Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def default_config(cls):
config = ResNet18.default_config()
config['body/block/resnext'] = True
return config
class ResNeXt34(ResNet):
""" The ResNeXt-34 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/resnext'] = True
return config
class ResNeXt50(ResNet):
""" The ResNeXt-50 architecture """
@classmethod
def default_config(cls):
config = ResNet50.default_config()
config['body/block/resnext'] = True
return config
class ResNeXt101(ResNet):
""" The ResNeXt-101 architecture """
@classmethod
def default_config(cls):
config = ResNet101.default_config()
config['body/block/resnext'] = True
return config
""" An ordinary ResNet block
Parameters
----------
inputs : tf.Tensor
input tensor
name : str
scope name
Returns
-------
tf.Tensor
"""
kwargs = cls.fill_params('body/br', **kwargs)
kwargs['filters'] = cls.num_channels(inputs, data_format=kwargs['data_format'])
return ResNet.block(inputs, name=name, **kwargs)
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = None
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = None
return config
class ResNet50(ResNet):
""" The original ResNet-50 architecture """
@classmethod
def default_config(cls):
config = ResNet34.default_config()
config['body/block/bottleneck'] = 4
return config
class ResNet101(ResNet):
""" The original ResNet-101 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 23, 3]
config['body/block/bottleneck'] = 4
return config
def trunk(cls, inputs, name='trunk', **kwargs):
""" Trunk branch
Parameters
----------
inputs : tf.Tensor
input tensor
name : str
scope name
Returns
-------
tf.Tensor
"""
kwargs = cls.fill_params('body/trunk', **kwargs)
x = ResNet.double_block(inputs, name=name, **kwargs)
return x
""" Two ResNet blocks of two 3x3 convolution + shortcut
Parameters
----------
inputs : tf.Tensor
input tensor
filters : int
number of output filters
name : str
scope name
Returns
-------
tf.Tensor
"""
return ResNet.double_block(inputs, filters=filters, name=name, downsample=True, **kwargs)
""" Two ResNet blocks of two 3x3 convolution + shortcut
Parameters
----------
inputs : tf.Tensor
input tensor
filters : int
number of output filters
name : str
scope name
Returns
-------
tf.Tensor
"""
return ResNet.double_block(inputs, filters=filters, name=name, downsample=True, **kwargs)
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 8, 36, 3]
config['body/block/bottleneck'] = True
return config
"""
num_blocks = cls.get('num_blocks', cls.fill_params('body', **kwargs))
with tf.variable_scope(name):
x = cls.body(inputs, name='body', **kwargs)
scope = tf.get_default_graph().get_name_scope()
encoder_tensors = []
for i, _ in enumerate(num_blocks):
tensor_name = scope + '/body/group-%d'%i + '/output:0'
x = tf.get_default_graph().get_tensor_by_name(tensor_name)
encoder_tensors.append(x)
return encoder_tensors
class ResNet18(ResNet):
""" The original ResNet-18 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [2, 2, 2, 2]
config['body/block/bottleneck'] = False
return config
class ResNet34(ResNet):
""" The original ResNet-34 architecture """
@classmethod
def default_config(cls):
config = ResNet.default_config()
config['body/num_blocks'] = [3, 4, 6, 3]
config['body/block/bottleneck'] = False