0

i have function that creates a ann model

def create_model(input_dim, n_action):
""" A multi-layer perceptron """

model = tf.keras.Sequential()

model.add(tf.keras.layers.Conv1D(
    128,
    kernel_size=5,
    padding='same',
    activation=tf.keras.activations.relu,
    input_shape=(101,)
))

model.add(tf.keras.layers.Conv1D(
    64,
    kernel_size=5,
    padding='same',
    activation=tf.keras.activations.relu,
))

model.add(tf.keras.layers.Dense(
    64,
    activation=tf.keras.activations.relu,
))

model.add(
    tf.keras.layers.Dense(
        64,
        activation=tf.keras.activations.relu,
    ))

model.add(
    tf.keras.layers.Dense(
        32,
        activation=tf.keras.activations.relu,
    ))

model.add(
    tf.keras.layers.Dense(
        n_action,
        activation=tf.keras.activations.relu,
    ))

model.compile(loss='mse', optimizer='adam')

print((model.summary()))

return model

as you can see the first layer is a 1d convolutional layer with filters 128 and kelrnel size 5.

my dataset is just an array of numbers of length 101

[584.95 582.3  581.7  ... 392.35 391.8  391.3 ]

but when i do

model.train_on_batch(states, target_full)

where states are arrays of length 101 and batch size 32 i get this error.

Input 0 of layer "conv1d_118" is incompatible with the layer: expected min_ndim=3, found ndim=2. Full shape received: (None, 101)

I don't understand why dose a 1dconv need 3 dimensional input.Can anyone help me solve this error?

Any help is very much appreciated.

AB Music Box
  • 81
  • 1
  • 6
  • 1
    Does this answer your question? [How is the Keras Conv1D input specified? I seem to be lacking a dimension](https://stackoverflow.com/questions/69591717/how-is-the-keras-conv1d-input-specified-i-seem-to-be-lacking-a-dimension) .. You just have to add an additional dimension to your dataset: `dataset = dataset[... None]` – AloneTogether Jul 06 '22 at 14:52
  • Hi @ABMusicBox, you can also try to expand the dimensions of the data by using the `tf.expand_dims` API. Please refer to [this](https://www.tensorflow.org/api_docs/python/tf/expand_dims) for more information. Thank you! –  Aug 02 '22 at 03:48

0 Answers0