Public Member Functions | Public Attributes | List of all members
se_mobilenet.DepthwiseConv2D Class Reference
Inheritance diagram for se_mobilenet.DepthwiseConv2D:

Public Member Functions

def __init__ (self, kernel_size, strides=(1, 1), padding='valid', depth_multiplier=1, data_format=None, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, bias_constraint=None, kwargs)
 
def build (self, input_shape)
 
def call (self, inputs, training=None)
 
def compute_output_shape (self, input_shape)
 
def get_config (self)
 

Public Attributes

 depth_multiplier
 
 depthwise_initializer
 
 depthwise_regularizer
 
 depthwise_constraint
 
 bias_initializer
 
 data_format
 
 depthwise_kernel
 
 bias
 
 input_spec
 
 built
 

Detailed Description

Depthwise separable 2D convolution.
Depthwise Separable convolutions consists in performing
just the first step in a depthwise spatial convolution
(which acts on each input channel separately).
The `depth_multiplier` argument controls how many
output channels are generated per input channel in the depthwise step.
# Arguments
    kernel_size: An integer or tuple/list of 2 integers, specifying the
        width and height of the 2D convolution window.
        Can be a single integer to specify the same value for
        all spatial dimensions.
    strides: An integer or tuple/list of 2 integers,
        specifying the strides of the convolution along the width and height.
        Can be a single integer to specify the same value for
        all spatial dimensions.
        Specifying any stride value != 1 is incompatible with specifying
        any `dilation_rate` value != 1.
    padding: one of `'valid'` or `'same'` (case-insensitive).
    depth_multiplier: The number of depthwise convolution output channels
        for each input channel.
        The total number of depthwise convolution output
        channels will be equal to `filters_in * depth_multiplier`.
    data_format: A string,
        one of `channels_last` (default) or `channels_first`.
        The ordering of the dimensions in the inputs.
        `channels_last` corresponds to inputs with shape
        `(batch, height, width, channels)` while `channels_first`
        corresponds to inputs with shape
        `(batch, channels, height, width)`.
        It defaults to the `image_data_format` value found in your
        Keras config file at `~/.keras/keras.json`.
        If you never set it, then it will be 'channels_last'.
    activation: Activation function to use
        (see [activations](../activations.md)).
        If you don't specify anything, no activation is applied
        (ie. 'linear' activation: `a(x) = x`).
    use_bias: Boolean, whether the layer uses a bias vector.
    depthwise_initializer: Initializer for the depthwise kernel matrix
        (see [initializers](../initializers.md)).
    bias_initializer: Initializer for the bias vector
        (see [initializers](../initializers.md)).
    depthwise_regularizer: Regularizer function applied to
        the depthwise kernel matrix
        (see [regularizer](../regularizers.md)).
    bias_regularizer: Regularizer function applied to the bias vector
        (see [regularizer](../regularizers.md)).
    activity_regularizer: Regularizer function applied to
        the output of the layer (its 'activation').
        (see [regularizer](../regularizers.md)).
    depthwise_constraint: Constraint function applied to
        the depthwise kernel matrix
        (see [constraints](../constraints.md)).
    bias_constraint: Constraint function applied to the bias vector
        (see [constraints](../constraints.md)).
# Input shape
    4D tensor with shape:
    `[batch, channels, rows, cols]` if data_format='channels_first'
    or 4D tensor with shape:
    `[batch, rows, cols, channels]` if data_format='channels_last'.
# Output shape
    4D tensor with shape:
    `[batch, filters, new_rows, new_cols]` if data_format='channels_first'
    or 4D tensor with shape:
    `[batch, new_rows, new_cols, filters]` if data_format='channels_last'.
    `rows` and `cols` values might have changed due to padding.

Definition at line 51 of file se_mobilenet.py.

Constructor & Destructor Documentation

def se_mobilenet.DepthwiseConv2D.__init__ (   self,
  kernel_size,
  strides = (1, 1),
  padding = 'valid',
  depth_multiplier = 1,
  data_format = None,
  activation = None,
  use_bias = True,
  depthwise_initializer = 'glorot_uniform',
  bias_initializer = 'zeros',
  depthwise_regularizer = None,
  bias_regularizer = None,
  activity_regularizer = None,
  depthwise_constraint = None,
  bias_constraint = None,
  kwargs 
)

Definition at line 134 of file se_mobilenet.py.

134  **kwargs):
135  super(DepthwiseConv2D, self).__init__(
136  filters=None,
137  kernel_size=kernel_size,
138  strides=strides,
139  padding=padding,
140  data_format=data_format,
141  activation=activation,
142  use_bias=use_bias,
143  bias_regularizer=bias_regularizer,
144  activity_regularizer=activity_regularizer,
145  bias_constraint=bias_constraint,
146  **kwargs)
147  self.depth_multiplier = depth_multiplier
148  self.depthwise_initializer = initializers.get(depthwise_initializer)
149  self.depthwise_regularizer = regularizers.get(depthwise_regularizer)
150  self.depthwise_constraint = constraints.get(depthwise_constraint)
151  self.bias_initializer = initializers.get(bias_initializer)
152 
def __init__(self, kernel_size, strides=(1, 1), padding='valid', depth_multiplier=1, data_format=None, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, bias_constraint=None, kwargs)

