I am trying to create a custom neural network that has 2 encoders and one decoder. The row encoder takes in the input of size eg: 30x40 and the column encoder is supposed to take the same data in transpose, making it 40x30. How do I make it happen?
Tensorflow gives me an error when I concatenate the two encoder inputs. Can this be done somehow? Should I use a different library or a different approach? Can this be done at all?
I know having data 40x40 for the same model works perfectly but I want it for non-square matrix.
Model:
from tensorflow.keras.layers import Input, Dense, Concatenate
from tensorflow.keras.models import Model
import tensorflow as tf
r = Input(shape=(data.shape[0],))
c = Input(shape=(data.shape[1],))
re = Dense(data.shape[0])(r)
ce = Dense(data.shape[1])(c)
e = Concatenate()([re, ce])
d = Dense(2, activation='sigmoid')(e)
o = Dense(data.shape[1], activation='linear')(d)
one_model = Model(inputs=[r, c], outputs=o)
one_model.compile(optimizer='adam', loss='mse')
history = one_model.fit([data, np.transpose(data)], data, epochs=50, batch_size=4, verbose=2)
Error:
Shapes of all inputs must match: values[0].shape = [30,40] != values[1].shape = [40,30]
ValueError: Data cardinality is ambiguous: x sizes: 30, 40 y sizes: 30 Make sure all arrays contain the same number of samples.