Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow: What exactly does depthwise convolution do?

I want to use depthwise_conv2d from Tensorflow. As far as I understand it now, it performs regular 2D convolutions for every single channel, each with a depth_multiplier number of features.

Then I should expect, if depth_multiplier = 1, to have the number of input channels the same as the number of output channels. But why can I have 256 input channels and 512 output channels? Where do the extra channels come from?

like image 831
Qubix Avatar asked Sep 19 '25 09:09

Qubix


1 Answers

The filters is of size[filter_height, filter_width, in_channels, channel_multiplier]. If the channel_multiplier = 1, then you get the same number of input channels as output. If its N, then you get N*input_channels as output channels, with each input channel convolved with N filters.

For example,

inputs = tf.Variable(tf.random_normal((20, 64,64,100)))
filters = tf.Variable(tf.random_normal((5,5,100,10)))
out = tf.nn.depthwise_conv2d(
      inputs,
      filters,
      strides=[1,1,1,1],
      padding='SAME')

you get out of shape: shape=(20, 64, 64, 1000)

like image 141
vijay m Avatar answered Sep 21 '25 03:09

vijay m