1
$\begingroup$

I am new to Keras, and I want to do the following: take a 2D image, and apply four 2D convolution kernels to it, giving four 2D feature maps. I could accomplish this. But then I want to apply two distinct 2D convolutions to each of those 4 maps, giving 8 feature maps. Is that possible?

Here's what I have so far:

import keras
from keras.layers import Conv2D

input_img = keras.Input(shape=(N_rows, N_cols, 1))
x = Conv2D(4, (3,3))(input_img)

But then I don't know how to apply 2 kernels to each of the 4 channels, so that I have eight 2D maps.

$\endgroup$
1
$\begingroup$

You may try Keras DepthwiseConv2D layer

Depthwise Separable convolutions consist of 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.

It will convolute each Channel separately. As shown in this depiction. enter image description here $\hspace{6cm}$Image credit - Blog by Chi-Feng Wang

With depth_multiplier argument, you can add more Filetrs i.e. more copy of the "triplet" shown in the depiction.

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.

$\endgroup$
1
  • $\begingroup$ Thank you, I didn't know about these! $\endgroup$ May 11 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.