SOLVED!
I am using keras with functional API and I have a tensor that is X = (None, 2) tensor and I need to concatenate it with a Y = (None,7) tensor to get a (None,9) tensor. The problem is X and Y's first dimension are unknown so I will have to repeat X a variable number of times, z, to make it equal Y.I have figured out how to repeat X with an unknown z using RepeatedVector but that adds an extra dimension (None, None, 2). So Now I need a way to flatten (None, None, 2) into (None, 2) so I can concatenate them leaving me with an object (None, 9) that I can put into a dense layer.
so what i have tried...
1 - tf.squeeze(X) but this removes all dimensions (None, None)
2 - tf.keras.layers.Reshape but this doesn't accept None arguments for output_shape which i need since y is variable
3 - K.flatten but this makes it 1 dimension.
4- tried adding a dimension to Y = (1,None,7) created odd error.
SOLUTION:
tf.reshape(X, shape=[tf.shape(X)[0]*tf.shape(x)[1],2])
i am calling the None dimensions using tf.shape() and multiplying them by each other.
https://stackoverflow.com/questions/65432925/reduce-none-none-2-to-none-2-using-keras December 24, 2020 at 09:29AM
没有评论:
发表评论