Reputation: 51209
I want my activation function select maximal value, generated by N
filters of M x M
convolution. This layer would convert X
channel image to 1-channel one.
How to do that?
First I wrote
classifier.add(Conv2D(3, (5, 5), activation='linear')
classifier.add(MaxPooling2D(pool_size=1, strides=1))
but then thought it doesn't return 1-channel image, but returns 3 channel.
How to do the job?
Upvotes: 5
Views: 2371
Reputation: 86620
This is not a direct answer, but, if you just want the result to be 1 channel, you can create a convolutional layer with only one filter. You can add it after your existing convolution, or simply change your existing convolution.
classifier.add(Conv2D(1, (5,5),....))
Upvotes: -1
Reputation: 40516
So to apply this you shoud create a Lambda
layer and max
from Backend:
from keras import backend as K
if K.image_data_format() == "channels_first":
channels_axis = 1
else:
channels_axis = 3
# To apply MaxOut:
classifier.add(Lambda(lambda x: K.max(x, axis=channels_axis, keepdims=True)))
Upvotes: 2
Reputation: 10789
You can use keras.backend.max
and give it the axis
argument in order to take the maximum along the correct axis. Which one depends on your backend.
Upvotes: 0