I am having a InvalidArgumentError with shapes using a toy dilation 1D-CNN example. My input
train_generator
has the shape TensorShape([128, 1])
with 128 values and 1 expanded dimension to fit the convolutional features in.
def model():
return Sequential([
Convolution1D(1, 7, activation='relu', padding='causal', dilation_rate=2,
input_shape = np.shape(train_generator[0][0]))
])
EPOCHS = 4
model = model()
optimizer = Adam(lr=1.0e-4)
model.compile(optimizer=optimizer, loss='mse', metrics=['mse'])
model.summary()
print('Starting fit...')
history = model.fit(
train_generator, epochs=EPOCHS,verbose=1,
validation_data=val_generator)
The model summary gives me:
Model: "sequential_77"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_146 (Conv1D) (None, 128, 1) 8
And the error received is:
InvalidArgumentError: padded_shape[0]=13 is not divisible by block_shape[0]=2
[[node sequential_77/conv1d_146/Conv1D/SpaceToBatchND
(defined at C:\Users\xxxxx\anaconda3\envs\tensorflow27\lib\site-packages\keras\layers\convolutional.py:231)
]] [Op:__inference_train_function_129421]
In order to reproduce, create a vector of 128 random numbers, expand dimensions on -1 and use the same vector vector for both training and validation.
import numpy as np
import tensorflow as tf
vec = np.random.rand(128)
vec = tf.expand_dims(vec, axis = -1)
train_x = vec
train_y = vec