garage.tf.models.cnn module

CNN in TensorFlow.

cnn(input_var, filter_dims, num_filters, strides, name, padding, hidden_nonlinearity=<function relu>, hidden_w_init=<tensorflow.python.ops.init_ops.GlorotUniform object>, hidden_b_init=<tensorflow.python.ops.init_ops.Zeros object>)[source]

Convolutional neural network (CNN).

Note

Based on ‘NHWC’ data format: [batch, height, width, channel].

Parameters:
  • input_var (tf.Tensor) – Input tf.Tensor to the CNN.
  • filter_dims (tuple[int]) – Dimension of the filters. For example, (3, 5) means there are two convolutional layers. The filter for first layer is of dimension (3 x 3) and the second one is of dimension (5 x 5).
  • num_filters (tuple[int]) – Number of filters. For example, (3, 32) means there are two convolutional layers. The filter for the first layer has 3 channels and the second one with 32 channels.
  • strides (tuple[int]) – The stride of the sliding window. For example, (1, 2) means there are two convolutional layers. The stride of the filter for first layer is 1 and that of the second layer is 2.
  • name (str) – Network name, also the variable scope.
  • padding (str) – The type of padding algorithm to use, either ‘SAME’ or ‘VALID’.
  • hidden_nonlinearity (callable) – Activation function for intermediate dense layer(s). It should return a tf.Tensor. Set it to None to maintain a linear activation.
  • hidden_w_init (callable) – Initializer function for the weight of intermediate dense layer(s). The function should return a tf.Tensor.
  • hidden_b_init (callable) – Initializer function for the bias of intermediate dense layer(s). The function should return a tf.Tensor.
Returns:

The output tf.Tensor of the CNN.

cnn_with_max_pooling(input_var, filter_dims, num_filters, strides, name, pool_shapes, pool_strides, padding, hidden_nonlinearity=<function relu>, hidden_w_init=<tensorflow.python.ops.init_ops.GlorotUniform object>, hidden_b_init=<tensorflow.python.ops.init_ops.Zeros object>)[source]

Convolutional neural network (CNN) with max-pooling.

Note

Based on ‘NHWC’ data format: [batch, height, width, channel].

Parameters:
  • input_var (tf.Tensor) – Input tf.Tensor to the CNN.
  • filter_dims (tuple[int]) – Dimension of the filters. For example, (3, 5) means there are two convolutional layers. The filter for first layer is of dimension (3 x 3) and the second one is of dimension (5 x 5).
  • num_filters (tuple[int]) – Number of filters. For example, (3, 32) means there are two convolutional layers. The filter for the first layer has 3 channels and the second one with 32 channels.
  • strides (tuple[int]) – The stride of the sliding window. For example, (1, 2) means there are two convolutional layers. The stride of the filter for first layer is 1 and that of the second layer is 2.
  • name (str) – Model name, also the variable scope of the cnn.
  • pool_shapes (tuple[int]) – Dimension of the pooling layer(s). For example, (2, 2) means that all the pooling layers have shape (2, 2).
  • pool_strides (tuple[int]) – The strides of the pooling layer(s). For example, (2, 2) means that all the pooling layers have strides (2, 2).
  • padding (str) – The type of padding algorithm to use, either ‘SAME’ or ‘VALID’.
  • hidden_nonlinearity (callable) – Activation function for intermediate dense layer(s). It should return a tf.Tensor. Set it to None to maintain a linear activation.
  • hidden_w_init (callable) – Initializer function for the weight of intermediate dense layer(s). The function should return a tf.Tensor.
  • hidden_b_init (callable) – Initializer function for the bias of intermediate dense layer(s). The function should return a tf.Tensor.
Returns:

The output tf.Tensor of the CNN.