handle labels for a multi-headed CNN

Viewed 162

I'm trying to build a "multi-headed CNN model" so each head is a branch taking in individual multi variant time series Data.

What is not clear to me how to handle the "fit" method or in other words how to properly prepare the y_train. There are 2 classes 0 and 1 for the label

The current architecture is as shown here. neural net architecture

the goal is to predict one time_step ahead

input shapes are:

A Training Data (1, 903155, 5)
B Training Data (1, 903116, 5)
C Training Data (1, 902996, 5)

label shapes:

y_train (903155, 1)

when doing:
history = model.fit(x = [A,B,C], y = y_in)

than i get: Input arrays should have the same number of samples as target arrays. Found 1 input samples and 903155 target samples.

reshaping y_in to (1, 903155) results in:

 expected dense_5 (see image) to have shape (1,) but got array with shape (903155,)

strange is that model.predict([A,B,C]) yield results

2 Answers

The problem's rooted in mishandling the batch dimension; the first dimension of all your layers, and of your data, is the batch dimension. Error explanations below.


Solution:

y_train (903155, 1) is correct, but A, B, and C probably aren't: they specify ONE sample with dimensions (903155, 5), (903116, 5), and (902996, 5), respectively. I doubt this is desired - more likely, the 90... are batch dimensions and should be reshaped as: (903155, 1, 5), etc.


Error explanations:

  • Error 1 is saying that you fed 1 sample (training example) as an input, but 903155 labels
  • Error 2 is saying that dense_5 output is shaped (None, 1), but is expected to be compared against (None, 903155) when computing loss

Input arrays should have the same number of samples as target arrays. Found 1 input samples and 903155 target samples. # Error 1

expected dense_5 to have shape (1,) but got array with shape (903155,) # Error 2

After some digging I found the answer as OverLordGoldDragon mentioned the input and output shape was not correct.

A 1d Conv expect the input data always as: (Samples, timesteps_per_sample, features_per_sample)

so in my case (1, 903155, 5) --> (903155, 1, 5)

Related