1
$\begingroup$

I'm approaching the Conv1D for the first time and I do not understand how to calculate the parameters in each layer. I have an input of (3000, 10, 30), but I decided to use a batch=10, so it becomes (10, 10, 30). Since I'm creating an autoencoder I need an output of the same size. This is my code:

model = tf.keras.Sequential(
    [
        tf.keras.layers.Conv1D(
            filters=128, kernel_size=8, padding="same", strides=3, activation="relu"
        ),
        tf.keras.layers.Dropout(rate=0.2),
        tf.keras.layers.Conv1D(
            filters=64, kernel_size=8, padding="same", strides=1, activation="relu"
        ),
        tf.keras.layers.Dropout(rate=0.2),
        tf.keras.layers.Conv1D(
            filters=32, kernel_size=8, padding="same", strides=1, activation="relu"
        ),
        tf.keras.layers.Conv1DTranspose(
            filters=32, kernel_size=8, padding="same", strides=3, activation="relu"
        ),
        tf.keras.layers.Dropout(rate=0.2),
        tf.keras.layers.Conv1DTranspose(
            filters=64, kernel_size=8, padding="same", strides=1, activation="relu"
        ),
        tf.keras.layers.Dropout(rate=0.2),
        tf.keras.layers.Conv1DTranspose(
            filters=128, kernel_size=8, padding="same", strides=1, activation="relu"
        ),
        tf.keras.layers.Conv1DTranspose(filters=30, kernel_size=8, padding="same"),
    ]
)

The problem is that when I run it I get the error:

ValueError: Dimensions must be equal, but are 12 and 10 for '{{node mean_squared_error/SquaredDifference}} = SquaredDifference[T=DT_FLOAT](sequential/conv1d_transpose_3/BiasAdd, IteratorGetNext:1)' with input shapes: [10,12,30], [10,10,30].

Does the formula changes when using a Conv1D layer? At the moment I'm calculating it using ((shape of width of the filter * shape of height of the filter * number of filters in the previous layer+1)*number of filters), but as you can see it doesn't work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.