0

I have a very simple model which takes in a vector and should output a repeated element vector. Eg: I/P : [1,2,3] rep =3 | O/P = [1,1,1,2,2,2,3,3,3]. This is how my model looks like :

def simple_network(dim):

    x1 = Input(shape = (dim))
    repeated = Lambda(lambda x: K.repeat_elements(x, rep=12, axis=0))(x1)
    model = Model(inputs = x1, outputs = repeated)

    return model

However, this is what model_summary shows :

Model: "model_61"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_19 (InputLayer)        [(None, 7)]               0         
_________________________________________________________________
lambda_17 (Lambda)           (None, 7)                 0         
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0

Dim of my input vector is 7. Shouldn't I be getting an 84 dim vector as output? where am I going wrong?

3
  • 1
    Tensorflow can't know that - you're lambda isn't executed until the model is run. Commented Jun 1, 2021 at 12:06
  • 1
    you should use K.repeat_elements(x, rep=12, axis=1) to get an output dimensionality of (None, 84) Commented Jun 1, 2021 at 13:02
  • @MarcoCerliani yes! Just discovered the mistake! Thanks a lot Commented Jun 1, 2021 at 17:21

1 Answer 1

1

From comments

You should use K.repeat_elements(x, rep=12, axis=1) to get an output dimensionality of (None, 84) (paraphrased from Marco Cerliani)

from tensorflow.keras import Input, Model
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Lambda

def simple_network(dim):

    x1 = Input(shape = (dim))
    repeated = Lambda(lambda x: K.repeat_elements(x, rep=12, axis=1))(x1)
    model = Model(inputs = x1, outputs = repeated)

    return model

simple_network(7).summary()

Output:

Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 7)]               0         
_________________________________________________________________
lambda (Lambda)              (None, 84)                0         
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.