0

The first layer of my network is a Conv1D as follows:

Conv1D(128, 9, activation='relu', input_shape=(100, 28))

My input data consists of elements with input shape (100, 28). i.e. My dataset consists of n of these elements, each with a label. The labels are one-shot arrays of length 15.

The output of .element_spec on my dataset gives:

(TensorSpec(shape=(100, 28), dtype=tf.float32, name=None),
 TensorSpec(shape=(15,), dtype=tf.int32, name=None))

This looks consistent but running .fit() on the model gives this error:

Error when checking input: expected conv1d_18_input to have 3 dimensions, but got array with shape (100, 28)

What am I doing wrong here? BTW, this is TensorFlow 2.0.

Edit: If I step through the tf code, it seems it is expecting (None, 100, 28), but that seems wrong to me. Each element presented to the layer is (100, 28). The "None" surely just represents that it is called many times. Also, you can't specify (None, 100, 28) as input_shape for the layer or it complains it only wants two dimensions, not three!

Many thanks,

Julian

stephen_mugisha
  • 889
  • 1
  • 8
  • 18
Julian7
  • 191
  • 1
  • 12
  • Do you mind also specifying the language your using? – stephen_mugisha Oct 03 '19 at 15:47
  • Language is Python 3.6 – Julian7 Oct 03 '19 at 16:15
  • 1
    Please see https://stackoverflow.com/questions/43396572/dimension-of-shape-in-conv1d – pawols Oct 03 '19 at 17:58
  • Thanks for the pointer but I think that is a different issue. That answer needed the input to be reshaped from (590, 30) to (590, 30, 1). i.e. (number of records, number of time units, number of features). (30, 1) is then used as input shape. In my case, I already have (n, 100, 28). I try to use (100, 28) as the input shape, and that is when I get the error. – Julian7 Oct 03 '19 at 18:35

1 Answers1

0

My misunderstanding here was with Dataset. My dataset on its own has individual elements of (100,28). What I needed to do was apply .batch(32) to the dataset. That produces (None,100,28), which is what is required. The output of .element_spec on this batched dataset is:

<class 'tuple'>: (TensorSpec(shape=(None, 100, 3), dtype=tf.float32, name=None), TensorSpec(shape=(None, 5), dtype=tf.int32, name=None))

This is what the 1D Convnet needs for input.

Julian7
  • 191
  • 1
  • 12