I want to build a model using Conv2D which will find vertical and horizontal patterns which describes the relationship between a series of features in a 2D matrix with Height=N and Width=6. This is not an image, but a list of events which consists from some variables, represented as a 2D matrix, each event has length=6 (6 variables), and the matrix size is Nx6. N is not a constant value.
I want the model to find some patterns using vertically and horizontally kernels like this:
Here is my code:
x = tf.keras.Input(shape=(None, 6, 1), name='input')
h1 = tf.keras.layers.Conv2D(128, (1, 6), name="conv2d_1", strides=(1, 1), activation="relu")(x)
h2 = tf.keras.layers.Conv2D(128, (6, 1), name="conv2d_2", strides=(1, 1), activation="relu")(x)
h1 = tf.keras.layers.Reshape((1, 128))(h1)
h2 = tf.keras.layers.Reshape((1, 6*128))(h2)
h3 = tf.keras.layers.Concatenate()([h1, h2])
h4 = tf.keras.layers.Dense(100,name='dense-1', activation='relu')(h3)
y1 = tf.keras.layers.Dense(1, name='output1', activation='sigmoid')(h4)
y2 = tf.keras.layers.Dense(1, name='output2', activation='linear')(h4)
net = tf.keras.Model(inputs=[x], outputs=[y1, y2])
opt = tf.keras.optimizers.get('Adagrad')
opt.learning_rate = 0.003
net.compile(loss='mean_squared_error', optimizer=opt, metrics=['accuracy'])
net.summary()
for i in range(len(exp)):
x = np.array(exp[i]).reshape((1,len(exp[i]),6,1))
loss = net.train_on_batch(x, np.array([[exp[i]] + [np.sum(x, where=[False, False, False, False, False, True])]]))
clear_output(wait=True)
print(loss)
I tried different ways to build this model, but cannot find a correct way, and each time I get different errors, the last one is:
non-broadcastable operand with shape (1,151,6,1) doesn't match the broadcast shape (1,151,6,6)
Please advice how to solve this. I realy want to go this way because I want to inspect this model and results, if it is able to find the horizontal and vertical patterns for correlation distribution of event features that have variables in series with other events variables.