emloop_tensorflow.models.conv_blocks

Classes

class emloop_tensorflow.models.conv_blocks.ConvBaseBlock(conv_fn=<function add_dispatch_support.<locals>.wrapper>, bn_fn=<function add_dispatch_support.<locals>.wrapper>, ln_fn=<function add_dispatch_support.<locals>.wrapper>, extra_dim=(), **kwargs)[source]

Bases: emloop_tensorflow.models.blocks.BaseBlock

Base block for convolution-like blocks.

Inheritance diagram of ConvBaseBlock

__init__(conv_fn=<function add_dispatch_support.<locals>.wrapper>, bn_fn=<function add_dispatch_support.<locals>.wrapper>, ln_fn=<function add_dispatch_support.<locals>.wrapper>, extra_dim=(), **kwargs)[source]

Try to parse and create new ConvBaseBlock.

Parameters:
  • conv_fn (Callable) – convolution function (with num_outputs, kernel_size, stride and scope kwargs)
  • bn_fn (Callable) – batch normalization function
  • ln_fn (Callable) – layer normalization function
  • extra_dim (Tuple[int]) – extra dimension (for 5-dim tensors)
  • kwargs
class emloop_tensorflow.models.conv_blocks.ConvBlock(**kwargs)[source]

Bases: emloop_tensorflow.models.conv_blocks.ConvBaseBlock

2D/3D convolutional layer.

code: (num_filters)c[(time_kernel_size)-](kernel_size)[s(stride)]

examples: 64c3, 64c3s2, 64c3-5s2 (convolution with kernel (3x5x5) assuming BTHWC data)

Inheritance diagram of ConvBlock

__init__(**kwargs)[source]

Try to parse and create new ConvBlock.

_handle_parsed_args(channels, _, time_kernel, kernel, __, stride)[source]

Handle parsed arguments.

Parameters:
  • channels (str) – number of output channels
  • time_kernel (Union[str, int]) – time kernel size (default 1)
  • kernel (str) – spatial kernel size
  • stride (Union[str, int]) – spatial stride (default 1)
Return type:

None

apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
inverse_code()[source]

Get code for the inverse block.

Return type:str
class emloop_tensorflow.models.conv_blocks.ResBlock(**kwargs)[source]

Bases: emloop_tensorflow.models.conv_blocks.ConvBaseBlock

Original residual block.

Inheritance diagram of ResBlock

__init__(**kwargs)[source]

Try to parse and create new ResBlock.

_handle_parsed_args(channels, _, stride)[source]

Handle (most likely save) the arguments matched with the regexp in the code.

Parameters:args – parsed arguments
Return type:None
apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
inverse_code()[source]

Get code for the inverse block.

Return type:str
class emloop_tensorflow.models.conv_blocks.IncBlock(pool_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Bases: emloop_tensorflow.models.conv_blocks.ConvBaseBlock

Inception-v3 block.

Inheritance diagram of IncBlock

__init__(pool_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Try to parse and create new inception-v3 block.

Parameters:pool_fn (Callable) – pooling function
_handle_parsed_args(channels)[source]

Handle (most likely save) the arguments matched with the regexp in the code.

Parameters:args – parsed arguments
Return type:None
apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
class emloop_tensorflow.models.conv_blocks.PoolBaseBlock(prefix='', pool_fn=<function add_dispatch_support.<locals>.wrapper>, extra_dim=(), **kwargs)[source]

Bases: emloop_tensorflow.models.blocks.BaseBlock

Base block for pooling blocks.

Inheritance diagram of PoolBaseBlock

__init__(prefix='', pool_fn=<function add_dispatch_support.<locals>.wrapper>, extra_dim=(), **kwargs)[source]

Try to parse and create new PoolBaseBlock.

Parameters:
  • prefix (str) – prefix for the regular expression
  • pool_fn (Callable) – pooling function (with kernel_size and stride kwargs)
  • extra_dim (Tuple[int]) – extra dimension (for 5-dim tensors)
_handle_parsed_args(kernel, _, stride)[source]

Handle (most likely save) the arguments matched with the regexp in the code.

Parameters:args – parsed arguments
Return type:None
apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
inverse_code()[source]

Get code for the inverse block.

Return type:str
class emloop_tensorflow.models.conv_blocks.MaxPoolBlock(mp_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Bases: emloop_tensorflow.models.conv_blocks.PoolBaseBlock

Max pooling block.

Inheritance diagram of MaxPoolBlock

__init__(mp_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Try to parse and create new PoolBaseBlock.

Parameters:
  • prefix – prefix for the regular expression
  • pool_fn – pooling function (with kernel_size and stride kwargs)
  • extra_dim – extra dimension (for 5-dim tensors)
class emloop_tensorflow.models.conv_blocks.AveragePoolBlock(ap_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Bases: emloop_tensorflow.models.conv_blocks.PoolBaseBlock

Average pooling block.

Inheritance diagram of AveragePoolBlock

__init__(ap_fn=<function add_dispatch_support.<locals>.wrapper>, **kwargs)[source]

Try to parse and create new PoolBaseBlock.

Parameters:
  • prefix – prefix for the regular expression
  • pool_fn – pooling function (with kernel_size and stride kwargs)
  • extra_dim – extra dimension (for 5-dim tensors)
class emloop_tensorflow.models.conv_blocks.UnPoolBlock(**kwargs)[source]

Bases: emloop_tensorflow.models.blocks.BaseBlock

Un pooling block.

Inheritance diagram of UnPoolBlock

CODE_PREFIX = 'u'

Un pooling code prefix character.

__init__(**kwargs)[source]

Try to parse and create new BaseBlock using the following procedure:

  1. try to match the given regexp to the given code (raise UnrecognizedCodeError if it fails)
  2. pass the matched groups to the _handle_parsed_args() method (must be overridden)
Parameters:
  • code – block configuration code
  • regexp – regular expression to be matched to the code
  • defaults – (in-order) default arguments for each of the regexp groups (optional)
Raises:

UnrecognizedCodeError – if the given regexp can not be matched to the given code

_handle_parsed_args(kernel)[source]

Handle (most likely save) the arguments matched with the regexp in the code.

Parameters:args – parsed arguments
Return type:None
apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
class emloop_tensorflow.models.conv_blocks.GlobalAveragePoolBlock(**kwargs)[source]

Bases: emloop_tensorflow.models.blocks.BaseBlock

Global average pooling block effectively flattening spatial dimensions of the input feature maps.

Warning

Expects ?HWC data format (e.g. BHWC or BTHWC).

Inheritance diagram of GlobalAveragePoolBlock

__init__(**kwargs)[source]

Try to parse and create new GlobalAveragePoolBlock.

_handle_parsed_args()[source]

Handle (most likely save) the arguments matched with the regexp in the code.

Parameters:args – parsed arguments
Return type:None
apply(x)[source]

Apply the block to the given tensor.

Parameters:x (Tensor) – Input tensor
Return type:Tensor
Returns:Output tensor
inverse_code()[source]

Get code for the inverse block.

Return type:str