I tried to concatenate keras layers beyond the last axis.
concat_layer = keras.layers.concatenate([layer1,layer2],axis=3);
The shapes of layer1 and layer2 are both (?,7,7),for now I want it become (?,7,7,2) rather than (?,7,14). If I wrote like axis=3, it returns "IndexError: list assignment index out of range"...
What should I do? Thank you so much!
Keras has two basic organizational modes: "Sequential" and "Functional". concatenate is the functional version, and really just wraps the Concatenate layer.
Concatenate(axis=-1, **kwargs) Layer that concatenates a list of inputs. It takes as input a list of tensors, all of the same shape except for the concatenation axis, and returns a single tensor that is the concatenation of all inputs.
Keras backend has an expand_dim operation, which you can you use with the Lambda layer. Try:
import keras.backend as K
from keras.layers import Lambda, concatenate
layer1 = Lambda(lambda x: K.expand_dims(x, axis=3))(layer1)
layer2 = Lambda(lambda x: K.expand_dims(x, axis=3))(layer2)
concat_layer = concatenate([layer1, layer2], axis=3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With