Skip to content

Latest commit

 

History

History
118 lines (78 loc) · 6.38 KB

api_docs.md

File metadata and controls

118 lines (78 loc) · 6.38 KB

cl.layers.dense(inputs, activation, num_outputs, out_caps_dims, routing_method='EMRouting', coordinate_addition=False, reuse=None, name=None)

A fully connected capsule layer.

Args:

  • inputs: A 4-D tensor with shape [batch_size, num_inputs] + in_caps_dims or [batch_size, in_height, in_width, in_channels] + in_caps_dims
  • activation: [batch_size, num_inputs] or [batch_size, in_height, in_width, in_channels]
  • num_outputs: Integer, the number of output capsules in the layer.
  • out_caps_dims: A list with two elements, pose shape of output capsules.
  • routing_method: One of 'EMRouting' or 'DynamicRouting', the method for updating coupling coefficients between votes and pose
  • coordinate_addition: Boolean, whether use Coordinate Addition technique proposed by Hinton etc al., only works when routing_method is EM Routing.

Returns:

  • pose: A 4-D tensor with shape [batch_size, num_outputs] + out_caps_dims
  • activation: [batch_size, num_outputs]

cl.layers.primaryCaps(inputs, filters, kernel_size, strides, out_caps_dims, method=None, name=None):

Primary capsule layer.

Args:

  • inputs: [batch_size, in_height, in_width, in_channels].
  • filters: Integer, the dimensionality of the output space.
  • kernel_size: kernel_size
  • strides: strides
  • out_caps_dims: A list of 2 integers.
  • method: the method of calculating probability of entity existence(logistic, norm, None)

Returns:

  • pose: A 6-D tensor, [batch_size, out_height, out_width, filters] + out_caps_dims
  • activation: A 4-D tensor, [batch_size, out_height, out_width, filters]

cl.layers.conv2d(inputs, activation, filters, out_caps_dims, kernel_size, strides, padding="valid", routing_method="EMRouting", name=None, reuse=None):

A 2D convolutional capsule layer.

Args:

  • inputs: A 6-D tensor with shape [batch_size, in_height, in_width, in_channels] + in_caps_dims.
  • activation: A 4-D tensor with shape [batch_size, in_height, in_width, in_channels].
  • filters: Integer, the dimensionality of the output space (i.e. the number of filters in the convolution).
  • out_caps_dims: A tuple/list of 2 integers, specifying the dimensions of output capsule, e.g. out_caps_dims=[4, 4] representing that each output capsule has shape [4, 4].
  • kernel_size: An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimens
  • strides: An integer or tuple/list of 2 integers, specifying the strides of the convolution along the height and width. Can be a single integer to specify the same value for all spatial dim
  • padding: One of "valid" or "same" (case-insensitive), now only support "valid".
  • routing_method: One of "EMRouting" or "DynamicRouting", the method of routing-by-agreement algorithm.
  • name: A string, the name of the layer.
  • reuse: Boolean, whether to reuse the weights of a previous layer by the same name.

Returns:

  • pose: A 6-D tensor with shape [batch_size, out_height, out_width, out_channels] + out_caps_dims.
  • activation: A 4-D tensor with shape [batch_size, out_height, out_width, out_channels].

cl.layers.conv3d(inputs, activation, filters, out_caps_dims, kernel_size, strides, padding="valid", routing_method="EMRouting", name=None, reuse=None):

A 3D convolutional capsule layer.

Args:

  • inputs: A 7-D tensor with shape [batch_size, in_depth, in_height, in_width, in_channels] + in_caps_dims.
  • activation: A 5-D tensor with shape [batch_size, in_depth, in_height, in_width, in_channels].
  • filters: Integer, the dimensionality of the output space (i.e. the number of filters in the convolution).
  • out_caps_dims: A tuple/list of 2 integers, specifying the dimensions of output capsule, e.g. out_caps_dims=[4, 4] representing that each output capsule has shape [4, 4].
  • kernel_size: An integer or tuple/list of 3 integers, specifying the height and width of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimens
  • strides: An integer or tuple/list of 3 integers, specifying the strides of the convolution along the height and width. Can be a single integer to specify the same value for all spatial dim
  • padding: One of "valid" or "same" (case-insensitive), now only support "valid".
  • routing_method: One of "EMRouting" or "DynamicRouting", the method of routing-by-agreement algorithm.
  • name: String, a name for the operation (optional).
  • reuse: Boolean, whether to reuse the weights of a previous layer by the same name.

Returns:

  • pose: A 7-D tensor with shape [batch_size, out_depth, out_height, out_width, out_channels] + out_caps_dims.
  • activation: A 5-D tensor with shape [batch_size, out_depth, out_height, out_width, out_channels].

cl.layers.conv1d(inputs, activation, filters, out_caps_dims, kernel_size, stride, padding="valid", routing_method="EMRouting", name=None, reuse=None):

A 1D convolutional capsule layer (e.g. temporal convolution).

Args:

  • inputs: A 5-D tensor with shape [batch_size, in_width, in_channels] + in_caps_dims.
  • activation: A 3-D tensor with shape [batch_size, in_width, in_channels].
  • kernel_size: An integer or tuple/list of a single integer, specifying the length of the 1D convolution window.
  • strides: An integer or tuple/list of a single integer, specifying the stride length of the convolution.

Returns:

  • pose: A 5-D tensor with shape [batch_size, out_width, out_channesl] + out_caps_dims.
  • activation: A 3-D tensor with shape [batch_size, out_width, out_channels].

cl.losses.spread_loss(labels, logits, margin, regularizer=None):

Args:

  • labels: [batch_size, num_label].
  • logits: [batch_size, num_label].
  • margin: Integer or 1-D Tensor.
  • regularizer: use regularization.

Returns:

  • loss: Spread loss.

cl.losses.margin_loss(labels, logits, upper_margin=0.9, bottom_margin=0.1, downweight=0.5):

Args:

  • labels: [batch_size, num_label].
  • logits: [batch_size, num_label]