1

I need to decrease the number of channels in CNN network. my input is a 4D object (samples, rows, column, channels). number of channels is 3 and my output for training has just one channel. is there anyway to do kind of max-pooling in channel direction during training?

Thanks in advance

Vahid_g
  • 49
  • 1
  • 7
  • What you try till now? – timiTao Oct 04 '17 at 21:07
  • This sounds like a typical color-separated input in the image-processing domain. What are you trying to do that a typical image-oriented CNN doesn't already do? Existing models don't deal with the quantity of channels after the first CONV layer; they're effectively just 3x as much input. – Prune Oct 05 '17 at 00:24

1 Answers1

3

You can follow a few options, sum the channels, take the max channel, make a standard RGB to B&W trasform, etc.

All of them are doable inside a Lambda layer, with a defined function:

import keras.backend as K

def channelPool(x):
    return K.sum(x,axis=-1)

    #or
    return K.mean(x,axis=-1)

    #or
    return K.max(x,axis=-1)

    #or 
    return (.21*x[:,:,:,:1]) + (0.72*x[:,:,:,1:2]) + (0.07*x[:,:,:,-1:])

The layer would be:

Lambda(channelPool, output_shape=optionalInTensorflow)

PS: If you're using "channels_first", the axes will be 1, and the transform will take x[:,channel,:,:].

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214