Member Function Documentation

def se_mobilenet.DepthwiseConv2D.build (   self,
  input_shape 
)

Definition at line 153 of file se_mobilenet.py.

153  def build(self, input_shape):
154  if len(input_shape) < 4:
155  raise ValueError('Inputs to `DepthwiseConv2D` should have rank 4. '
156  'Received input shape:', str(input_shape))
157  if self.data_format == 'channels_first':
158  channel_axis = 1
159  else:
160  channel_axis = 3
161  if input_shape[channel_axis] is None:
162  raise ValueError('The channel dimension of the inputs to '
163  '`DepthwiseConv2D` '
164  'should be defined. Found `None`.')
165  input_dim = int(input_shape[channel_axis])
166  depthwise_kernel_shape = (self.kernel_size[0],
167  self.kernel_size[1],
168  input_dim,
169  self.depth_multiplier)
170 
171  self.depthwise_kernel = self.add_weight(
172  shape=depthwise_kernel_shape,
173  initializer=self.depthwise_initializer,
174  name='depthwise_kernel',
175  regularizer=self.depthwise_regularizer,
176  constraint=self.depthwise_constraint)
177 
178  if self.use_bias:
179  self.bias = self.add_weight(shape=(input_dim * self.depth_multiplier,),
180  initializer=self.bias_initializer,
181  name='bias',
182  regularizer=self.bias_regularizer,
183  constraint=self.bias_constraint)
184  else:
185  self.bias = None
186  # Set input spec.
187  self.input_spec = InputSpec(ndim=4, axes={channel_axis: input_dim})
188  self.built = True
189 
static QCString str
def build(self, input_shape)
def se_mobilenet.DepthwiseConv2D.call (   self,
  inputs,
  training = None 
)

Definition at line 190 of file se_mobilenet.py.

190  def call(self, inputs, training=None):
191  outputs = K.depthwise_conv2d(
192  inputs,
193  self.depthwise_kernel,
194  strides=self.strides,
195  padding=self.padding,
196  dilation_rate=self.dilation_rate,
197  data_format=self.data_format)
198 
199  if self.bias:
200  outputs = K.bias_add(
201  outputs,
202  self.bias,
203  data_format=self.data_format)
204 
205  if self.activation is not None:
206  return self.activation(outputs)
207 
208  return outputs
209 
def call(self, inputs, training=None)
def se_mobilenet.DepthwiseConv2D.compute_output_shape (   self,
  input_shape 
)

Definition at line 210 of file se_mobilenet.py.

210  def compute_output_shape(self, input_shape):
211  if self.data_format == 'channels_first':
212  rows = input_shape[2]
213  cols = input_shape[3]
214  out_filters = input_shape[1] * self.depth_multiplier
215  elif self.data_format == 'channels_last':
216  rows = input_shape[1]
217  cols = input_shape[2]
218  out_filters = input_shape[3] * self.depth_multiplier
219 
220  rows = conv_utils.conv_output_length(rows, self.kernel_size[0],
221  self.padding,
222  self.strides[0])
223  cols = conv_utils.conv_output_length(cols, self.kernel_size[1],
224  self.padding,
225  self.strides[1])
226 
227  if self.data_format == 'channels_first':
228  return (input_shape[0], out_filters, rows, cols)
229  elif self.data_format == 'channels_last':
230  return (input_shape[0], rows, cols, out_filters)
231 
def compute_output_shape(self, input_shape)
def se_mobilenet.DepthwiseConv2D.get_config (   self)

Definition at line 232 of file se_mobilenet.py.

232  def get_config(self):
233  config = super(DepthwiseConv2D, self).get_config()
234  config.pop('filters')
235  config.pop('kernel_initializer')
236  config.pop('kernel_regularizer')
237  config.pop('kernel_constraint')
238  config['depth_multiplier'] = self.depth_multiplier
239  config['depthwise_initializer'] = initializers.serialize(self.depthwise_initializer)
240  config['depthwise_regularizer'] = regularizers.serialize(self.depthwise_regularizer)
241  config['depthwise_constraint'] = constraints.serialize(self.depthwise_constraint)
242  return config
243 
244 

Member Data Documentation

se_mobilenet.DepthwiseConv2D.bias

Definition at line 179 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.bias_initializer

Definition at line 151 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.built

Definition at line 188 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.data_format

Definition at line 157 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.depth_multiplier

Definition at line 147 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.depthwise_constraint

Definition at line 150 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.depthwise_initializer

Definition at line 148 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.depthwise_kernel

Definition at line 171 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.depthwise_regularizer

Definition at line 149 of file se_mobilenet.py.

se_mobilenet.DepthwiseConv2D.input_spec

Definition at line 187 of file se_mobilenet.py.


The documentation for this class was generated from the following file: