There seems no built-in support for Mean Pooling layer for RNN in Keras. Anyone knows how to wrap one?
Asked
Active
Viewed 2,676 times
5
-
Look at this answer, use [TemporalMeanPooling](http://stackoverflow.com/a/43014228/1105231) may help you. – XY WANG Mar 25 '17 at 08:35
1 Answers
7
Keras has a layer AveragePooling1D
for that. If you use the graph API, you should be able to do something like:
model.add_node(AveragePooling1D(...),
inputs=['h0', 'h1', ..., 'hn'],
merge_mode='concat', ...)

Mikael Rousson
- 2,247
- 1
- 15
- 16
-
Do you have any example for Sequential model? Eg. how to connect AveragePooling1D with an RNN layer that has return_sequence enabled. – Isilmë O. Feb 14 '16 at 13:11
-
I don't have an example but it looks like should be able to just add an `AveragePooling1D` layer to your `Sequential` after the `RNN` layer and specify the correct dimension for the pooling. – Mikael Rousson Feb 14 '16 at 15:39
-
@IsilmëO - since you've accepted the answer, can you show a complete example? I'm unable to follow the `AveragePooling1D` layer with a `Dense(1)` layer – mossaab Apr 01 '16 at 03:27