Skip to content
Advertisement

Value error in convolutional neural network due to data shape

I am trying to predict the of number peaks in time series data by using a CNN and keep on getting a data shape error. My data looks as follows:

  • X = list of 520 lists (each is a time series) of various lengths (shortest = 137 elements, longest = 2297 elements)
  • y = list with 520 elements, each being the number of peaks for the respective time series

Due to the various lengths of the time series, I padded X. The shapes of X_train and X_test, after converting them from numpy arrays to tensors are:

  • X_train.shape = TensorShape([390, 2297])
  • X_test.shape = TensorShape([130, 2297])

I am new to keras and I am very unsure about the input_size in the first Conv1D layer. According to this post (Keras/Tensorflow Conv1D expected input shape) I chose it as (2297, 1) or (520, 1), but none of them works. The documentation of Keras says that the input shape should be (batch_size, feature_size, channels), where batch_size is omitted though.

JavaScript

Error:

JavaScript

What might be the issue here?

Advertisement

Answer

I was able to solve it. The correct input shape is given here Convolutional neural network Conv1d input shape in the answer of user ‘rnso’.

I shaped my X_train and X_test (being numpy.arrays) as

JavaScript

and stated the input_shape in the Conv1D statement as input_shape=(ncols, 1)

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement