Search code examples
numpykeraskeras-layer

Keras - How do I turn a 5d Tensor into a 3d one by getting rid of the last three dimensions?


In Keras, I have a (100, 200, 300, 400, 500) Tensor outputted from a Layer, and want to turn it into a (100, 200, 300*400*500) one before feeding it into a new Layer. How do I do that?


Solution

  • Try to add a keras.layers.Reshape layer:

    from keras.layers import Reshape
    
    # ...
    model.add(Reshape((100,200,300*400*500)))
    # ...
    

    or

    model.add(Reshape((-1,200,300*400*500)))